Greeks and Implied Volatility
Key Concepts
Introduction
LEAN provides multiple ways for you to get the Greeks and implied volatility (IV) of Option contracts. There is a daily, pre-calculated dataset based on the end of the previous trading day. There is also a stream of values that are calculated on-the-fly as your algorithm runs.
Greeks on Data Events
The Greeks and IV values that you get from the current Slice are from the price model calculations. These values aren't the same as the values you get in the universe filter function.
public class FutureOptionDataEventsAlgorithm : QCAlgorithm
{
private Future _future;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
Settings.SeedInitialPrices = true;
AddSecurityInitializer(security =>
{
if (security.Type == SecurityType.FutureOption)
{
(security as Option).PriceModel = OptionPriceModels.CrankNicolsonFD();
}
});
_future = AddFuture(Futures.Indices.SP500EMini,
dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
dataMappingMode: DataMappingMode.OpenInterest,
contractDepthOffset: 0);
_future.SetFilter(0, 182);
AddFutureOption(_future.Symbol, universe => universe.Strikes(-5, 5));
}
public override void OnData(Slice data)
{
foreach (var chain in data.OptionChains.Values)
{
foreach (var contract in chain)
{
var iv = contract.ImpliedVolatility;
var delta = contract.Greeks.Delta;
}
}
}
} class BasicFutureOptionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 12, 31)
self.settings.seed_initial_prices = True
self.add_security_initializer(self._custom_security_initializer)
self._future = self.add_future(
Futures.Indices.SP_500_E_MINI,
data_mapping_mode=DataMappingMode.OPEN_INTEREST,
data_normalization_mode=DataNormalizationMode.BACKWARDS_RATIO,
contract_depth_offset=0
)
self._future.set_filter(0, 182)
self.add_future_option(self._future.symbol, lambda universe: universe.strikes(-5, 5))
def on_data(self, data):
for chain in data.option_chains.values():
for contract in chain:
iv = contract.implied_volatility
delta = contract.greeks.delta
def _custom_security_initializer(self, security: Security) -> None:
if security.type == SecurityType.FUTURE_OPTION:
security.price_model = OptionPriceModels.crank_nicolson_fd()
To view all the models LEAN supports, see Supported Models.
Greek Indicators
Option indicators provide daily and intraday values for the Greeks and implied volatility of Future Option contracts.
Examples
For detailed examples on using Option Greeks and Implied Volatility indicators in algorithm, you may refer to the Greeks Indicators page examples.