From 7ea5718843e61622fc9b27e89fdf496cd74dbdc1 Mon Sep 17 00:00:00 2001 From: Josue Nina Date: Fri, 20 Mar 2026 16:52:22 -0500 Subject: [PATCH] Add GetSafeTheta to handle decimal overflow --- Common/Data/Market/Greeks.cs | 19 +++++++++++++++++++ .../Data/UniverseSelection/OptionUniverse.cs | 2 +- Indicators/GreeksIndicators.cs | 13 +------------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Common/Data/Market/Greeks.cs b/Common/Data/Market/Greeks.cs index 16d67ec61bd6..a054207b33fe 100644 --- a/Common/Data/Market/Greeks.cs +++ b/Common/Data/Market/Greeks.cs @@ -13,6 +13,7 @@ * limitations under the License. */ +using System; using QuantConnect.Python; namespace QuantConnect.Data.Market @@ -111,6 +112,24 @@ public virtual decimal ThetaPerDay set { Theta = value * 365m; } } + /// + /// Calculates the annualized theta value based on a daily theta input. + /// + /// The theta value per day to be annualized. + /// The annualized theta value, calculated as the daily theta multiplied by 365. Returns decimal.MaxValue or + /// decimal.MinValue if the result overflows. + public static decimal GetSafeTheta(decimal thetaPerDay) + { + try + { + return thetaPerDay * 365m; + } + catch (OverflowException) + { + return thetaPerDay < 0 ? decimal.MinValue : decimal.MaxValue; + } + } + /// /// Initializes a new instance of the class. /// diff --git a/Common/Data/UniverseSelection/OptionUniverse.cs b/Common/Data/UniverseSelection/OptionUniverse.cs index b2c30b7412dd..b8909c81d705 100644 --- a/Common/Data/UniverseSelection/OptionUniverse.cs +++ b/Common/Data/UniverseSelection/OptionUniverse.cs @@ -257,7 +257,7 @@ private class PreCalculatedGreeks : Greeks public override decimal Vega => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 2); - public override decimal Theta => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 3) * 365m; + public override decimal Theta => GetSafeTheta(_csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 3)); public override decimal Rho => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 4); diff --git a/Indicators/GreeksIndicators.cs b/Indicators/GreeksIndicators.cs index 604c60a396d4..d51b1c7d178d 100644 --- a/Indicators/GreeksIndicators.cs +++ b/Indicators/GreeksIndicators.cs @@ -78,18 +78,7 @@ public Greeks Greeks { get { - var theta = 0m; - var thetaPerDay = ThetaPerDay.Current.Value; - try - { - theta = thetaPerDay * 365m; - } - catch (OverflowException) - { - theta = thetaPerDay < 0 ? decimal.MinValue : decimal.MaxValue; - } - - return new Greeks(Delta, Gamma, Vega, theta, Rho, 0m); + return new Greeks(Delta, Gamma, Vega, Greeks.GetSafeTheta(ThetaPerDay.Current.Value), Rho, 0m); } }