Supported Indicators

Rho

Introduction

Option Rho indicator that calculate the rho of an option

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

Using R Indicator

To create an automatic indicators for Rho, call the R helper method from the QCAlgorithm class. The R method creates a Rho 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 RhoAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Rho _r;

    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);
        _r = R(_option, _mirrorOption);
    }

    public override void OnData(Slice data)
    {
        if (_r.IsReady)
        {
            // The current value of _r is represented by itself (_r)
            // or _r.Current.Value
            Plot("Rho", "r", _r);
            // Plot all properties of r
            Plot("Rho", "impliedvolatility", _r.ImpliedVolatility);
            Plot("Rho", "riskfreerate", _r.RiskFreeRate);
            Plot("Rho", "dividendyield", _r.DividendYield);
            Plot("Rho", "price", _r.Price);
            Plot("Rho", "oppositeprice", _r.OppositePrice);
            Plot("Rho", "underlyingprice", _r.UnderlyingPrice);
        }
    }
}
class RhoAlgorithm(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.r = self.R(self.option, self.mirrorOption)

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

The following reference table describes the R method:

R()1/1

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

Creates a new Rho 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 Rho 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 RhoAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Rho _r;

    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);
        _r = new Rho(_option, interest_rate_model, dividend_yield_model, _mirrorOption);
    }

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
        {      
            _r.Update(new IndicatorDataPoint(_symbol, bar.EndTime, bar.Close));
        }
        if (data.QuoteBars.TryGetValue(_option, out bar))
        {      
            _r.Update(new IndicatorDataPoint(_option, bar.EndTime, bar.Close));
        }
        if (data.QuoteBars.TryGetValue(_mirrorOption, out bar))
        {      
            _r.Update(new IndicatorDataPoint(_mirrorOption, bar.EndTime, bar.Close));
        }
   
        if (_r.IsReady)
        {
            // The current value of _r is represented by itself (_r)
            // or _r.Current.Value
            Plot("Rho", "r", _r);
            // Plot all properties of r
            Plot("Rho", "impliedvolatility", _r.ImpliedVolatility);
            Plot("Rho", "riskfreerate", _r.RiskFreeRate);
            Plot("Rho", "dividendyield", _r.DividendYield);
            Plot("Rho", "price", _r.Price);
            Plot("Rho", "oppositeprice", _r.OppositePrice);
            Plot("Rho", "underlyingprice", _r.UnderlyingPrice);
        }
    }
}
class RhoAlgorithm(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.r = Rho(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.r.Update(IndicatorDataPoint(self.symbol, bar.EndTime, bar.Close))
        bar = slice.QuoteBars.get(self.option)
        if bar:
            self.r.Update(IndicatorDataPoint(self.option, bar.EndTime, bar.Close))
        bar = slice.QuoteBars.get(self.mirrorOption)
        if bar:
            self.r.Update(IndicatorDataPoint(self.mirrorOption, bar.EndTime, bar.Close))
        if self.r.IsReady:
            # The current value of self.r is represented by self.r.Current.Value
            self.plot("Rho", "r", self.r.Current.Value)
            # Plot all attributes of self.r
            self.plot("Rho", "impliedvolatility", self.r.ImpliedVolatility.Current.Value)
            self.plot("Rho", "riskfreerate", self.r.RiskFreeRate.Current.Value)
            self.plot("Rho", "dividendyield", self.r.DividendYield.Current.Value)
            self.plot("Rho", "price", self.r.Price.Current.Value)
            self.plot("Rho", "oppositeprice", self.r.OppositePrice.Current.Value)
            self.plot("Rho", "underlyingprice", self.r.UnderlyingPrice.Current.Value)

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

public class RhoAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Rho _r;

    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);
        _r = new Rho(_option, interest_rate_model, dividend_yield_model, _mirrorOption);
        RegisterIndicator(_symbol, _r, Resolution.Daily);
        RegisterIndicator(_option, _r, Resolution.Daily);
        RegisterIndicator(_mirrorOption, _r, Resolution.Daily);
    }

    public override void OnData(Slice data)
    {
        if (_r.IsReady)
        {
            // The current value of _r is represented by itself (_r)
            // or _r.Current.Value
            Plot("Rho", "r", _r);
            // Plot all properties of r
            Plot("Rho", "impliedvolatility", _r.ImpliedVolatility);
            Plot("Rho", "riskfreerate", _r.RiskFreeRate);
            Plot("Rho", "dividendyield", _r.DividendYield);
            Plot("Rho", "price", _r.Price);
            Plot("Rho", "oppositeprice", _r.OppositePrice);
            Plot("Rho", "underlyingprice", _r.UnderlyingPrice);
        }
    }
}
class RhoAlgorithm(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.r = Rho(self.option, interest_rate_model, dividend_yield_model, self.mirrorOption)
        self.RegisterIndicator(self.symbol, self.r, Resolution.Daily)
        self.RegisterIndicator(self.option, self.r, Resolution.Daily)
        self.RegisterIndicator(self.mirrorOption, self.r, Resolution.Daily)

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

The following reference table describes the Rho constructor:

Rho()1/10

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

Initializes a new instance of the Rho class.

Rho()2/10

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

Initializes a new instance of the Rho class.

Rho()3/10

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

Initializes a new instance of the Rho class.

Rho()4/10

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

Initializes a new instance of the Rho class.

Rho()5/10

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

Initializes a new instance of the Rho class.

Rho()6/10

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

Initializes a new instance of the Rho class.

Rho()7/10

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

Initializes a new instance of the Rho class.

Rho()8/10

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

Initializes a new instance of the Rho class.

Rho()9/10

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

Initializes a new instance of the Rho class.

Rho()10/10

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

Initializes a new instance of the Rho class.

Visualization

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

Rho 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: