Skip to content

Security Re-Addition Behavior Tidy Up #8647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ public override void Initialize()

public override void OnEndOfAlgorithm()
{
const int expected = 78;
const int expected = 80;
if (Insights.TotalCount != expected)
{
throw new RegressionTestException($"The total number of insights should be {expected}. Actual: {Insights.TotalCount}");
@@ -54,32 +54,32 @@ public override void OnEndOfAlgorithm()
public override Dictionary<string, string> ExpectedStatistics => new()
{
{"Total Orders", "69"},
{"Average Win", "0.18%"},
{"Average Win", "0.17%"},
{"Average Loss", "-0.15%"},
{"Compounding Annual Return", "42.429%"},
{"Compounding Annual Return", "46.315%"},
{"Drawdown", "0.900%"},
{"Expectancy", "0.367"},
{"Expectancy", "0.292"},
{"Start Equity", "100000"},
{"End Equity", "102949.54"},
{"Net Profit", "2.950%"},
{"Sharpe Ratio", "5.164"},
{"Sortino Ratio", "8.556"},
{"Probabilistic Sharpe Ratio", "90.449%"},
{"Loss Rate", "38%"},
{"Win Rate", "62%"},
{"Profit-Loss Ratio", "1.22"},
{"Alpha", "0.306"},
{"Beta", "-0.129"},
{"Annual Standard Deviation", "0.055"},
{"End Equity", "103177.61"},
{"Net Profit", "3.178%"},
{"Sharpe Ratio", "5.515"},
{"Sortino Ratio", "9.319"},
{"Probabilistic Sharpe Ratio", "91.936%"},
{"Loss Rate", "40%"},
{"Win Rate", "60%"},
{"Profit-Loss Ratio", "1.15"},
{"Alpha", "0.333"},
{"Beta", "-0.138"},
{"Annual Standard Deviation", "0.056"},
{"Annual Variance", "0.003"},
{"Information Ratio", "1.181"},
{"Tracking Error", "0.077"},
{"Treynor Ratio", "-2.186"},
{"Information Ratio", "1.488"},
{"Tracking Error", "0.078"},
{"Treynor Ratio", "-2.221"},
{"Total Fees", "$267.37"},
{"Estimated Strategy Capacity", "$6000000.00"},
{"Estimated Strategy Capacity", "$4000000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Portfolio Turnover", "65.87%"},
{"OrderListHash", "15bd0a959060b7ec5d77646e7e585f04"}
{"Portfolio Turnover", "65.85%"},
{"OrderListHash", "a30e9c3a0143e548439788896d94a670"}
};
}
}
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
}
}
}
// We expect the equity to get Removed
// De equity is deselected, but it should not be removed since the options universe still selects it as the underlying
else if (Time.Day == 7)
{
if (Time.Hour != 0)
@@ -141,12 +141,12 @@ public override void OnSecuritiesChanged(SecurityChanges changes)

// Options can be selected/deselected on this day, but the equity should be removed

if (changes.RemovedSecurities.Count == 0 || !changes.RemovedSecurities.Any(x => x.Symbol == _aapl))
if (changes.RemovedSecurities.Count == 0 || changes.RemovedSecurities.Any(x => x.Symbol == _aapl))
{
throw new RegressionTestException($"Unexpected SecurityChanges: {changes}");
}
}
// We expect the options to get Removed, happens in the next loop after removing the equity
// We expect the options to get Removed, as well as the underlying, happens in the next loop after removing the equity
else if (Time.Day == 9)
{
if (Time.Hour != 0)
Original file line number Diff line number Diff line change
@@ -60,9 +60,10 @@ public override void OnEndOfAlgorithm()
{
// We have removed all securities from the universe. The Alpha Model should remove the consolidator
var consolidatorCount = SubscriptionManager.Subscriptions.Sum(s => s.Consolidators.Count);
if (consolidatorCount > 0)
// Expect 2 consolidators for SPY and AIG, which where manually added at the start
if (consolidatorCount != 2)
{
throw new RegressionTestException($"The number of consolidator is should be zero. Actual: {consolidatorCount}");
throw new RegressionTestException($"The number of consolidator is should be 2. Actual: {consolidatorCount}");
}
}

@@ -84,7 +85,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 1008;
public int AlgorithmHistoryDataPoints => 1512;

/// <summary>
/// Final status of the algorithm
@@ -97,32 +98,32 @@ public override void OnEndOfAlgorithm()
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "6"},
{"Average Win", "0.99%"},
{"Average Loss", "-0.84%"},
{"Compounding Annual Return", "24.021%"},
{"Drawdown", "0.800%"},
{"Expectancy", "0.089"},
{"Average Win", "0.82%"},
{"Average Loss", "-0.39%"},
{"Compounding Annual Return", "43.360%"},
{"Drawdown", "0.700%"},
{"Expectancy", "0.546"},
{"Start Equity", "100000"},
{"End Equity", "100295.35"},
{"Net Profit", "0.295%"},
{"Sharpe Ratio", "4.205"},
{"End Equity", "100494.63"},
{"Net Profit", "0.495%"},
{"Sharpe Ratio", "10.477"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "61.706%"},
{"Probabilistic Sharpe Ratio", "85.907%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "1.18"},
{"Alpha", "0.08"},
{"Beta", "0.06"},
{"Annual Standard Deviation", "0.047"},
{"Annual Variance", "0.002"},
{"Information Ratio", "-8.305"},
{"Tracking Error", "0.214"},
{"Treynor Ratio", "3.313"},
{"Total Fees", "$31.60"},
{"Estimated Strategy Capacity", "$3200000.00"},
{"Profit-Loss Ratio", "2.09"},
{"Alpha", "0.227"},
{"Beta", "0.066"},
{"Annual Standard Deviation", "0.034"},
{"Annual Variance", "0.001"},
{"Information Ratio", "-7.7"},
{"Tracking Error", "0.21"},
{"Treynor Ratio", "5.41"},
{"Total Fees", "$25.78"},
{"Estimated Strategy Capacity", "$3300000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Portfolio Turnover", "80.47%"},
{"OrderListHash", "476d54ac7295563a79add3a80310a0a8"}
{"Portfolio Turnover", "60.55%"},
{"OrderListHash", "0eb251234d0fa772130bb341457091b4"}
};
}
}
52 changes: 26 additions & 26 deletions Algorithm.CSharp/RawPricesUniverseRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -91,12 +91,12 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 135;
public long DataPoints => 144;

/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 30;
public int AlgorithmHistoryDataPoints => 90;

/// <summary>
/// Final status of the algorithm
@@ -108,33 +108,33 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "12"},
{"Average Win", "0.34%"},
{"Average Loss", "-0.14%"},
{"Compounding Annual Return", "4.586%"},
{"Drawdown", "0.700%"},
{"Expectancy", "0.158"},
{"Total Orders", "33"},
{"Average Win", "0.22%"},
{"Average Loss", "-0.31%"},
{"Compounding Annual Return", "-25.889%"},
{"Drawdown", "2.200%"},
{"Expectancy", "-0.199"},
{"Start Equity", "50000"},
{"End Equity", "50090.17"},
{"Net Profit", "0.180%"},
{"Sharpe Ratio", "5.991"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "99.393%"},
{"Loss Rate", "67%"},
{"Win Rate", "33%"},
{"Profit-Loss Ratio", "2.47"},
{"Alpha", "0.17"},
{"Beta", "0.029"},
{"Annual Standard Deviation", "0.028"},
{"Annual Variance", "0.001"},
{"Information Ratio", "2.734"},
{"Tracking Error", "0.098"},
{"Treynor Ratio", "5.803"},
{"End Equity", "49401.67"},
{"Net Profit", "-1.197%"},
{"Sharpe Ratio", "-1.036"},
{"Sortino Ratio", "-0.681"},
{"Probabilistic Sharpe Ratio", "31.423%"},
{"Loss Rate", "53%"},
{"Win Rate", "47%"},
{"Profit-Loss Ratio", "0.72"},
{"Alpha", "-0.02"},
{"Beta", "0.682"},
{"Annual Standard Deviation", "0.086"},
{"Annual Variance", "0.007"},
{"Information Ratio", "0.195"},
{"Tracking Error", "0.063"},
{"Treynor Ratio", "-0.131"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$99000000.00"},
{"Estimated Strategy Capacity", "$220000000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Portfolio Turnover", "15.96%"},
{"OrderListHash", "d915ae36ce856457b32ebbfce4581281"}
{"Portfolio Turnover", "44.69%"},
{"OrderListHash", "93b3a1c9d6234bf616f0a69a5129a781"}
};
}
}
Original file line number Diff line number Diff line change
@@ -116,8 +116,9 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
_universeAdded |= changes.AddedSecurities.Count == expectedChangesCount;
}

// TODO: shouldn't be sending AAPL as a removed security since it was added by another universe
_universeRemoved |= changes.RemovedSecurities.Count == expectedChangesCount &&
// AAPL was added by another universe, so it should be removed when this universe is removed, hence "- 1"
_universeRemoved |= changes.RemovedSecurities.Count == expectedChangesCount - 1 &&
!changes.RemovedSecurities.Any(security => security.Symbol == _aapl) &&
UtcTime.Date >= _delistingDate &&
UtcTime.Date < EndDate;
}
7 changes: 4 additions & 3 deletions Algorithm.CSharp/RsiAlphaModelFrameworkRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -35,9 +35,10 @@ public override void OnEndOfAlgorithm()
{
// We have removed all securities from the universe. The Alpha Model should remove the consolidator
var consolidatorCount = SubscriptionManager.Subscriptions.Sum(s => s.Consolidators.Count);
if (consolidatorCount > 0)
{
throw new RegressionTestException($"The number of consolidators should be zero. Actual: {consolidatorCount}");
// Expect 2 consolidators for AAPL and AIG, which where manually added at the start
if (consolidatorCount != 2)
{
throw new RegressionTestException($"The number of consolidators should be 2. Actual: {consolidatorCount}");
}
}

Loading