Supported Indicators

Delta

Introduction

Option Delta indicator that calculate the delta of an option

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

Using D Indicator

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

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

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

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

The following reference table describes the D method:

D()1/1

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

Creates a new Delta 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 Delta 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 DeltaAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Delta _d;

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

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

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

public class DeltaAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _option, _mirrorOption;
    private Delta _d;

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

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

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

The following reference table describes the Delta constructor:

Delta()1/10

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

Initializes a new instance of the Delta class.

Delta()2/10

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

Initializes a new instance of the Delta class.

Delta()3/10

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

Initializes a new instance of the Delta class.

Delta()4/10

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

Initializes a new instance of the Delta class.

Delta()5/10

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

Initializes a new instance of the Delta class.

Delta()6/10

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

Initializes a new instance of the Delta class.

Delta()7/10

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

Initializes a new instance of the Delta class.

Delta()8/10

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

Initializes a new instance of the Delta class.

Delta()9/10

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

Initializes a new instance of the Delta class.

Delta()10/10

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

Initializes a new instance of the Delta class.

Visualization

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

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