Skip to content

Commit c127287

Browse files
Adding regression statistics
1 parent ff172ad commit c127287

3 files changed

Lines changed: 84 additions & 10 deletions

File tree

Algorithm.CSharp/Alphas/ForexCalendarAlpha.cs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using QuantConnect.Data;
2727
using QuantConnect.Data.Custom;
2828
using QuantConnect.Data.UniverseSelection;
29+
using QuantConnect.Interfaces;
2930
using QuantConnect.Securities.Forex;
3031

3132
namespace QuantConnect.Algorithm.CSharp.Alphas
@@ -34,8 +35,8 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
3435
// This demonstration alpha reads the DailyFx calendar and provides insights based upon
3536
// the news outlook for the country associated currency pairs
3637
// </summary>
37-
public class ForexCalendarAlpha : QCAlgorithmFramework
38-
{
38+
public class ForexCalendarAlpha : QCAlgorithmFramework, IRegressionAlgorithmDefinition
39+
{
3940

4041
public override void Initialize()
4142
{
@@ -69,7 +70,43 @@ public override void Initialize()
6970

7071
//we create a DailyFx event handler but insights will be produced in the Alpha Model
7172
public void OnData(DailyFx data) { }
72-
}
73+
74+
/// <summary>
75+
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
76+
/// </summary>
77+
public bool CanRunLocally { get; } = false;
78+
79+
/// <summary>
80+
/// This is used by the regression test system to indicate which languages this algorithm is written in.
81+
/// </summary>
82+
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
83+
84+
/// <summary>
85+
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
86+
/// </summary>
87+
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
88+
{
89+
{"Total Trades", "647"},
90+
{"Average Win", "0.07%"},
91+
{"Average Loss", "-0.03%"},
92+
{"Compounding Annual Return", "2.958%"},
93+
{"Drawdown", "0.700%"},
94+
{"Expectancy", "1.008"},
95+
{"Net Profit", "9.285%"},
96+
{"Sharpe Ratio", "1.572"},
97+
{"Loss Rate", "43%"},
98+
{"Win Rate", "57%"},
99+
{"Profit-Loss Ratio", "2.50"},
100+
{"Alpha", "0.051"},
101+
{"Beta", "-1.878"},
102+
{"Annual Standard Deviation", "0.014"},
103+
{"Annual Variance", "0"},
104+
{"Information Ratio", "0.5"},
105+
{"Tracking Error", "0.014"},
106+
{"Treynor Ratio", "-0.012"},
107+
{"Total Fees", "$0.00"}
108+
};
109+
}
73110

74111
/// <summary>
75112
/// Generate Forex Insights for High Impact Calendar Events.
@@ -84,7 +121,7 @@ public FxCalendarTrigger()
84121
public override IEnumerable<Insight> Update(QCAlgorithmFramework algorithm, Slice data)
85122
{
86123
var insights = new List<Insight>();
87-
var period = TimeSpan.FromMinutes(60);
124+
var period = TimeSpan.FromMinutes(5);
88125
var magnitude = 0.0005;
89126

90127
// We will create our insights when we recieve news

Algorithm.CSharp/Alphas/RebalancingLeveragedETFAlpha.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using QuantConnect.Algorithm.Framework.Risk;
2424
using QuantConnect.Algorithm.Framework.Selection;
2525
using QuantConnect.Data;
26+
using QuantConnect.Interfaces;
2627

2728
namespace QuantConnect.Algorithm.CSharp.Alphas
2829
{
@@ -34,8 +35,8 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
3435
/// <meta name="tag" content="alphastream" />
3536
/// <meta name="tag" content="algorithm framework" />
3637
/// <meta name="tag" content="etf" />
37-
public class RebalancingLeveragedETFAlpha : QCAlgorithmFramework
38-
{
38+
public class RebalancingLeveragedETFAlpha : QCAlgorithmFramework, IRegressionAlgorithmDefinition
39+
{
3940
private readonly List<ETFGroup> Groups = new List<ETFGroup>();
4041

4142
public override void Initialize()
@@ -45,12 +46,12 @@ public override void Initialize()
4546
SetCash(100000);
4647

4748
var underlying = new List<string> {"SPY","QLD","DIA","IJR","MDY","IWM","QQQ","IYE","EEM","IYW","EFA","GAZB","SLV","IEF","IYM","IYF","IYH","IYR","IYC","IBB","FEZ","USO","TLT"};
48-
var ultra = new List<string> {"SSO","UGL","DDM","SAA","MZZ","UWM","QLD","DIG","EET","ROM","EFO","BOIL","AGQ","UST","UYM","UYG","RXL","URE","UCC","BIB","ULE","UCO","UBT"};
49+
var ultraLong = new List<string> {"SSO","UGL","DDM","SAA","MZZ","UWM","QLD","DIG","EET","ROM","EFO","BOIL","AGQ","UST","UYM","UYG","RXL","URE","UCC","BIB","ULE","UCO","UBT"};
4950
var ultraShort = new List<string> {"SDS","GLL","DXD","SDD","MVV","TWM","QID","DUG","EEV","REW","EFU","KOLD","ZSL","PST","SMN","SKF","RXD","SRS","SCC","BIS","EPV","SCO","TBT"};
5051

5152
for (var i = 0; i < underlying.Count; i++)
5253
{
53-
Groups.Add(new ETFGroup(AddEquity(underlying[i]).Symbol, AddEquity(ultra[i]).Symbol, AddEquity(ultraShort[i]).Symbol));
54+
Groups.Add(new ETFGroup(AddEquity(underlying[i]).Symbol, AddEquity(ultraLong[i]).Symbol, AddEquity(ultraShort[i]).Symbol));
5455
}
5556

5657
// Manually curated universe
@@ -64,7 +65,42 @@ public override void Initialize()
6465
SetExecution(new ImmediateExecutionModel());
6566
SetRiskManagement(new NullRiskManagementModel());
6667
}
67-
}
68+
/// <summary>
69+
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
70+
/// </summary>
71+
public bool CanRunLocally { get; } = false;
72+
73+
/// <summary>
74+
/// This is used by the regression test system to indicate which languages this algorithm is written in.
75+
/// </summary>
76+
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
77+
78+
/// <summary>
79+
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
80+
/// </summary>
81+
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
82+
{
83+
{"Total Trades", "2465"},
84+
{"Average Win", "0.26%"},
85+
{"Average Loss", "-0.24%"},
86+
{"Compounding Annual Return", "8.143%"},
87+
{"Drawdown", "17.600%"},
88+
{"Expectancy", "0.036"},
89+
{"Net Profit", "9.582%"},
90+
{"Sharpe Ratio", "0.505"},
91+
{"Loss Rate", "50%"},
92+
{"Win Rate", "50%"},
93+
{"Profit-Loss Ratio", "1.07"},
94+
{"Alpha", "0.58"},
95+
{"Beta", "-24.276"},
96+
{"Annual Standard Deviation", "0.191"},
97+
{"Annual Variance", "0.036"},
98+
{"Information Ratio", "0.401"},
99+
{"Tracking Error", "0.191"},
100+
{"Treynor Ratio", "-0.004"},
101+
{"Total Fees", "$9056.88"}
102+
};
103+
}
68104

69105
/// <summary>
70106
/// If the underlying ETF has experienced a return >= 1% since the previous day's close up to the current time at 14:15,

Algorithm.Python/Alphas/RebalancingLeveragedETFAlpha.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ class ETFGroup:
114114
def __init__(self,underlying, ultraLong, ultraShort):
115115
self.underlying = underlying
116116
self.ultraLong = ultraLong
117-
self.ultraShort = ultraShort
117+
self.ultraShort = ultraShort
118+
self.yesterdayClose = 0

0 commit comments

Comments
 (0)