Supported Indicators

Implied Volatility

Introduction

Implied Volatility indicator that calculate the IV of an option using Black-Scholes Model

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

Using IV Indicator

To create an automatic indicators for ImpliedVolatility, call the IV helper method from the QCAlgorithm class. The IV method creates a ImpliedVolatility 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 Initialize method.

public class ImpliedVolatilityAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private ImpliedVolatility _iv;

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

    public override void OnData(Slice data)
    {
        if (_iv.IsReady)
        {
            // The current value of _iv is represented by itself (_iv)
            // or _iv.Current.Value
            Plot("ImpliedVolatility", "iv", _iv);
            // Plot all properties of iv
            Plot("ImpliedVolatility", "historicalvolatility", _iv.HistoricalVolatility);
            Plot("ImpliedVolatility", "riskfreerate", _iv.RiskFreeRate);
            Plot("ImpliedVolatility", "dividendyield", _iv.DividendYield);
            Plot("ImpliedVolatility", "price", _iv.Price);
            Plot("ImpliedVolatility", "oppositeprice", _iv.OppositePrice);
            Plot("ImpliedVolatility", "underlyingprice", _iv.UnderlyingPrice);
        }
    }
}
class ImpliedVolatilityAlgorithm(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.mirror_option = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 450, datetime(2023, 12, 22))
        self.AddOptionContract(self.mirror_option, Resolution.Daily)
        self.iv = self.IV(self.option, self.mirror_option)

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

The following reference table describes the IV method:

IV()1/1

            ImpliedVolatility QuantConnect.Algorithm.QCAlgorithm.IV (
    Symbol                       symbol,
    *Symbol                      mirrorOption,
    *Nullable<Decimal>     riskFreeRate,
    *Nullable<Decimal>     dividendYield,
    *OptionPricingModelType      optionModel,
    *Int32                       period,
    *Nullable<Resolution>  resolution
   )
        

Creates a new ImpliedVolatility 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 ImpliedVolatility 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 Update method with time/number pair or an IndicatorDataPoint. The indicator will only be ready after you prime it with enough data.

public class ImpliedVolatilityAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private ImpliedVolatility _iv;

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

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
        {      
            _iv.Update(new IndicatorDataPoint(_symbol, bar.EndTime, bar.Close));
        }
        if (data.QuoteBars.TryGetValue(_option, out bar))
        {      
            _iv.Update(new IndicatorDataPoint(_option, bar.EndTime, bar.Close));
        }
        if (data.QuoteBars.TryGetValue(_mirrorOption, out bar))
        {      
            _iv.Update(new IndicatorDataPoint(_mirrorOption, bar.EndTime, bar.Close));
        }
   
        if (_iv.IsReady)
        {
            // The current value of _iv is represented by itself (_iv)
            // or _iv.Current.Value
            Plot("ImpliedVolatility", "iv", _iv);
            // Plot all properties of iv
            Plot("ImpliedVolatility", "historicalvolatility", _iv.HistoricalVolatility);
            Plot("ImpliedVolatility", "riskfreerate", _iv.RiskFreeRate);
            Plot("ImpliedVolatility", "dividendyield", _iv.DividendYield);
            Plot("ImpliedVolatility", "price", _iv.Price);
            Plot("ImpliedVolatility", "oppositeprice", _iv.OppositePrice);
            Plot("ImpliedVolatility", "underlyingprice", _iv.UnderlyingPrice);
        }
    }
}
class ImpliedVolatilityAlgorithm(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.mirror_option = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 450, datetime(2023, 12, 22))
        self.AddOptionContract(self.mirror_option, Resolution.Daily)
        self.iv = ImpliedVolatility(self.option, interest_rate_model, dividend_yield_model, self.mirror_option)

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

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

public class ImpliedVolatilityAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private ImpliedVolatility _iv;

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

    public override void OnData(Slice data)
    {
        if (_iv.IsReady)
        {
            // The current value of _iv is represented by itself (_iv)
            // or _iv.Current.Value
            Plot("ImpliedVolatility", "iv", _iv);
            // Plot all properties of iv
            Plot("ImpliedVolatility", "historicalvolatility", _iv.HistoricalVolatility);
            Plot("ImpliedVolatility", "riskfreerate", _iv.RiskFreeRate);
            Plot("ImpliedVolatility", "dividendyield", _iv.DividendYield);
            Plot("ImpliedVolatility", "price", _iv.Price);
            Plot("ImpliedVolatility", "oppositeprice", _iv.OppositePrice);
            Plot("ImpliedVolatility", "underlyingprice", _iv.UnderlyingPrice);
        }
    }
}
class ImpliedVolatilityAlgorithm(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.mirror_option = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 450, datetime(2023, 12, 22))
        self.AddOptionContract(self.mirror_option, Resolution.Daily)
        self.iv = ImpliedVolatility(self.option, interest_rate_model, dividend_yield_model, self.mirror_option)
        self.RegisterIndicator(self.symbol, self.iv, Resolution.Daily)
        self.RegisterIndicator(self.option, self.iv, Resolution.Daily)
        self.RegisterIndicator(self.mirror_option, self.iv, Resolution.Daily)

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

The following reference table describes the ImpliedVolatility constructor:

ImpliedVolatility()1/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    string                      name,
    Symbol                      option,
    IRiskFreeInterestRateModel  riskFreeRateModel,
    IDividendYieldModel         dividendYieldModel,
    *Symbol                     mirrorOption,
    *OptionPricingModelType     optionModel,
    *int                        period
   )
        

Initializes a new instance of the ImpliedVolatility class.

ImpliedVolatility()2/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    Symbol                      option,
    IRiskFreeInterestRateModel  riskFreeRateModel,
    IDividendYieldModel         dividendYieldModel,
    *Symbol                     mirrorOption,
    *OptionPricingModelType     optionModel,
    *int                        period
   )
        

Initializes a new instance of the ImpliedVolatility class.

ImpliedVolatility()3/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    string                   name,
    Symbol                   option,
    PyObject                 riskFreeRateModel,
    PyObject                 dividendYieldModel,
    *Symbol                  mirrorOption,
    *OptionPricingModelType  optionModel,
    *int                     period
   )
        

Initializes a new instance of the ImpliedVolatility class.

ImpliedVolatility()4/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    Symbol                   option,
    PyObject                 riskFreeRateModel,
    PyObject                 dividendYieldModel,
    *Symbol                  mirrorOption,
    *OptionPricingModelType  optionModel,
    *int                     period
   )
        

Initializes a new instance of the ImpliedVolatility class.

ImpliedVolatility()5/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    string                      name,
    Symbol                      option,
    IRiskFreeInterestRateModel  riskFreeRateModel,
    *decimal                    dividendYield,
    *Symbol                     mirrorOption,
    *OptionPricingModelType     optionModel,
    *int                        period
   )
        

Initializes a new instance of the ImpliedVolatility class.

ImpliedVolatility()6/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    Symbol                      option,
    IRiskFreeInterestRateModel  riskFreeRateModel,
    *decimal                    dividendYield,
    *Symbol                     mirrorOption,
    *OptionPricingModelType     optionModel,
    *int                        period
   )
        

Initializes a new instance of the ImpliedVolatility class.

ImpliedVolatility()7/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    string                   name,
    Symbol                   option,
    PyObject                 riskFreeRateModel,
    *decimal                 dividendYield,
    *Symbol                  mirrorOption,
    *OptionPricingModelType  optionModel,
    *int                     period
   )
        

Initializes a new instance of the ImpliedVolatility class.

ImpliedVolatility()8/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    Symbol                   option,
    PyObject                 riskFreeRateModel,
    *decimal                 dividendYield,
    *Symbol                  mirrorOption,
    *OptionPricingModelType  optionModel,
    *int                     period
   )
        

Initializes a new instance of the ImpliedVolatility class.

ImpliedVolatility()9/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    string                   name,
    Symbol                   option,
    *decimal                 riskFreeRate,
    *decimal                 dividendYield,
    *Symbol                  mirrorOption,
    *OptionPricingModelType  optionModel,
    *int                     period
   )
        

Initializes a new instance of the ImpliedVolatility class.

ImpliedVolatility()10/10

            ImpliedVolatility QuantConnect.Indicators.ImpliedVolatility (
    Symbol                   option,
    *decimal                 riskFreeRate,
    *decimal                 dividendYield,
    *Symbol                  mirrorOption,
    *OptionPricingModelType  optionModel,
    *int                     period
   )
        

Initializes a new instance of the ImpliedVolatility class.

Visualization

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

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