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, 1, 1); SetSecurityInitializer( new MySecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)) ); _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 MySecurityInitializer : BrokerageModelSecurityInitializer { public MySecurityInitializer(IBrokerageModel brokerageModel, ISecuritySeeder securitySeeder) : base(brokerageModel, securitySeeder) {} public override void Initialize(Security security) { base.Initialize(security); if (security.Type == SecurityType.FutureOption) { (security as Option).PriceModel = OptionPriceModels.CrankNicolsonFD(); } } }
class BasicFutureOptionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2020, 1, 1) self.set_security_initializer( MySecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)) ) 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 class MySecurityInitializer(BrokerageModelSecurityInitializer): def __init__(self, brokerage_model: IBrokerageModel, security_seeder: ISecuritySeeder) -> None: super().__init__(brokerage_model, security_seeder) def initialize(self, security: Security) -> None: super().initialize(security) if security.type == SecurityType.FUTURE_OPTION: security.price_model = OptionPriceModels.CrankNicolsonFD()
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.