Skip to content

Commit 0854ab8

Browse files
authored
Default option filter now includes weeklies to prevent empty chains (#9162)
* Return weekly contracts if no standard contracts exist * Fix unit and regression tests * Centralize default expiration type flags * Add ExcludeWeeklys() method * Mark IncludeWeeklys() as obsolete since weeklies are now default
1 parent 2c0390f commit 0854ab8

File tree

51 files changed

+311
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+311
-97
lines changed

Algorithm.CSharp/AddOptionUniverseSelectionModelRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public override void OnEndOfAlgorithm()
9696
/// <summary>
9797
/// Data Points count of all timeslices of algorithm
9898
/// </summary>
99-
public long DataPoints => 1658168;
99+
public long DataPoints => 2349547;
100100

101101
/// <summary>
102102
/// Data Points count of the algorithm history

Algorithm.CSharp/BasicTemplateOptionEquityStrategyAlgorithm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override void Initialize()
4444
_optionSymbol = option.Symbol;
4545

4646
// set our strike/expiry filter for this option chain
47-
option.SetFilter(u => u.Strikes(-2, +2)
47+
option.SetFilter(u => u.StandardsOnly().Strikes(-2, +2)
4848
// Expiration method accepts TimeSpan objects or integer for days.
4949
// The following statements yield the same filtering criteria
5050
.Expiration(0, 180));
@@ -73,7 +73,7 @@ public override void OnData(Slice slice)
7373
var higherStrike = callContracts[2].Strike;
7474

7575
var optionStrategy = OptionStrategies.CallButterfly(_optionSymbol, higherStrike, middleStrike, lowerStrike, expiry);
76-
76+
7777
Order(optionStrategy, 10);
7878
}
7979
}

Algorithm.CSharp/BasicTemplateOptionStrategyAlgorithm.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public override void Initialize()
5050
// set our strike/expiry filter for this option chain
5151
// SetFilter method accepts TimeSpan objects or integer for days.
5252
// The following statements yield the same filtering criteria
53-
option.SetFilter(-2, +2, 0, 180);
54-
// option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
53+
option.SetFilter(u => u.StandardsOnly()
54+
.Strikes(-2, +2)
55+
.Expiration(0, 180));
5556

5657
// Adding this to reproduce GH issue #2314
5758
SetWarmup(TimeSpan.FromMinutes(1));
@@ -83,7 +84,7 @@ public override void OnData(Slice slice)
8384
Liquidate();
8485
}
8586

86-
foreach(var kpv in slice.Bars)
87+
foreach (var kpv in slice.Bars)
8788
{
8889
Log($"---> OnData: {Time}, {kpv.Key.Value}, {kpv.Value.Close:0.00}");
8990
}

Algorithm.CSharp/BasicTemplateOptionsAlgorithm.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ public override void Initialize()
4848
_optionSymbol = option.Symbol;
4949

5050
// set our strike/expiry filter for this option chain
51-
option.SetFilter(u => u.Strikes(-2, +2)
51+
option.SetFilter(u => u.StandardsOnly().Strikes(-2, +2)
5252
// Expiration method accepts TimeSpan objects or integer for days.
5353
// The following statements yield the same filtering criteria
54-
.Expiration(0, 180));
55-
// .Expiration(TimeSpan.Zero, TimeSpan.FromDays(180)));
54+
.Expiration(0, 180)); // .Expiration(TimeSpan.Zero, TimeSpan.FromDays(180)));
5655

5756
// use the underlying equity as the benchmark
5857
SetBenchmark(equity.Symbol);

Algorithm.CSharp/BasicTemplateOptionsHourlyAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public override void Initialize()
4848
_optionSymbol = option.Symbol;
4949

5050
// set our strike/expiry filter for this option chain
51-
option.SetFilter(u => u.Strikes(-2, +2)
51+
option.SetFilter(u => u.StandardsOnly().Strikes(-2, +2)
5252
// Expiration method accepts TimeSpan objects or integer for days.
5353
// The following statements yield the same filtering criteria
5454
.Expiration(0, 180));

Algorithm.CSharp/ComboOrderAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override void Initialize()
5858
var option = AddOption(equity.Symbol, fillForward: true);
5959
_optionSymbol = option.Symbol;
6060

61-
option.SetFilter(u => u.Strikes(-2, +2)
61+
option.SetFilter(u => u.StandardsOnly().Strikes(-2, +2)
6262
.Expiration(0, 180));
6363
}
6464

Algorithm.CSharp/ComboOrderTicketDemoAlgorithm.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override void Initialize()
4747
var option = AddOption(equity.Symbol, fillForward: true);
4848
_optionSymbol = option.Symbol;
4949

50-
option.SetFilter(u => u.Strikes(-2, +2)
50+
option.SetFilter(u => u.StandardsOnly().Strikes(-2, +2)
5151
.Expiration(0, 180));
5252
}
5353

@@ -243,8 +243,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
243243
}
244244
if (orderEvent.Quantity != order.Quantity)
245245
{
246-
throw new RegressionTestException($@"OrderEvent quantity should hold the current order Quantity. Got {orderEvent.Quantity
247-
}, expected {order.Quantity}");
246+
throw new RegressionTestException($@"OrderEvent quantity should hold the current order Quantity. Got {orderEvent.Quantity}, expected {order.Quantity}");
248247
}
249248
if (order is ComboLegLimitOrder && orderEvent.LimitPrice == 0)
250249
{
@@ -303,8 +302,7 @@ public override void OnEndOfAlgorithm()
303302
{
304303
throw new RegressionTestException(
305304
"There were expected 6 filled market orders, 3 filled combo limit orders and 6 filled combo leg limit orders, " +
306-
$@"but there were {filledComboMarketOrders.Count} filled market orders, {filledComboLimitOrders.Count
307-
} filled combo limit orders and {filledComboLegLimitOrders.Count} filled combo leg limit orders");
305+
$@"but there were {filledComboMarketOrders.Count} filled market orders, {filledComboLimitOrders.Count} filled combo limit orders and {filledComboLegLimitOrders.Count} filled combo leg limit orders");
308306
}
309307

310308
if (openOrders.Count != 0 || openOrderTickets.Count != 0)

Algorithm.CSharp/CoveredCallComboLimitOrderAlgorithm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public override void Initialize()
4343
var option = AddOption(equity.Symbol);
4444
_optionSymbol = option.Symbol;
4545

46-
option.SetFilter(u => u.Strikes(-1, +1).Expiration(0, 30));
46+
option.SetFilter(u => u.StandardsOnly().Strikes(-1, +1).Expiration(0, 30));
4747
}
4848
/// <summary>
4949
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
@@ -70,7 +70,7 @@ public override void OnData(Slice slice)
7070
var legs = new List<Leg> { Leg.Create(atmContract.Symbol, -1), Leg.Create(atmContract.Symbol.Underlying, 100) };
7171

7272
var comboPrice = underlyingPrice - optionPrice;
73-
if(comboPrice < 734m)
73+
if (comboPrice < 734m)
7474
{
7575
// just to make sure the price makes sense
7676
throw new RegressionTestException($"Unexpected combo price {comboPrice}");

Algorithm.CSharp/DailyOptionChainOpenInterestDataWithStrictDailyEndTimesRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override void Initialize()
4040
SetEndDate(2014, 07, 06);
4141

4242
var option = AddOption("AAPL", Resolution.Daily);
43-
option.SetFilter(-5, +5, 0, 365);
43+
option.SetFilter(u => u.StandardsOnly().Strikes(-5, +5).Expiration(0, 365));
4444

4545
_symbol = option.Symbol;
4646
}

Algorithm.CSharp/LargeQuantityOptionStrategyAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override void Initialize()
4444
var option = AddOption("GOOG");
4545
_optionSymbol = option.Symbol;
4646

47-
option.SetFilter(-2, +2, 0, 180);
47+
option.SetFilter(u => u.StandardsOnly().Strikes(-2, +2).Expiration(0, 180));
4848
}
4949

5050
public override void OnData(Slice slice)

0 commit comments

Comments
 (0)