Overall Statistics |
Total Trades 56 Average Win 0.05% Average Loss 0% Compounding Annual Return -16.360% Drawdown 3.800% Expectancy 0 Net Profit -2.163% Sharpe Ratio -2.348 Probabilistic Sharpe Ratio 4.275% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha -0.115 Beta -0.003 Annual Standard Deviation 0.05 Annual Variance 0.002 Information Ratio -4.714 Tracking Error 0.144 Treynor Ratio 41.743 Total Fees $0.00 Estimated Strategy Capacity $70000.00 Lowest Capacity Asset SPXW 324PKW8N4MKUM|SPX 31 |
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. # Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. # from AlgorithmImports import * ### <summary> ### This example demonstrates how to add and trade SPX index weekly options ### </summary> class BasicTemplateSPXWeeklyIndexOptionsAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2023, 1, 1) self.SetEndDate(2023, 2, 14) self.SetCash(100000) self.spx = self.AddIndex("SPX", Resolution.Minute) # weekly option SPX contracts spxw = self.AddIndexOption(self.spx.Symbol, "SPXW") # set our strike/expiry filter for this option chain spxw.SetFilter(lambda u: (u.Strikes(-25, 25) .Expiration(0,0) .IncludeWeeklys())) self.spxw_option = spxw.Symbol self.day_low = 10000 self.day_high = 0 #self.SetWarmUp(90, Resolution.Minute) def OnData(self,slice): #day high and day low current_price = self.spx.Price if current_price < self.day_low: self.day_low = current_price if current_price > self.day_high: self.day_high = current_price ratio = current_price/self.day_high #self.Debug(current_price) #self.Debug(int(self.day_low)) #self.Debug(ratio) if self.Portfolio.Invested: return if self.Time.hour <= 10: return delta = 0.05 chain = slice.OptionChains.GetValue(self.spxw_option) if chain is None: return call = [x for x in chain if x.Right == OptionRight.Call] put = [x for x in chain if x.Right == OptionRight.Put] # we sort the contracts to find contract with the right delta put_contract = sorted(put,key = lambda x: abs(abs(x.Greeks.Delta) - delta)) call_contract = sorted(call,key = lambda x: abs(x.Greeks.Delta - delta)) # if found, trade it if len(put_contract) == 0: return else: if current_price <= 1.001*self.day_low: put_ = put_contract[0].Symbol self.MarketOrder(put_, -1) if len(call_contract) == 0: return else: if current_price >= 0.999*self.day_high: call_ = call_contract[0].Symbol self.MarketOrder(call_, -1) def OnOrderEvent(self, orderEvent): self.Debug(str(orderEvent)) def OnEndOfDay(self): self.day_low = 10000 self.day_high = 0