Overall Statistics |
Total Orders 13 Average Win 0.12% Average Loss 0% Compounding Annual Return 2.928% Drawdown 0.900% Expectancy 0 Start Equity 1000000 End Equity 1014545.34 Net Profit 1.455% Sharpe Ratio -3.359 Sortino Ratio -3.215 Probabilistic Sharpe Ratio 78.636% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha -0.051 Beta 0.095 Annual Standard Deviation 0.01 Annual Variance 0 Information Ratio -2.546 Tracking Error 0.08 Treynor Ratio -0.366 Total Fees $1.00 Estimated Strategy Capacity $56000000.00 Lowest Capacity Asset SPXW 32IZK9MH27TYM|SPX 31 Portfolio Turnover 0.03% |
# region imports from AlgorithmImports import * # endregion class StrategyTwoSellPutAndHedge(QCAlgorithm): def initialize(self): self.set_start_date(2024, 1, 1) self.set_end_date(2024, 7, 1) self.set_cash(1000000) # Use the security initializer to get the last known price so we can place orders after we add the option contract self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices))) # Adds the SPX and create the chain symbol spx = self.add_index("SPX").symbol self.index_option_symbol = Symbol.create_canonical_option(spx, "SPXW", Market.USA, "?SPXW") # We will hedge the short puts with SPY self.hedge = self.add_equity("SPY").symbol # We will check for trades every day, so we open new trades after the option expires self.schedule.on(self.date_rules.month_start(spx), self.time_rules.after_market_open(spx, 1), self.trade) def trade(self): # Get all the contracts available for the day option_contract_list = self.option_chain_provider.get_option_contract_list(self.index_option_symbol, self.time) # Filter the OTM puts with expiry to one month expiry = min(option_contract_list, key=lambda symbol: abs((symbol.id.date - self.time).days - 30)).id.date underlying_price = self.securities[self.index_option_symbol.underlying].price puts = filter(lambda symbol: symbol.id.option_right == OptionRight.PUT and symbol.id.date == expiry and symbol.id.strike_price < underlying_price, option_contract_list) # Add the contract to calculate the delta deltas_by_symbol = {} for put in puts: call = Symbol.create_option(put.id.underlying.symbol, "SPXW", put.id.market, put.id.option_style, OptionRight.CALL, put.id.strike_price, put.id.date) deltas = self.indicator_history(Delta(option=put, mirror_option=call), [call, put, call.Underlying], 24, Resolution.HOUR) if deltas.count == 0: continue delta = list(deltas)[-1].current.value deltas_by_symbol[put] = delta put = sorted(deltas_by_symbol.items(), key=lambda x: abs(x[1]+.10))[0][0] self.add_option_contract(put) self.market_order(put, -1, tag=f'Delta={deltas_by_symbol[put]:.3f}') if not self.portfolio[self.hedge].invested: self.market_order(self.hedge, 100)