Skip to content

Commit

Permalink
Modify helper method to calculate settlement time instead of expirati…
Browse files Browse the repository at this point in the history
…on time
  • Loading branch information
jhonabreul committed Dec 13, 2024
1 parent 45fb613 commit c648de8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
19 changes: 10 additions & 9 deletions Common/Securities/Option/OptionSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,23 @@ public static DateTime GetLastDayOfTrading(Symbol symbol)
}

/// <summary>
/// Returns the actual expiration date time, adjusted to market close of the expiration day.
/// Returns the settlement date time of the option contract.
/// </summary>
/// <param name="symbol">The option contract symbol</param>
/// <returns>The expiration date time, adjusted to market close of the expiration day</returns>
public static DateTime GetExpirationDateTime(Symbol symbol)
/// <returns>The settlement date time</returns>
public static DateTime GetSettlementDateTime(Symbol symbol)
{
if (!TryGetExpirationDateTime(symbol, out var expiryTime, out _))
if (!TryGetExpirationDateTime(symbol, out var expiryTime, out var exchangeHours))
{
throw new ArgumentException("The symbol must be an option type");
}

// Standard index options are AM-settled, which means they settle on market open of the expiration date
if (expiryTime.Date == symbol.ID.Date.Date && symbol.SecurityType == SecurityType.IndexOption && IsStandard(symbol))
{
expiryTime = exchangeHours.GetNextMarketOpen(expiryTime.Date, false);
}

return expiryTime;
}

Expand Down Expand Up @@ -189,11 +195,6 @@ private static bool TryGetExpirationDateTime(Symbol symbol, out DateTime expiryT
}
expiryTime = symbol.ID.Date.AddDays(1).Date;
}
// Standard index options are AM-settled, which means they settle on market open of the last trading date
else if (symbol.SecurityType == SecurityType.IndexOption && IsStandard(symbol))
{
expiryTime = exchangeHours.GetNextMarketOpen(expiryTime.Date, false);
}

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Indicators/ImpliedVolatility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ protected override decimal Calculate(IndicatorDataPoint input)
DividendYield.Update(time, _dividendYieldModel.GetDividendYield(time, UnderlyingPrice.Current.Value));

var timeTillExpiry = Convert.ToDecimal(
OptionGreekIndicatorsHelper.TimeTillExpiry(Securities.Option.OptionSymbol.GetExpirationDateTime(OptionSymbol), time));
OptionGreekIndicatorsHelper.TimeTillExpiry(Securities.Option.OptionSymbol.GetSettlementDateTime(OptionSymbol), time));
_impliedVolatility = CalculateIV(timeTillExpiry);
}

Expand Down
2 changes: 1 addition & 1 deletion Indicators/OptionGreekIndicatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected override decimal Calculate(IndicatorDataPoint input)
DividendYield.Update(time, _dividendYieldModel.GetDividendYield(time, UnderlyingPrice.Current.Value));

var timeTillExpiry = Convert.ToDecimal(
OptionGreekIndicatorsHelper.TimeTillExpiry(Securities.Option.OptionSymbol.GetExpirationDateTime(OptionSymbol), time));
OptionGreekIndicatorsHelper.TimeTillExpiry(Securities.Option.OptionSymbol.GetSettlementDateTime(OptionSymbol), time));
try
{
_greekValue = timeTillExpiry < 0 ? 0 : CalculateGreek(timeTillExpiry);
Expand Down
6 changes: 3 additions & 3 deletions Tests/Common/Securities/Options/OptionSymbolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ private static IEnumerable<TestCaseData> ExpirationDateTimeTestCases()
}

[TestCaseSource(nameof(ExpirationDateTimeTestCases))]
public void CalculatesExpirationDateTime(Symbol symbol, DateTime expectedExpirationDateTime)
public void CalculatesSettlementDateTime(Symbol symbol, DateTime expectedSettlementDateTime)
{
var expirationDateTime = OptionSymbol.GetExpirationDateTime(symbol);
Assert.AreEqual(expectedExpirationDateTime, expirationDateTime);
var settlementDateTime = OptionSymbol.GetSettlementDateTime(symbol);
Assert.AreEqual(expectedSettlementDateTime, settlementDateTime);
}
}
}

0 comments on commit c648de8

Please sign in to comment.