Skip to content

Commit

Permalink
Remove dynamic options filter behavior (#7620)
Browse files Browse the repository at this point in the history
* Make options filter non-dynamic by default and explicitly set

* Deprecate ContractSecurityFilterUniverse.OnlyApplyFilterAtMarketOpen

* Add regression algorithm

* Remove dynamic option chain filter behavior
  • Loading branch information
jhonabreul authored Dec 14, 2023
1 parent 59b9e57 commit 442dd77
Show file tree
Hide file tree
Showing 72 changed files with 276 additions and 205 deletions.
20 changes: 5 additions & 15 deletions Algorithm.CSharp/AddRemoveOptionUniverseRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public override void OnData(Slice data)
}
// find first put above market price
return u.IncludeWeeklys()
.Strikes(+1, +1)
.Strikes(+1, +3)
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(1))
.Contracts(c => c.Where(s => s.ID.OptionRight == OptionRight.Put));
});
Expand All @@ -141,16 +141,6 @@ public override void OnData(Slice data)

public override void OnSecuritiesChanged(SecurityChanges changes)
{
if (changes.AddedSecurities.Count > 1)
{
// added event fired for underlying since it was added to the option chain universe
if (changes.AddedSecurities.All(s => s.Symbol != Underlying))
{
var securities = string.Join(Environment.NewLine, changes.AddedSecurities.Select(s => s.Symbol));
throw new Exception($"This algorithm intends to add a single security at a time but added: {changes.AddedSecurities.Count}{Environment.NewLine}{securities}");
}
}

if (changes.AddedSecurities.Any())
{
foreach (var added in changes.AddedSecurities)
Expand Down Expand Up @@ -213,7 +203,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 200618;
public long DataPoints => 200807;

/// <summary>
/// Data Points count of the algorithm history
Expand Down Expand Up @@ -246,10 +236,10 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$6.00"},
{"Estimated Strategy Capacity", "$2000.00"},
{"Estimated Strategy Capacity", "$3000.00"},
{"Lowest Capacity Asset", "GOOCV 305RBR0BSWIX2|GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "1.19%"},
{"OrderListHash", "f5fb175f744ac9021efd92be13fbe386"}
{"Portfolio Turnover", "1.49%"},
{"OrderListHash", "3adcc7ebf4153baabb073a8152e8cb2b"}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public override OrderEvent MarketFill(Security asset, MarketOrder order)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1272232;
public long DataPoints => 1267414;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 475788;
public long DataPoints => 471135;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/BasicTemplateOptionStrategyAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 475777;
public long DataPoints => 471124;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/BasicTemplateOptionsAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 475777;
public long DataPoints => 471124;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1253773;
public long DataPoints => 1252633;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/BasicTemplateOptionsHourlyAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 32492;
public long DataPoints => 32351;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 65536;
public virtual long DataPoints => 57794;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void Initialize()

// weekly option SPX contracts
var spxw = AddIndexOption(spx, "SPXW");
spxw.SetFilter(u => u.Strikes(0, 1)
spxw.SetFilter(u => u.Strikes(-1, +1)
// single week ahead since there are many SPXW contracts and we want to preserve performance
.Expiration(0, 7)
.IncludeWeeklys());
Expand All @@ -66,7 +66,7 @@ public override void OnData(Slice slice)
OptionChain chain;
if (slice.OptionChains.TryGetValue(_spxOption, out chain))
{
// we find the first expiration group of call options and order them in ascending strike
// we find the first expiration group of call options and order them in ascending strike
var contracts = chain
.Where(x => x.Right == OptionRight.Call)
.OrderBy(x => x.Expiry)
Expand Down Expand Up @@ -109,7 +109,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 35451;
public virtual long DataPoints => 40893;

/// <summary>
/// Data Points count of the algorithm history
Expand All @@ -121,31 +121,31 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "4"},
{"Average Win", "0.12%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "8.975%"},
{"Total Trades", "10"},
{"Average Win", "0.47%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "99.729%"},
{"Drawdown", "0.100%"},
{"Expectancy", "62.078"},
{"Net Profit", "0.110%"},
{"Sharpe Ratio", "-14.495"},
{"Expectancy", "24.484"},
{"Net Profit", "0.890%"},
{"Sharpe Ratio", "8.078"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "1.216%"},
{"Probabilistic Sharpe Ratio", "93.697%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "125.16"},
{"Alpha", "-0.014"},
{"Beta", "0.001"},
{"Annual Standard Deviation", "0"},
{"Profit-Loss Ratio", "49.97"},
{"Alpha", "-1.975"},
{"Beta", "0.301"},
{"Annual Standard Deviation", "0.021"},
{"Annual Variance", "0"},
{"Information Ratio", "-103.223"},
{"Tracking Error", "0.069"},
{"Treynor Ratio", "-4.479"},
{"Information Ratio", "-143.477"},
{"Tracking Error", "0.049"},
{"Treynor Ratio", "0.566"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$1800000.00"},
{"Estimated Strategy Capacity", "$13000000.00"},
{"Lowest Capacity Asset", "SPXW XKX6S2GM9PGU|SPX 31"},
{"Portfolio Turnover", "0.03%"},
{"OrderListHash", "3d5b18554d5e10a5edaed0c7cb298192"}
{"Portfolio Turnover", "0.28%"},
{"OrderListHash", "ddc78aa04824180bc36aac3472ae22b4"}
};
}
}
2 changes: 1 addition & 1 deletion Algorithm.CSharp/ComboLegLimitOrderAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 475788;
public override long DataPoints => 471135;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/ComboLimitOrderAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 475788;
public override long DataPoints => 471135;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/ComboMarketOrderAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 475788;
public override long DataPoints => 471135;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/ComboOrderTicketDemoAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 475788;
public long DataPoints => 471135;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/CoveredCallComboLimitOrderAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 465320;
public long DataPoints => 463141;

/// </summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public override void OnData(Slice slice)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 7311;
public long DataPoints => 5265;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 4263205;
public virtual long DataPoints => 4180329;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public override void OnData(Slice slice)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 14931;
public long DataPoints => 18491;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 526804;
public long DataPoints => 522277;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 475777;
public long DataPoints => 471124;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Loading

0 comments on commit 442dd77

Please sign in to comment.