Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
class VGRemoveOption(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 4, 25) # Set Start Date self.SetEndDate(2020, 4, 27) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.spy = self.AddEquity("SPY", Resolution.Minute) self.spy.SetDataNormalizationMode(DataNormalizationMode.Raw) def OnData(self, slice): if self.Time.minute == 31 and self.Time.hour == 9: spyPrice = (slice["SPY"].Close) self.subscribeOption("SPY",spyPrice) if self.Time.minute < 40 and self.Time.hour == 9: for i in slice.OptionChains: oc = i.Value self.Debug(str([[x.Right,str(x.Strike),str(x.Expiry),str(x.BidPrice),str(x.AskPrice)] for x in oc])) if self.Time.minute == 40 and self.Time.hour == 9: self.RemoveOptionContract(self.option.Symbol) def subscribeOption(self,tk,spyPrice): contracts = self.OptionChainProvider.GetOptionContractList(tk, self.Time) expiries = sorted(list(set([d.ID.Date for d in contracts]))) expry = expiries[min(range(len(expiries)), key= lambda i: abs(expiries[i] - (self.Time + timedelta(30))))] avl_stks = [d.ID.StrikePrice for d in contracts if (d.ID.Date == expry and d.ID.OptionRight == 0)] atm_stk = avl_stks[min(range(len(avl_stks)), key = lambda i: abs(avl_stks[i]-spyPrice))] for i in contracts: if i.ID.StrikePrice == atm_stk and i.ID.Date == expry and i.ID.OptionRight == 1: self.option = self.AddOptionContract(i, Resolution.Minute)