book
Checkout our new book! Hands on AI Trading with Python, QuantConnect, and AWS Learn More arrow

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.

Select Language:
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.

Select Language:
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/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.
None
update_frequencytimedelta/NoneTypeThe frequency at which new values are inserted into the rolling window for the standard deviation calculation. If the value is None, it defaults to the timedelta representation of resolution. If the value and resolution are None, it defaults to a timedelta of one day.None

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

|μ|σ

where μ is the average of the samples and σ is the standard deviation of the samples.

Select Language:
underlying_security.volatility_model = RelativeStandardDeviationVolatilityModel(timedelta(days=1), 10)

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
period_spantimedeltaThe 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: