Volatility

Supported Models

Introduction

This page describes all of the pre-built volatility models in LEAN. If none of these models perform exactly how you want, create a custom volatility model.

Null Model

The NullVolatilityModel sets the volatility of the security to zero. It's the default volatility model for the underlying asset of Future Options.

underlyingSecurity.VolatilityModel = VolatilityModel.Null;
underlying_security.volatility_model = VolatilityModel.NULL

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

Standard Deviation of Returns Model

The StandardDeviationOfReturnsVolatilityModel sets the volatility of the security to the annualized sample standard deviation of trailing returns. It's the default volatility model for the underlying asset of Equity Options and Index Options.

underlyingSecurity.VolatilityModel = new StandardDeviationOfReturnsVolatilityModel(30);
underlying_security.volatility_model = StandardDeviationOfReturnsVolatilityModel(30)

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
periodsintThe max number of samples to use when calculating the standard deviation of returns. This value must be greater than two.
resolutionResolution?Resolution/NoneTypeThe resolution of the price data used to calculate the standard deviation. This only has a material effect in live mode. For backtesting, this value does not cause any behavioral changes.
nullNone
updateFrequencyupdate_frequencyTimeSpan?timedelta/NoneTypeThe frequency at which new values are inserted into the rolling window for the standard deviation calculation. If the value is nullNone, it defaults to the TimeSpantimedelta representation of resolution. If the value and resolution are nullNone, it defaults to a TimeSpantimedelta of one day.nullNone

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

Relative Standard Deviation Model

The RelativeStandardDeviationVolatilityModel sets the volatility of the security to the relative standard deviation of its price. In symbols, the value is

$$ \frac{|\mu|}{\sigma} $$

where $\mu$ is the average of the samples and $\sigma$ is the standard deviation of the samples.

underlyingSecurity.VolatilityModel = new RelativeStandardDeviationVolatilityModel(TimeSpan.FromDays(1), 10);
underlying_security.volatility_model = RelativeStandardDeviationVolatilityModel(timedelta(days=1), 10)

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
periodSpanperiod_spanTimeSpantimedeltaThe period of time to wait between each sample of the security price
periodsintThe number of samples to use to calculate the volatility value

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

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: