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 indicator for Rho, call the Rr helper method from the QCAlgorithm class. The Rr 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, _option, _mirrorOption;
private Rho _r;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 9, 20);
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_option = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920C00564000");
_mirrorOption = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920P00564000");
AddOptionContract(_option, Resolution.Daily);
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);
}
}
} class RhoAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 9, 20)
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920C00564000");
self._mirror_option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920P00564000");
self.add_option_contract(self._option, Resolution.DAILY);
self.add_option_contract(self._mirror_option, Resolution.DAILY);
self._r = self.r(self._option, self._mirror_option)
def on_data(self, slice: Slice) -> None:
if self._r.is_ready:
# The current value of self._r is represented by self._r.current.value
self.plot("Rho", "r", self._r.current.value)For more information about this method, see the QCAlgorithm classQCAlgorithm class.
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. The indicator will only be ready after you prime it with enough data.
public class RhoAlgorithm : QCAlgorithm
{
private Symbol _symbol, _option, _mirrorOption;
private Rho _rho;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 9, 20);
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
var interestRateModel = new InterestRateProvider();
var dividendYieldModel = new DividendYieldProvider(_symbol);
_option = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920C00564000");
_mirrorOption = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920P00564000");
AddOptionContract(_option, Resolution.Daily);
AddOptionContract(_mirrorOption, Resolution.Daily);
_rho = new Rho(_option, interestRateModel, dividendYieldModel, _mirrorOption);
}
public override void OnData(Slice data)
{
if (data.Bars.TryGetValue(_symbol, out var bar))
_rho.Update(new IndicatorDataPoint(_symbol, bar.EndTime, bar.Close));
if (data.QuoteBars.TryGetValue(_option, out var quoteBar))
_rho.Update(new IndicatorDataPoint(_option, quoteBar.EndTime, quoteBar.Close));
if (data.QuoteBars.TryGetValue(_mirrorOption, out quoteBar))
_rho.Update(new IndicatorDataPoint(_mirrorOption, quoteBar.EndTime, quoteBar.Close));
if (_rho.IsReady)
{
// The current value of _rho is represented by itself (_rho)
// or _rho.Current.Value
Plot("Rho", "rho", _rho);
}
}
} class RhoAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 9, 20)
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
interest_rate_model = InterestRateProvider()
dividend_yield_model = DividendYieldProvider(self._symbol)
self._option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920C00564000");
self._mirror_option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920P00564000");
self.add_option_contract(self._option, Resolution.DAILY);
self.add_option_contract(self._mirror_option, Resolution.DAILY);
self._rho = Rho(self._option, interest_rate_model, dividend_yield_model, self._mirror_option)
def on_data(self, slice: Slice) -> None:
bar = slice.bars.get(self._symbol)
if bar:
self._rho.update(IndicatorDataPoint(self._symbol, bar.end_time, bar.close))
bar = slice.quote_bars.get(self._option)
if bar:
self._rho.update(IndicatorDataPoint(self._option, bar.end_time, bar.close))
bar = slice.quote_bars.get(self._mirror_option)
if bar:
self._rho.update(IndicatorDataPoint(self._mirror_option, bar.end_time, bar.close))
if self._rho.is_ready:
# The current value of self._rho is represented by self._rho.current.value
self.plot("Rho", "rho", self._rho.current.value)For more information about this indicator, see its referencereference.
Indicator History
To get the historical data of the Rho indicator, call the IndicatorHistoryself.indicator_history method. This method resets your indicator, makes a history request, and updates the indicator with the historical data. Just like with regular history requests, the IndicatorHistoryindicator_history method supports time periods based on a trailing number of bars, a trailing period of time, or a defined period of time. If you don't provide a resolution argument, it defaults to match the resolution of the security subscription.
public class RhoAlgorithm : QCAlgorithm
{
private Symbol _symbol, _option, _mirrorOption;
private Rho _r;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 9, 20);
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_option = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920C00564000");
_mirrorOption = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920P00564000");
AddOptionContract(_option, Resolution.Daily);
AddOptionContract(_mirrorOption, Resolution.Daily);
_r = R(_option, _mirrorOption);
var indicatorHistory = IndicatorHistory(_r, new[] { _symbol, _option, _mirrorOption }, 100, Resolution.Minute);
var timeSpanIndicatorHistory = IndicatorHistory(_r, new[] { _symbol, _option, _mirrorOption }, TimeSpan.FromDays(10), Resolution.Minute);
var timePeriodIndicatorHistory = IndicatorHistory(_r, new[] { _symbol, _option, _mirrorOption }, new DateTime(2024, 7, 1), new DateTime(2024, 7, 5), Resolution.Minute);
}
} class RhoAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 9, 20)
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920C00564000");
self._mirror_option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920P00564000");
self.add_option_contract(self._option, Resolution.DAILY);
self.add_option_contract(self._mirror_option, Resolution.DAILY);
self._r = self.r(self._option, self._mirror_option)
indicator_history = self.indicator_history(self._r, [self._symbol, self._option, self._mirror_option], 100, Resolution.MINUTE)
timedelta_indicator_history = self.indicator_history(self._r, [self._symbol, self._option, self._mirror_option], timedelta(days=10), Resolution.MINUTE)
time_period_indicator_history = self.indicator_history(self._r, [self._symbol, self._option, self._mirror_option], datetime(2024, 7, 1), datetime(2024, 7, 5), Resolution.MINUTE)