diff --git a/project-templates/csharp/intraday-greeks-based-options-selection/Main.cs b/project-templates/csharp/intraday-greeks-based-options-selection/Main.cs index aacc08464b..a2f6c91624 100644 --- a/project-templates/csharp/intraday-greeks-based-options-selection/Main.cs +++ b/project-templates/csharp/intraday-greeks-based-options-selection/Main.cs @@ -81,9 +81,14 @@ public override void Initialize() // Warm-up the option contracts as soon as it is added to the algorithm Settings.SeedInitialPrices = true; - // The EMA/price cross will determine we trade ATM contracts + // The EMA/price cross will determine we trade ATM contracts _index = AddIndex("RUT"); - EMA(_index, 60).Updated += TradeTargetDeltaContract; + var ema = EMA(_index, 60); + // To use a manual EMA instead, replace the automatic indicator above with: + // var ema = new ExponentialMovingAverage(60); + // WarmUpIndicator(_index, ema); + // RegisterIndicator(_index, ema); + ema.Updated += TradeTargetDeltaContract; _optionChainSymbol = QuantConnect.Symbol.CreateCanonicalOption(_index, "RUTW", Market.USA, "?RUTW"); _dividendYieldModel = new DividendYieldProvider(_index); @@ -92,14 +97,14 @@ public override void Initialize() public void TradeTargetDeltaContract(object sender, IndicatorDataPoint current) { // Pace trades every 10 minutes - var lastTrateTime = _lastTicket?.Time ?? DateTime.MinValue; - if ((UtcTime-lastTrateTime).TotalMinutes < 10) return; + var lastTradeTime = _lastTicket?.Time ?? DateTime.MinValue; + if ((UtcTime-lastTradeTime).TotalMinutes < 10) return; var ema = sender as ExponentialMovingAverage; if (!ema.IsReady) return; var spot = _index.Price; - + if (spot > current && spot > ema[-1]) { var atmCall = GetTargetDeltaContract(OptionRight.Call, spot); @@ -144,7 +149,7 @@ private Option GetTargetDeltaContract(OptionRight right, decimal spot, decimal t { return null; } - + return AddOptionContract(targetDeltaContract.Symbol); } } diff --git a/project-templates/python/intraday-greeks-based-options-selection/main.py b/project-templates/python/intraday-greeks-based-options-selection/main.py index 6d40632e32..c47840298e 100644 --- a/project-templates/python/intraday-greeks-based-options-selection/main.py +++ b/project-templates/python/intraday-greeks-based-options-selection/main.py @@ -16,9 +16,14 @@ def initialize(self) -> None: # Warm-up the option contracts as soon as it is added to the algorithm self.settings.seed_initial_prices = True - # The EMA/price cross will determine we trade ATM contracts + # The EMA/price cross will determine we trade ATM contracts self._index = self.add_index("RUT") - self.ema(self._index, 60).updated += self._trade_target_delta_contract + ema = self.ema(self._index, 60) + # To use a manual EMA instead, replace the automatic indicator above with: + # ema = ExponentialMovingAverage(60) + # self.warm_up_indicator(self._index, ema) + # self.register_indicator(self._index, ema) + ema.updated += self._trade_target_delta_contract self._option_chain_symbol = Symbol.create_canonical_option(self._index, "RUTW", Market.USA, "?RUTW") self._dividend_yield_model = DividendYieldProvider(self._index) @@ -31,7 +36,7 @@ def _trade_target_delta_contract(self, ema: ExponentialMovingAverage, current: I if not ema.is_ready: return spot = self._index.price - + if spot > current.value and spot > ema[-1].value: atm_call = self._get_target_delta_contract(OptionRight.CALL, spot) if atm_call and not self.portfolio[atm_call].invested: @@ -48,7 +53,7 @@ def _get_target_delta_contract(self, right: OptionRight, spot: float, target_del if not chain: return None expiry = min([x.expiry for x in chain]) - + def get_delta(x: OptionContract) -> tuple[OptionContract, float]: mirror_option = Symbol.create_option(x.symbol.underlying, "RUT", Market.USA, OptionStyle.EUROPEAN, mirror_option_right, x.strike, x.expiry) delta = Delta(x, self._interest_rate_model, self._dividend_yield_model, mirror_option)