Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Common/Data/Market/Greeks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

using System;
using QuantConnect.Python;

namespace QuantConnect.Data.Market
Expand Down Expand Up @@ -111,6 +112,24 @@ public virtual decimal ThetaPerDay
set { Theta = value * 365m; }
}

/// <summary>
/// Calculates the annualized theta value based on a daily theta input.
/// </summary>
/// <param name="thetaPerDay">The theta value per day to be annualized.</param>
/// <returns>The annualized theta value, calculated as the daily theta multiplied by 365. Returns decimal.MaxValue or
/// decimal.MinValue if the result overflows.</returns>
public static decimal GetSafeTheta(decimal thetaPerDay)
{
try
{
return thetaPerDay * 365m;
}
catch (OverflowException)
{
return thetaPerDay < 0 ? decimal.MinValue : decimal.MaxValue;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="Greeks"/> class.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Common/Data/UniverseSelection/OptionUniverse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 1 addition & 12 deletions Indicators/GreeksIndicators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Loading