Supported Indicators

Vega

Introduction

Option Vega indicator that calculate the Vega of an option

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

Using V Indicator

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

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

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

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

The following reference table describes the V method:

V()1/2

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

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

V()2/2

            Variance QuantConnect.Algorithm.QCAlgorithm.V (
    Symbol                           symbol,
    Int32                            period,
    *Nullable<Resolution>      resolution,
    *Func<IBaseData, Decimal>  selector
   )
        

Creates a new Variance indicator. This will return the population variance of samples over the specified period.

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 Vega 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 VegaAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Vega _v;

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

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

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

public class VegaAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Vega _v;

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

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

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

The following reference table describes the Vega constructor:

Vega()1/10

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

Initializes a new instance of the Vega class.

Vega()2/10

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

Initializes a new instance of the Vega class.

Vega()3/10

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

Initializes a new instance of the Vega class.

Vega()4/10

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

Initializes a new instance of the Vega class.

Vega()5/10

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

Initializes a new instance of the Vega class.

Vega()6/10

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

Initializes a new instance of the Vega class.

Vega()7/10

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

Initializes a new instance of the Vega class.

Vega()8/10

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

Initializes a new instance of the Vega class.

Vega()9/10

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

Initializes a new instance of the Vega class.

Vega()10/10

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

Initializes a new instance of the Vega class.

Visualization

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

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