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:
Argument | Data Type | Description | Default Value |
---|---|---|---|
periods | int | The max number of samples to use when calculating the standard deviation of returns. This value must be greater than two. | |
resolution | Resolution? Resolution /NoneType | The 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. | null None |
updateFrequency update_frequency | TimeSpan? timedelta /NoneType | The frequency at which new values are inserted into the rolling window for the standard deviation calculation. If the value is null None , it defaults to the TimeSpan timedelta representation of resolution . If the value and resolution are null None , it defaults to a TimeSpan timedelta of one day. | null 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 $\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:
Argument | Data Type | Description | Default Value |
---|---|---|---|
periodSpan period_span | TimeSpan timedelta | The period of time to wait between each sample of the security price | |
periods | int | The number of samples to use to calculate the volatility value |
To view the implementation of this model, see the LEAN GitHub repository.