Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Algorithm.CSharp/AddOptionContractExpiresRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,33 +135,33 @@ public override void OnData(Slice slice)
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "3"},
{"Average Win", "2.73%"},
{"Average Win", "2.67%"},
{"Average Loss", "-2.98%"},
{"Compounding Annual Return", "-4.619%"},
{"Drawdown", "0.300%"},
{"Expectancy", "-0.042"},
{"Compounding Annual Return", "-5.432%"},
{"Drawdown", "0.400%"},
{"Expectancy", "-0.052"},
{"Start Equity", "100000"},
{"End Equity", "99668"},
{"Net Profit", "-0.332%"},
{"Sharpe Ratio", "-4.614"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0.427%"},
{"End Equity", "99608"},
{"Net Profit", "-0.392%"},
{"Sharpe Ratio", "-5.487"},
{"Sortino Ratio", "-2.607"},
{"Probabilistic Sharpe Ratio", "0.016%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "0.92"},
{"Alpha", "-0.022"},
{"Beta", "-0.012"},
{"Profit-Loss Ratio", "0.90"},
{"Alpha", "-0.028"},
{"Beta", "-0.01"},
{"Annual Standard Deviation", "0.005"},
{"Annual Variance", "0"},
{"Information Ratio", "-2.823"},
{"Information Ratio", "-2.949"},
{"Tracking Error", "0.049"},
{"Treynor Ratio", "2.01"},
{"Treynor Ratio", "3.063"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$5700000.00"},
{"Lowest Capacity Asset", "AOL VRKS95ENPM9Y|AOL R735QTJ8XC9X"},
{"Portfolio Turnover", "0.55%"},
{"Portfolio Turnover", "0.54%"},
{"Drawdown Recovery", "0"},
{"OrderListHash", "d314aef81752b6583fd58f9e49054cd4"}
{"OrderListHash", "65d9c6a5991648c8c54a23423a51340d"}
};
}
}
7 changes: 5 additions & 2 deletions Algorithm.CSharp/AutomaticSeedBaseRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ public abstract class AutomaticSeedBaseRegressionAlgorithm : QCAlgorithm, IRegre
protected virtual bool ShouldHaveTradeData { get; }
protected virtual bool ShouldHaveQuoteData { get; }
protected virtual bool ShouldHaveOpenInterestData { get; }
protected virtual List<string> SecuritiesToIgnoreForChecking => Enumerable.Empty<string>().ToList();

public override void OnSecuritiesChanged(SecurityChanges changes)
{
var gotTrades = false;
var gotQuotes = false;
var gotOpenInterest = false;

foreach (var addedSecurity in changes.AddedSecurities.Where(x => !x.Symbol.IsCanonical() || x.Symbol.SecurityType == SecurityType.Future))
var securitiesToCheck = changes.AddedSecurities.Where(x => (!x.Symbol.IsCanonical() || x.Symbol.SecurityType == SecurityType.Future) && !SecuritiesToIgnoreForChecking.Contains(x.Symbol.Value)).ToList();

foreach (var addedSecurity in securitiesToCheck)
{
if (addedSecurity.Price == 0)
{
Expand All @@ -55,7 +58,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
gotOpenInterest |= addedSecurity.Cache.GetData<OpenInterest>() != null;
}

if (changes.AddedSecurities.Count > 0)
if (securitiesToCheck.Count > 0)
{
if (ShouldHaveTradeData && !gotTrades)
{
Expand Down
28 changes: 14 additions & 14 deletions Algorithm.CSharp/BacktestingBrokerageRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,30 +316,30 @@ public override OrderEvent MarketFill(Security asset, MarketOrder order)
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "-0.40%"},
{"Compounding Annual Return", "-21.378%"},
{"Drawdown", "0.400%"},
{"Compounding Annual Return", "119.386%"},
{"Drawdown", "0.800%"},
{"Expectancy", "-1"},
{"Start Equity", "100000"},
{"End Equity", "99671.06"},
{"Net Profit", "-0.329%"},
{"Sharpe Ratio", "-14.095"},
{"End Equity", "101082.06"},
{"Net Profit", "1.082%"},
{"Sharpe Ratio", "12.594"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "1.216%"},
{"Probabilistic Sharpe Ratio", "95.977%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.01"},
{"Beta", "0.097"},
{"Annual Standard Deviation", "0.002"},
{"Annual Variance", "0"},
{"Information Ratio", "7.39"},
{"Tracking Error", "0.015"},
{"Treynor Ratio", "-0.234"},
{"Alpha", "0.504"},
{"Beta", "-6.672"},
{"Annual Standard Deviation", "0.111"},
{"Annual Variance", "0.012"},
{"Information Ratio", "12.001"},
{"Tracking Error", "0.127"},
{"Treynor Ratio", "-0.209"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "17.02%"},
{"Drawdown Recovery", "0"},
{"Drawdown Recovery", "4"},
{"OrderListHash", "1be5073f2cf8802ffa163f7dab7d040e"}
};
}
Expand Down
61 changes: 33 additions & 28 deletions Algorithm.CSharp/BasicTemplateContinuousFutureAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class BasicTemplateContinuousFutureAlgorithm : QCAlgorithm, IRegressionAl
private SimpleMovingAverage _fast;
private SimpleMovingAverage _slow;

// Minimum SMA gap required before acting on a cross; see the workaround note in OnData.
private const decimal CrossThreshold = 0.001m;

/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
Expand Down Expand Up @@ -69,15 +72,17 @@ public override void OnData(Slice slice)
}
}

// Workaround so the C# and Python versions take the exact same trades on the limited
// sample data in the repository (decimal vs double rounding can disagree at a cross).
if (!Portfolio.Invested)
{
if(_fast > _slow)
if(_fast.Current.Value - _slow.Current.Value > CrossThreshold)
{
_currentContract = Securities[_continuousContract.Mapped];
Buy(_currentContract.Symbol, 1);
}
}
else if(_fast < _slow)
else if(_slow.Current.Value - _fast.Current.Value > CrossThreshold)
{
Liquidate();
}
Expand Down Expand Up @@ -134,34 +139,34 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "5"},
{"Average Win", "2.48%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "11.325%"},
{"Drawdown", "1.500%"},
{"Expectancy", "0"},
{"Total Orders", "9"},
{"Average Win", "2.85%"},
{"Average Loss", "-0.43%"},
{"Compounding Annual Return", "11.019%"},
{"Drawdown", "0.900%"},
{"Expectancy", "2.818"},
{"Start Equity", "100000"},
{"End Equity", "105549.6"},
{"Net Profit", "5.550%"},
{"Sharpe Ratio", "1.332"},
{"Sortino Ratio", "879.904"},
{"Probabilistic Sharpe Ratio", "79.894%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.075"},
{"Beta", "-0.017"},
{"Annual Standard Deviation", "0.053"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-1.48"},
{"Tracking Error", "0.099"},
{"Treynor Ratio", "-4.187"},
{"Total Fees", "$10.75"},
{"Estimated Strategy Capacity", "$7100000.00"},
{"End Equity", "105403.5"},
{"Net Profit", "5.404%"},
{"Sharpe Ratio", "1.531"},
{"Sortino Ratio", "2.106"},
{"Probabilistic Sharpe Ratio", "82.864%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "6.64"},
{"Alpha", "0.067"},
{"Beta", "0.009"},
{"Annual Standard Deviation", "0.045"},
{"Annual Variance", "0.002"},
{"Information Ratio", "-1.606"},
{"Tracking Error", "0.093"},
{"Treynor Ratio", "7.237"},
{"Total Fees", "$19.35"},
{"Estimated Strategy Capacity", "$1000000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "2.33%"},
{"Drawdown Recovery", "37"},
{"OrderListHash", "223735440010fcec5889bb7becacfa82"}
{"Portfolio Turnover", "4.18%"},
{"Drawdown Recovery", "19"},
{"OrderListHash", "eb3bed9886f79a56c631225a6445adb2"}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class BasicTemplateContinuousFutureWithExtendedMarketAlgorithm : QCAlgori
private SimpleMovingAverage _fast;
private SimpleMovingAverage _slow;

// Minimum SMA gap required before acting on a cross; see the workaround note in OnData.
private const decimal CrossThreshold = 0.001m;

/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
Expand Down Expand Up @@ -76,17 +79,24 @@ public override void OnData(Slice slice)
return;
}

if (!Portfolio.Invested)
// This is just to limit the amount of orders done in this regression test, since data in the repo is limited.
// Also limit it to 3 orders so that the continuous contract rolls happens with an open position.
if (Time < new DateTime(2013, 11, 12) && Transactions.OrdersCount < 3)
{
if(_fast > _slow)
// Workaround so the C# and Python versions take the exact same trades on the limited
// sample data in the repository (decimal vs double rounding can disagree at a cross).
if (!Portfolio.Invested)
{
_currentContract = Securities[_continuousContract.Mapped];
Buy(_currentContract.Symbol, 1);
if (_fast.Current.Value - _slow.Current.Value > CrossThreshold)
{
_currentContract = Securities[_continuousContract.Mapped];
Buy(_currentContract.Symbol, 1);
}
}
else if (_slow.Current.Value - _fast.Current.Value > CrossThreshold)
{
Liquidate();
}
}
else if(_fast < _slow)
{
Liquidate();
}

if (_currentContract != null && _currentContract.Symbol != _continuousContract.Mapped)
Expand Down Expand Up @@ -140,34 +150,34 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "5"},
{"Average Win", "2.86%"},
{"Total Orders", "3"},
{"Average Win", "6.15%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "12.959%"},
{"Drawdown", "1.100%"},
{"Compounding Annual Return", "13.813%"},
{"Drawdown", "1.400%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "106337.1"},
{"Net Profit", "6.337%"},
{"Sharpe Ratio", "1.41"},
{"Sortino Ratio", "1.242"},
{"Probabilistic Sharpe Ratio", "77.992%"},
{"End Equity", "106741.4"},
{"Net Profit", "6.741%"},
{"Sharpe Ratio", "2.003"},
{"Sortino Ratio", "2.845"},
{"Probabilistic Sharpe Ratio", "92.590%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.071"},
{"Beta", "0.054"},
{"Annual Standard Deviation", "0.059"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-1.392"},
{"Tracking Error", "0.097"},
{"Treynor Ratio", "1.518"},
{"Total Fees", "$10.75"},
{"Estimated Strategy Capacity", "$890000000.00"},
{"Alpha", "0.069"},
{"Beta", "0.086"},
{"Annual Standard Deviation", "0.044"},
{"Annual Variance", "0.002"},
{"Information Ratio", "-1.506"},
{"Tracking Error", "0.086"},
{"Treynor Ratio", "1.023"},
{"Total Fees", "$6.45"},
{"Estimated Strategy Capacity", "$3700000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "2.32%"},
{"Drawdown Recovery", "34"},
{"OrderListHash", "1504a8892da8d8c0650018732f315753"}
{"Portfolio Turnover", "1.37%"},
{"Drawdown Recovery", "18"},
{"OrderListHash", "764ab9f6ea662a60e41daedb9613b246"}
};
}
}
42 changes: 21 additions & 21 deletions Algorithm.CSharp/BasicTemplateFutureRolloverAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,34 +193,34 @@ public void Dispose()
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Total Orders", "3"},
{"Average Win", "0.14%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-0.010%"},
{"Drawdown", "0.000%"},
{"Compounding Annual Return", "0.770%"},
{"Drawdown", "0.100%"},
{"Expectancy", "0"},
{"Start Equity", "1000000"},
{"End Equity", "999983.2"},
{"Net Profit", "-0.002%"},
{"Sharpe Ratio", "-225.214"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0.135%"},
{"End Equity", "1001341.4"},
{"Net Profit", "0.134%"},
{"Sharpe Ratio", "-0.494"},
{"Sortino Ratio", "-0.544"},
{"Probabilistic Sharpe Ratio", "55.093%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.008"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Alpha", "-0.015"},
{"Beta", "0.03"},
{"Annual Standard Deviation", "0.004"},
{"Annual Variance", "0"},
{"Information Ratio", "-5.146"},
{"Tracking Error", "0.083"},
{"Treynor Ratio", "-542.359"},
{"Total Fees", "$2.15"},
{"Estimated Strategy Capacity", "$0"},
{"Information Ratio", "-5.235"},
{"Tracking Error", "0.081"},
{"Treynor Ratio", "-0.069"},
{"Total Fees", "$6.45"},
{"Estimated Strategy Capacity", "$780000000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "0.13%"},
{"Drawdown Recovery", "0"},
{"OrderListHash", "a6ccce3a1a7f549f887d83e84bfa878d"}
{"Portfolio Turnover", "0.42%"},
{"Drawdown Recovery", "3"},
{"OrderListHash", "d17bbe62c86730e5178528a3153df0e6"}
};
}
}
Loading
Loading