Greeks and Implied Volatility

Option Indicators

Introduction

This page explains the most popular Option indicators and how to use them with LEAN.

Parameters

The following table describes the arguments that the automatic Option indicators methods accept:

ArgumentData TypeDescriptionDefault Value
symbolSymbolThe contract to use when calculating the indicator values.
mirrorOptionSymbolThe mirror contract to use in parity type calculations.nullNone
riskFreeRatedecimalfloat The risk-free interest rate. If you don't provide a value, the default value is the US primary credit rate from the Interest Rate Provider Model. nullNone
dividendYielddecimalfloat The dividend yield rate. If you don't provide a value, the default value comes from the Dividend Yield Provider Model. nullNone
optionModelOptionPricingModelType The Option pricing model that's used to calculate the Greeks. If you don't provide a value, the default value is OptionPricingModelType.BlackScholes for European Options or OptionPricingModelType.BinomialCoxRossRubinstein for American Options. nullNone
resolutionResolution The resolution of the indicator data. If you don't provide a value, the default value is the resolution of the subscription you have for the Option contract(s). nullNone

To perform implied volatility (IV) smoothing with a put-call pair, pass one of the contracts as the symbol argument and pass the other contract in the pair as the mirrorOption argument. The default IV smoothing method uses the one contract in the pair that's at-the-money or out-of-money to calculate the IV. To change the smoothing function, call the SetSmoothingFunction method of the ImpliedVolatility class/property.

Several different Option pricing models are supported to calculate the IV and Greeks. The following table describes the OptionPricingModelType enumeration members:

Implied Volatility

Implied volatility, , is the market's expectation for the future volatility of an asset and is implied by the price of the assets's Options contracts. You can't observe it in the market but you can derive it from the price of an Option. For more information about implied volatility, see Implied Volatility.

Automatic Indicators

To create an automatic indicator for implied volatility, call the QCAlgorithm.IV method with the Option contract Symbol object(s).

private ImpliedVolatility _impliedvolatility;

public override void Initialize()
{
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    // Example of using the single-contract IV calculation:
    _impliedvolatility = IV(option);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _impliedvolatility = IV(option, mirrorOption);
}
def initialize(self):
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    # Example of using the single-contract IV calculation:
    self.impliedvolatility = self.IV(option)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505, datetime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.impliedvolatility = self.IV(option, mirror_option)

The follow table describes the arguments that the IV method accepts in addition to the standard parameters:

ArgumentData TypeDescriptionDefault Value
periodintThe number of periods to use when calculating the historical volatility for comparison.252

For more information about the IV method, see Using IV Indicator.

Manual Indicators

To create a manual indicator for implied volatility, call the ImpliedVolatility constructor.

private ImpliedVolatility _impliedvolatility;

public override void Initialize()
{
    var equity = AddEquity("AAPL").Symbol;
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    var interestRateProvider = new InterestRateProvider();
    var dividendYieldProvider = new DividendYieldProvider(equity);

    // Example of using the single-contract IV calculation:
    _impliedvolatility = new ImpliedVolatility(option, interestRateProvider, dividendYieldProvider);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _impliedvolatility = new ImpliedVolatility(option, interestRateProvider, dividendYieldProvider, mirrorOption);
}
def initialize(self):
    equity = self.add_equity("AAPL").symbol
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    interest_rate_provider = InterestRateProvider()
    dividend_yield_provider = DividendYieldProvider(equity)

    # Example of using the single-contract IV calculation:
    self.impliedvolatility = ImpliedVolatility(option, interest_rate_provider, dividend_yield_provider)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505m, new DateTime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.impliedvolatility = ImpliedVolatility(option, interest_rate_provider, dividend_yield_provider, mirror_option)

For more information about the ImpliedVolatility constructor, see Using IV Indicator.

Volatility Smoothing

The default IV smoothing method uses the one contract in the pair that's at-the-money or out-of-money to calculate the IV. To change the smoothing function, pass a mirrorOption argument to the IV method or ImpliedVolatility constructor and then call the SetSmoothingFunction method of the resulting ImpliedVolatility object. The follow table describes the arguments of the custom function:

ArgumentData TypeDescription
ivdecimalfloatThe IV of the Option contract.
mirrorIvdecimalfloatThe IV of the mirror Option contract.

The method must return a decimalfloat as the smoothened IV.

private ImpliedVolatility _iv;

public override void Initialize()
{
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);

    _iv = IV(option, mirrorOption);
    // example: take average of the call-put pair
    _iv.SetSmoothingFunction((iv, mirrorIv) => (iv + mirrorIv) * 0.5m);
}
def initialize(self):
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505m, new DateTime(2014, 6, 27))
    self.add_option_contract(mirror_option)

    self.iv = self.IV(option, mirror_option)
    # Example: The average of the call-put pair.
    self.iv.set_smoothing_function(lambda iv, mirror_iv: (iv + mirror_iv) * 0.5)

Delta

Delta, , is the rate of change of the Option price with respect to the price of the underlying asset. It measures the first-order sensitivity of the price to a movement in underlying price. For example, an Option delta of 0.4 means that if the underlying asset moves by 1%, then the value of the Option moves by 0.4 × 1% = 0.4%. For more information about delta, see Delta.

Automatic Indicators

To create an automatic indicator for delta, call the QCAlgorithm.D method with the Option contract Symbol object(s).

private Delta _delta;

public override void Initialize()
{
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    // Example of using the single-contract IV calculation:
    _delta = D(option);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _delta = D(option, mirrorOption);
}
def initialize(self):
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    # Example of using the single-contract IV calculation:
    self.delta = self.D(option)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505, datetime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.delta = self.D(option, mirror_option)

The follow table describes the arguments that the D method accepts in addition to the standard parameters:

ArgumentData TypeDescriptionDefault Value
ivModelOptionPricingModelType The Option pricing model to use to estimate the IV when calculating Delta. If you don't provide a value, the default value is to match the optionModel parameter. nullNone

For more information about the D method, see Using D Indicator.

Manual Indicators

To create a manual indicator for delta, call the Delta constructor.

private Delta _delta;

public override void Initialize()
{
    var equity = AddEquity("AAPL").Symbol;
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    var interestRateProvider = new InterestRateProvider();
    var dividendYieldProvider = new DividendYieldProvider(equity);

    // Example of using the single-contract IV calculation:
    _delta = new Delta(option, interestRateProvider, dividendYieldProvider);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _delta = new Delta(option, interestRateProvider, dividendYieldProvider, mirrorOption);
}
def initialize(self):
    equity = self.add_equity("AAPL").symbol
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    interest_rate_provider = InterestRateProvider()
    dividend_yield_provider = DividendYieldProvider(equity)

    # Example of using the single-contract IV calculation:
    self.delta = Delta(option, interest_rate_provider, dividend_yield_provider)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505m, new DateTime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.delta = Delta(option, interest_rate_provider, dividend_yield_provider, mirror_option)

For more information about the Delta constructor, see Using D Indicator.

Volatility Smoothing

The default IV smoothing method uses the one contract in the pair that's at-the-money or out-of-money to calculate the IV. To change the smoothing function, pass a mirrorOption argument to the indicator method or constructor and then call the SetSmoothingFunction method of the ImpliedVolatility property of the indicator.

// Example: Average IV of the call-put pair.
_delta.ImpliedVolatility.SetSmoothingFunction((iv, mirrorIv) => (iv + mirrorIv) * 0.5m);
# Example: Average IV of the call-put pair.
self.delta.implied_volatility.set_smoothing_function(lambda iv, mirror_iv: (iv + mirror_iv) * 0.5)

For more information about the IV smoothing function, see Implied Volatility.

Gamma

Gamma, , is the rate of change of the portfolio's delta with respect to the underlying asset's price. It represents the second-order sensitivity of the Option to a movement in the underlying asset's price. For more information about Gamma, see Gamma.

Automatic Indicators

To create an automatic indicator for gamma, call the QCAlgorithm.G method with the Option contract Symbol object(s).

private Gamma _gamma;

public override void Initialize()
{
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    // Example of using the single-contract IV calculation:
    _gamma = G(option);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _gamma = G(option, mirrorOption);
}
def initialize(self):
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    # Example of using the single-contract IV calculation:
    self.gamma = self.G(option)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505, datetime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.gamma = self.G(option, mirror_option)

The follow table describes the arguments that the G method accepts in addition to the standard parameters:

ArgumentData TypeDescriptionDefault Value
ivModelOptionPricingModelType The Option pricing model to use to estimate the IV when calculating Gamma. If you don't provide a value, the default value is to match the optionModel parameter. nullNone

For more information about the G method, see Using G Indicator.

Manual Indicators

To create a manual indicator for gamma, call the Gamma constructor.

private Gamma _gamma;

public override void Initialize()
{
    var equity = AddEquity("AAPL").Symbol;
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    var interestRateProvider = new InterestRateProvider();
    var dividendYieldProvider = new DividendYieldProvider(equity);

    // Example of using the single-contract IV calculation:
    _gamma = new Gamma(option, interestRateProvider, dividendYieldProvider);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _gamma = new Gamma(option, interestRateProvider, dividendYieldProvider, mirrorOption);
}
def initialize(self):
    equity = self.add_equity("AAPL").symbol
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    interest_rate_provider = InterestRateProvider()
    dividend_yield_provider = DividendYieldProvider(equity)

    # Example of using the single-contract IV calculation:
    self.gamma = Gamma(option, interest_rate_provider, dividend_yield_provider)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505m, new DateTime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.gamma = Gamma(option, interest_rate_provider, dividend_yield_provider, mirror_option)

For more information about the Gamma constructor, see Using G Indicator.

Volatility Smoothing

The default IV smoothing method uses the one contract in the pair that's at-the-money or out-of-money to calculate the IV. To change the smoothing function, pass a mirrorOption argument to the indicator method or constructor and then call the SetSmoothingFunction method of the ImpliedVolatility property of the indicator.

// Example: Average IV of the call-put pair.
_gamma.ImpliedVolatility.SetSmoothingFunction((iv, mirrorIv) => (iv + mirrorIv) * 0.5m);
# Example: Average IV of the call-put pair.
self.gamma.implied_volatility.set_smoothing_function(lambda iv, mirror_iv: (iv + mirror_iv) * 0.5)

For more information about the IV smoothing function, see Implied Volatility.

Vega

Vega, , is the rate of change in the value of the Option with respect to the volatility of the underlying asset. For more information about vega, see Vega.

Automatic Indicators

To create an automatic indicator for vega, call the QCAlgorithm.V method with the Option contract Symbol object(s).

private Vega _vega;

public override void Initialize()
{
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    // Example of using the single-contract IV calculation:
    _vega = V(option);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _vega = V(option, mirrorOption);
}
def initialize(self):
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    # Example of using the single-contract IV calculation:
    self.vega = self.V(option)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505, datetime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.vega = self.V(option, mirror_option)

The follow table describes the arguments that the V method accepts in addition to the standard parameters:

ArgumentData TypeDescriptionDefault Value
ivModelOptionPricingModelType The Option pricing model to use to estimate the IV when calculating Vega. If you don't provide a value, the default value is to match the optionModel parameter. nullNone

For more information about the V method, see Using V Indicator.

Manual Indicators

To create a manual indicator for vega, call the Vega constructor.

private Vega _vega;

public override void Initialize()
{
    var equity = AddEquity("AAPL").Symbol;
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    var interestRateProvider = new InterestRateProvider();
    var dividendYieldProvider = new DividendYieldProvider(equity);

    // Example of using the single-contract IV calculation:
    _vega = new Vega(option, interestRateProvider, dividendYieldProvider);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _vega = new Vega(option, interestRateProvider, dividendYieldProvider, mirrorOption);
}
def initialize(self):
    equity = self.add_equity("AAPL").symbol
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    interest_rate_provider = InterestRateProvider()
    dividend_yield_provider = DividendYieldProvider(equity)

    # Example of using the single-contract IV calculation:
    self.vega = Vega(option, interest_rate_provider, dividend_yield_provider)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505m, new DateTime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.vega = Vega(option, interest_rate_provider, dividend_yield_provider, mirror_option)

For more information about the Vega constructor, see Using V Indicator.

Volatility Smoothing

The default IV smoothing method uses the one contract in the pair that's at-the-money or out-of-money to calculate the IV. To change the smoothing function, pass a mirrorOption argument to the indicator method or constructor and then call the SetSmoothingFunction method of the ImpliedVolatility property of the indicator.

// Example: Average IV of the call-put pair.
_vega.ImpliedVolatility.SetSmoothingFunction((iv, mirrorIv) => (iv + mirrorIv) * 0.5m);
# Example: Average IV of the call-put pair.
self.vega.implied_volatility.set_smoothing_function(lambda iv, mirror_iv: (iv + mirror_iv) * 0.5)

For more information about the IV smoothing function, see Implied Volatility.

Theta

Theta, , is the rate of change of the value of the Option with respect to the passage of time. It is also known to as the time decay of an Option. For more information about theta, see Theta.

Automatic Indicators

To create an automatic indicator for theta, call the QCAlgorithm.T method with the Option contract Symbol object(s).

private Theta _theta;

public override void Initialize()
{
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    // Example of using the single-contract IV calculation:
    _theta = T(option);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _theta = T(option, mirrorOption);
}
def initialize(self):
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    # Example of using the single-contract IV calculation:
    self.theta = self.T(option)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505, datetime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.theta = self.T(option, mirror_option)

The follow table describes the arguments that the T method accepts in addition to the standard parameters:

ArgumentData TypeDescriptionDefault Value
ivModelOptionPricingModelType The Option pricing model to use to estimate the IV when calculating theta. If you don't provide a value, the default value is to match the optionModel parameter. nullNone

For more information about the T method, see Using T Indicator.

Manual Indicators

To create a manual indicator for theta, call the Theta constructor.

private Theta _theta;

public override void Initialize()
{
    var equity = AddEquity("AAPL").Symbol;
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    var interestRateProvider = new InterestRateProvider();
    var dividendYieldProvider = new DividendYieldProvider(equity);

    // Example of using the single-contract IV calculation:
    _theta = new Theta(option, interestRateProvider, dividendYieldProvider);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _theta = new Theta(option, interestRateProvider, dividendYieldProvider, mirrorOption);
}
def initialize(self):
    equity = self.add_equity("AAPL").symbol
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    interest_rate_provider = InterestRateProvider()
    dividend_yield_provider = DividendYieldProvider(equity)

    # Example of using the single-contract IV calculation:
    self.theta = Theta(option, interest_rate_provider, dividend_yield_provider)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505m, new DateTime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.theta = Theta(option, interest_rate_provider, dividend_yield_provider, mirror_option)

For more information about the Theta constructor, see Using T Indicator.

Volatility Smoothing

The default IV smoothing method uses the one contract in the pair that's at-the-money or out-of-money to calculate the IV. To change the smoothing function, pass a mirrorOption argument to the indicator method or constructor and then call the SetSmoothingFunction method of the ImpliedVolatility property of the indicator.

// Example: Average IV of the call-put pair.
_theta.ImpliedVolatility.SetSmoothingFunction((iv, mirrorIv) => (iv + mirrorIv) * 0.5m);
# Example: Average IV of the call-put pair.
self.theta.implied_volatility.set_smoothing_function(lambda iv, mirror_iv: (iv + mirror_iv) * 0.5)

For more information about the IV smoothing function, see Implied Volatility.

Rho

Rho, , is the rate of change of the value of a derivative with respect to the interest rate.  It is usually small and not a big issue in practice unless the Option is deep in-the-money and has a long horizon. In this case, the interest rate matters because you need to discount a larger cash flow over a longer horizon. For more information about rho, see Rho.

Automatic Indicators

To create an automatic indicator for rho, call the QCAlgorithm.R method with the Option contract Symbol object(s).

private Rho _rho;

public override void Initialize()
{
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    // Example of using the single-contract IV calculation:
    _rho = R(option);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _rho = R(option, mirrorOption);
}
def initialize(self):
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    # Example of using the single-contract IV calculation:
    self.rho = self.R(option)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505, datetime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.rho = self.R(option, mirror_option)

The follow table describes the arguments that the R method accepts in addition to the standard parameters:

ArgumentData TypeDescriptionDefault Value
ivModelOptionPricingModelType The Option pricing model to use to estimate the IV when calculating rho If you don't provide a value, the default value is to match the optionModel parameter. nullNone

Manual Indicators

To create a manual indicator for rho, call the Rho constructor.

private Rho _rho;

public override void Initialize()
{
    var equity = AddEquity("AAPL").Symbol;
    var option = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Put, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(option);

    var interestRateProvider = new InterestRateProvider();
    var dividendYieldProvider = new DividendYieldProvider(equity);

    // Example of using the single-contract IV calculation:
    _rho = new Rho(option, interestRateProvider, dividendYieldProvider);

    // Example of using the using mirror-contract IV calculation:
    var mirrorOption = QuantConnect.Symbol.CreateOption("AAPL", Market.USA, OptionStyle.American, OptionRight.Call, 505m, new DateTime(2014, 6, 27));
    AddOptionContract(mirrorOption);
    _rho = new Rho(option, interestRateProvider, dividendYieldProvider, mirrorOption);
}
def initialize(self):
    equity = self.add_equity("AAPL").symbol
    option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.PUT, 505, datetime(2014, 6, 27))
    self.add_option_contract(option)

    interest_rate_provider = InterestRateProvider()
    dividend_yield_provider = DividendYieldProvider(equity)

    # Example of using the single-contract IV calculation:
    self.rho = Rho(option, interest_rate_provider, dividend_yield_provider)

    # Example of using the using mirror-contract IV calculation:
    mirror_option = Symbol.create_option("AAPL", Market.USA, OptionStyle.AMERICAN, OptionRight.CALL, 505m, new DateTime(2014, 6, 27))
    self.add_option_contract(mirror_option)
    self.rho = Rho(option, interest_rate_provider, dividend_yield_provider, mirror_option)

For more information about the Rho constructor, see Using R Indicator.

Volatility Smoothing

The default IV smoothing method uses the one contract in the pair that's at-the-money or out-of-money to calculate the IV. To change the smoothing function, pass a mirrorOption argument to the indicator method or constructor and then call the SetSmoothingFunction method of the ImpliedVolatility property of the indicator.

// Example: Average IV of the call-put pair.
_rho.ImpliedVolatility.SetSmoothingFunction((iv, mirrorIv) => (iv + mirrorIv) * 0.5m);
# Example: Average IV of the call-put pair.
self.rho.implied_volatility.set_smoothing_function(lambda iv, mirror_iv: (iv + mirror_iv) * 0.5)

For more information about the IV smoothing function, see Implied Volatility.

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: