Supported Indicators

Theta

Introduction

Option Theta indicator that calculate the theta of an option

To view the implementation of this indicator, see the LEAN GitHub repository.

Using T Indicator

To create an automatic indicators for Theta, call the T helper method from the QCAlgorithm class. The T method creates a Theta object, hooks it up for automatic updates, and returns it so you can used it in your algorithm. In most cases, you should call the helper method in the Initializeinitialize method.

public class ThetaAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Theta _t;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _option = QuantConnect.Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Put, 450m, new DateTime(2023, 12, 22));
        AddOptionContract(_option, Resolution.Daily);
        _mirrorOption = QuantConnect.Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 450m, new DateTime(2023, 12, 22));
        AddOptionContract(_mirrorOption, Resolution.Daily);
        _t = T(_option, _mirrorOption);
    }

    public override void OnData(Slice data)
    {
        if (_t.IsReady)
        {
            // The current value of _t is represented by itself (_t)
            // or _t.Current.Value
            Plot("Theta", "t", _t);
            // Plot all properties of t
            Plot("Theta", "impliedvolatility", _t.ImpliedVolatility);
            Plot("Theta", "riskfreerate", _t.RiskFreeRate);
            Plot("Theta", "dividendyield", _t.DividendYield);
            Plot("Theta", "price", _t.Price);
            Plot("Theta", "oppositeprice", _t.OppositePrice);
            Plot("Theta", "underlyingprice", _t.UnderlyingPrice);
        }
    }
}
class ThetaAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.option = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Put, 450, datetime(2023, 12, 22))
        self.AddOptionContract(self.option, Resolution.Daily)
        self.mirrorOption = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 450, datetime(2023, 12, 22))
        self.AddOptionContract(self.mirrorOption, Resolution.Daily)
        self.t = self.T(self.option, self.mirrorOption)

    def on_data(self, slice: Slice) -> None:
        if self.t.IsReady:
            # The current value of self.t is represented by self.t.Current.Value
            self.plot("Theta", "t", self.t.Current.Value)
            # Plot all attributes of self.t
            self.plot("Theta", "impliedvolatility", self.t.ImpliedVolatility.Current.Value)
            self.plot("Theta", "riskfreerate", self.t.RiskFreeRate.Current.Value)
            self.plot("Theta", "dividendyield", self.t.DividendYield.Current.Value)
            self.plot("Theta", "price", self.t.Price.Current.Value)
            self.plot("Theta", "oppositeprice", self.t.OppositePrice.Current.Value)
            self.plot("Theta", "underlyingprice", self.t.UnderlyingPrice.Current.Value)

The following reference table describes the T method:

T()1/1

            Theta QuantConnect.Algorithm.QCAlgorithm.T (
    Symbol                                   symbol,
    *Symbol                                  mirrorOption,
    *Nullable<Decimal>                 riskFreeRate,
    *Nullable<Decimal>                 dividendYield,
    *OptionPricingModelType                  optionModel,
    *Nullable<OptionPricingModelType>  ivModel,
    *Nullable<Resolution>              resolution
   )
        

Creates a new Theta indicator for the symbol The indicator will be automatically updated on the symbol's subscription resolution.

If you don't provide a resolution, it defaults to the security resolution. If you provide a resolution, it must be greater than or equal to the resolution of the security. For instance, if you subscribe to hourly data for a security, you should update its indicator with data that spans 1 hour or longer.

For more information about the selector argument, see Alternative Price Fields.

For more information about plotting indicators, see Plotting Indicators.

You can manually create a Theta indicator, so it doesn't automatically update. Manual indicators let you update their values with any data you choose.

Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Updateupdate method with time/number pair or an IndicatorDataPoint. The indicator will only be ready after you prime it with enough data.

public class ThetaAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Theta _t;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _option = QuantConnect.Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Put, 450m, new DateTime(2023, 12, 22));
        AddOptionContract(_option, Resolution.Daily);
        _mirrorOption = QuantConnect.Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 450m, new DateTime(2023, 12, 22));
        AddOptionContract(_mirrorOption, Resolution.Daily);
        _t = new Theta(_option, interest_rate_model, dividend_yield_model, _mirrorOption);
    }

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
        {      
            _t.Update(new IndicatorDataPoint(_symbol, bar.EndTime, bar.Close));
        }
        if (data.QuoteBars.TryGetValue(_option, out bar))
        {      
            _t.Update(new IndicatorDataPoint(_option, bar.EndTime, bar.Close));
        }
        if (data.QuoteBars.TryGetValue(_mirrorOption, out bar))
        {      
            _t.Update(new IndicatorDataPoint(_mirrorOption, bar.EndTime, bar.Close));
        }
   
        if (_t.IsReady)
        {
            // The current value of _t is represented by itself (_t)
            // or _t.Current.Value
            Plot("Theta", "t", _t);
            // Plot all properties of t
            Plot("Theta", "impliedvolatility", _t.ImpliedVolatility);
            Plot("Theta", "riskfreerate", _t.RiskFreeRate);
            Plot("Theta", "dividendyield", _t.DividendYield);
            Plot("Theta", "price", _t.Price);
            Plot("Theta", "oppositeprice", _t.OppositePrice);
            Plot("Theta", "underlyingprice", _t.UnderlyingPrice);
        }
    }
}
class ThetaAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.option = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Put, 450, datetime(2023, 12, 22))
        self.AddOptionContract(self.option, Resolution.Daily)
        self.mirrorOption = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 450, datetime(2023, 12, 22))
        self.AddOptionContract(self.mirrorOption, Resolution.Daily)
        self.t = Theta(self.option, interest_rate_model, dividend_yield_model, self.mirrorOption)

    def on_data(self, slice: Slice) -> None:
        bar = slice.Bars.get(self.symbol)
        if bar:
            self.t.Update(IndicatorDataPoint(self.symbol, bar.EndTime, bar.Close))
        bar = slice.QuoteBars.get(self.option)
        if bar:
            self.t.Update(IndicatorDataPoint(self.option, bar.EndTime, bar.Close))
        bar = slice.QuoteBars.get(self.mirrorOption)
        if bar:
            self.t.Update(IndicatorDataPoint(self.mirrorOption, bar.EndTime, bar.Close))
        if self.t.IsReady:
            # The current value of self.t is represented by self.t.Current.Value
            self.plot("Theta", "t", self.t.Current.Value)
            # Plot all attributes of self.t
            self.plot("Theta", "impliedvolatility", self.t.ImpliedVolatility.Current.Value)
            self.plot("Theta", "riskfreerate", self.t.RiskFreeRate.Current.Value)
            self.plot("Theta", "dividendyield", self.t.DividendYield.Current.Value)
            self.plot("Theta", "price", self.t.Price.Current.Value)
            self.plot("Theta", "oppositeprice", self.t.OppositePrice.Current.Value)
            self.plot("Theta", "underlyingprice", self.t.UnderlyingPrice.Current.Value)

To register a manual indicator for automatic updates with the security data, call the RegisterIndicator method.

public class ThetaAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Theta _t;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _option = QuantConnect.Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Put, 450m, new DateTime(2023, 12, 22));
        AddOptionContract(_option, Resolution.Daily);
        _mirrorOption = QuantConnect.Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 450m, new DateTime(2023, 12, 22));
        AddOptionContract(_mirrorOption, Resolution.Daily);
        _t = new Theta(_option, interest_rate_model, dividend_yield_model, _mirrorOption);
        RegisterIndicator(_symbol, _t, Resolution.Daily);
        RegisterIndicator(_option, _t, Resolution.Daily);
        RegisterIndicator(_mirrorOption, _t, Resolution.Daily);
    }

    public override void OnData(Slice data)
    {
        if (_t.IsReady)
        {
            // The current value of _t is represented by itself (_t)
            // or _t.Current.Value
            Plot("Theta", "t", _t);
            // Plot all properties of t
            Plot("Theta", "impliedvolatility", _t.ImpliedVolatility);
            Plot("Theta", "riskfreerate", _t.RiskFreeRate);
            Plot("Theta", "dividendyield", _t.DividendYield);
            Plot("Theta", "price", _t.Price);
            Plot("Theta", "oppositeprice", _t.OppositePrice);
            Plot("Theta", "underlyingprice", _t.UnderlyingPrice);
        }
    }
}
class ThetaAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.option = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Put, 450, datetime(2023, 12, 22))
        self.AddOptionContract(self.option, Resolution.Daily)
        self.mirrorOption = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 450, datetime(2023, 12, 22))
        self.AddOptionContract(self.mirrorOption, Resolution.Daily)
        self.t = Theta(self.option, interest_rate_model, dividend_yield_model, self.mirrorOption)
        self.RegisterIndicator(self.symbol, self.t, Resolution.Daily)
        self.RegisterIndicator(self.option, self.t, Resolution.Daily)
        self.RegisterIndicator(self.mirrorOption, self.t, Resolution.Daily)

    def on_data(self, slice: Slice) -> None:
        if self.t.IsReady:
            # The current value of self.t is represented by self.t.Current.Value
            self.plot("Theta", "t", self.t.Current.Value)
            # Plot all attributes of self.t
            self.plot("Theta", "impliedvolatility", self.t.ImpliedVolatility.Current.Value)
            self.plot("Theta", "riskfreerate", self.t.RiskFreeRate.Current.Value)
            self.plot("Theta", "dividendyield", self.t.DividendYield.Current.Value)
            self.plot("Theta", "price", self.t.Price.Current.Value)
            self.plot("Theta", "oppositeprice", self.t.OppositePrice.Current.Value)
            self.plot("Theta", "underlyingprice", self.t.UnderlyingPrice.Current.Value)

The following reference table describes the Theta constructor:

Theta()1/10

            Theta QuantConnect.Indicators.Theta (
    string                      name,
    Symbol                      option,
    IRiskFreeInterestRateModel  riskFreeRateModel,
    IDividendYieldModel         dividendYieldModel,
    *Symbol                     mirrorOption,
    *OptionPricingModelType     optionModel,
    *OptionPricingModelType?    ivModel
   )
        

Initializes a new instance of the Theta class.

Theta()2/10

            Theta QuantConnect.Indicators.Theta (
    Symbol                      option,
    IRiskFreeInterestRateModel  riskFreeRateModel,
    IDividendYieldModel         dividendYieldModel,
    *Symbol                     mirrorOption,
    *OptionPricingModelType     optionModel,
    *OptionPricingModelType?    ivModel
   )
        

Initializes a new instance of the Theta class.

Theta()3/10

            Theta QuantConnect.Indicators.Theta (
    string                    name,
    Symbol                    option,
    PyObject                  riskFreeRateModel,
    PyObject                  dividendYieldModel,
    *Symbol                   mirrorOption,
    *OptionPricingModelType   optionModel,
    *OptionPricingModelType?  ivModel
   )
        

Initializes a new instance of the Theta class.

Theta()4/10

            Theta QuantConnect.Indicators.Theta (
    Symbol                    option,
    PyObject                  riskFreeRateModel,
    PyObject                  dividendYieldModel,
    *Symbol                   mirrorOption,
    *OptionPricingModelType   optionModel,
    *OptionPricingModelType?  ivModel
   )
        

Initializes a new instance of the Theta class.

Theta()5/10

            Theta QuantConnect.Indicators.Theta (
    string                      name,
    Symbol                      option,
    IRiskFreeInterestRateModel  riskFreeRateModel,
    *decimal                    dividendYield,
    *Symbol                     mirrorOption,
    *OptionPricingModelType     optionModel,
    *OptionPricingModelType?    ivModel
   )
        

Initializes a new instance of the Theta class.

Theta()6/10

            Theta QuantConnect.Indicators.Theta (
    Symbol                      option,
    IRiskFreeInterestRateModel  riskFreeRateModel,
    *decimal                    dividendYield,
    *Symbol                     mirrorOption,
    *OptionPricingModelType     optionModel,
    *OptionPricingModelType?    ivModel
   )
        

Initializes a new instance of the Theta class.

Theta()7/10

            Theta QuantConnect.Indicators.Theta (
    string                    name,
    Symbol                    option,
    PyObject                  riskFreeRateModel,
    *decimal                  dividendYield,
    *Symbol                   mirrorOption,
    *OptionPricingModelType   optionModel,
    *OptionPricingModelType?  ivModel
   )
        

Initializes a new instance of the Theta class.

Theta()8/10

            Theta QuantConnect.Indicators.Theta (
    Symbol                    option,
    PyObject                  riskFreeRateModel,
    *decimal                  dividendYield,
    *Symbol                   mirrorOption,
    *OptionPricingModelType   optionModel,
    *OptionPricingModelType?  ivModel
   )
        

Initializes a new instance of the Theta class.

Theta()9/10

            Theta QuantConnect.Indicators.Theta (
    string                    name,
    Symbol                    option,
    *decimal                  riskFreeRate,
    *decimal                  dividendYield,
    *Symbol                   mirrorOption,
    *OptionPricingModelType   optionModel,
    *OptionPricingModelType?  ivModel
   )
        

Initializes a new instance of the Theta class.

Theta()10/10

            Theta QuantConnect.Indicators.Theta (
    Symbol                    option,
    *decimal                  riskFreeRate,
    *decimal                  dividendYield,
    *Symbol                   mirrorOption,
    *OptionPricingModelType   optionModel,
    *OptionPricingModelType?  ivModel
   )
        

Initializes a new instance of the Theta class.

Visualization

The following image shows plot values of selected properties of Theta using the plotly library.

Theta line plot.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: