Skip to content

Commit 33e8fa9

Browse files
committed
TEST
1 parent e26a190 commit 33e8fa9

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

Common/Securities/Option/DefaultOptionAssignmentModel.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
using System;
17+
using QuantConnect.Logging;
1718
using QuantConnect.Orders;
1819
using QuantConnect.Orders.Fees;
1920

@@ -55,34 +56,32 @@ public virtual OptionAssignmentResult GetAssignment(OptionAssignmentParameters p
5556
var underlying = parameters.Option.Underlying;
5657

5758
// we take only options that expire soon
58-
try
59+
if ((option.Symbol.ID.OptionStyle == OptionStyle.American && option.Symbol.ID.Date - option.LocalTime <= _priorExpiration ||
60+
option.Symbol.ID.OptionStyle == OptionStyle.European && option.Symbol.ID.Date.Date == option.LocalTime.Date)
61+
// we take only deep ITM strikes
62+
&& IsDeepInTheMoney(option))
5963
{
60-
if ((option.Symbol.ID.OptionStyle == OptionStyle.American && option.Symbol.ID.Date - option.LocalTime <= _priorExpiration ||
61-
option.Symbol.ID.OptionStyle == OptionStyle.European && option.Symbol.ID.Date.Date == option.LocalTime.Date)
62-
// we take only deep ITM strikes
63-
&& IsDeepInTheMoney(option))
64+
// we estimate P/L
65+
var potentialPnL = EstimateArbitragePnL(option, (OptionHolding)option.Holdings, underlying);
66+
if (potentialPnL > 0)
6467
{
65-
// we estimate P/L
66-
var potentialPnL = EstimateArbitragePnL(option, (OptionHolding)option.Holdings, underlying);
67-
if (potentialPnL > 0)
68-
{
69-
return new OptionAssignmentResult(option.Holdings.AbsoluteQuantity, "Simulated option assignment before expiration");
70-
}
68+
return new OptionAssignmentResult(option.Holdings.AbsoluteQuantity, "Simulated option assignment before expiration");
7169
}
72-
73-
return OptionAssignmentResult.Null;
74-
}
75-
catch (DivideByZeroException e)
76-
{
77-
throw new DivideByZeroException($"Error in DefaultOptionAssignmentModel.GetAssignment({option.Symbol.Value} :: {underlying.Symbol.ID} :: {underlying.Symbol.Value}): {e.Message}", e);
7870
}
71+
72+
return OptionAssignmentResult.Null;
7973
}
8074

8175
private bool IsDeepInTheMoney(Option option)
8276
{
8377
var symbol = option.Symbol;
8478
var underlyingPrice = option.Underlying.Close;
8579

80+
if (underlyingPrice == 0)
81+
{
82+
Log.Error($"-----------> Underlying price is 0 for {option.Symbol}. Cannot determine if option is deep in the money.");
83+
}
84+
8685
// For some options, the price is based on a fraction of the underlying, such as for NQX.
8786
// Therefore, for those options we need to scale the price when comparing it with the
8887
// underlying. For that reason we use option.ScaledStrikePrice instead of

0 commit comments

Comments
 (0)