Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndicatorDataPoint>(_index, ema);
// RegisterIndicator(_index, ema);
ema.Updated += TradeTargetDeltaContract;

_optionChainSymbol = QuantConnect.Symbol.CreateCanonicalOption(_index, "RUTW", Market.USA, "?RUTW");
_dividendYieldModel = new DividendYieldProvider(_index);
Expand All @@ -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);
Expand Down Expand Up @@ -144,7 +149,7 @@ private Option GetTargetDeltaContract(OptionRight right, decimal spot, decimal t
{
return null;
}

return AddOptionContract(targetDeltaContract.Symbol);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand Down