Overall Statistics |
Total Trades 1 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 $1.00 Estimated Strategy Capacity $220000000.00 Lowest Capacity Asset SPY 31JDGNP5TATEU|SPY R735QTJ8XC9X |
class SmoothBlueBat(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 12, 9) self.SetCash(100000) self.SetSecurityInitializer(self.security_initializer) self.symbol = self.AddEquity("SPY", Resolution.Minute).Symbol self.contract = None self.ordered = False def security_initializer(self, security): if security.Type == SecurityType.Equity: security.SetDataNormalizationMode(DataNormalizationMode.Raw) def OnData(self, data): if not (data.ContainsKey(self.symbol) and data[self.symbol] is not None): return if self.ordered: self.Quit() return if self.contract is None: min_strike = data[self.symbol].Price - 20 max_strike = data[self.symbol].Price + 20 min_expiry = self.Time + timedelta(days=1) max_expiry = self.Time + timedelta(days=90) sorted_function = lambda x: x.BidSize self.contract = self.GetOption(data, self.symbol, OptionRight.Put, min_strike, max_strike, min_expiry, max_expiry, sorted_function, False) if data.ContainsKey(self.contract.Symbol): self.MarketOrder(self.contract.Symbol, 1) self.ordered = True def GetOption(self,slice,underlying,optionright,MinStrike,\ MaxStrike,MinExpiry,MaxExpiry,sortedfunction,reverse): ## Get list of Options Contracts for a specific time chainProvider = self.OptionChainProvider contracts = chainProvider.GetOptionContractList(underlying, self.Time) if len(contracts) == 0: return filtered_options = [x for x in contracts if x.ID.OptionRight == optionright and\ x.ID.StrikePrice > MinStrike and\ x.ID.StrikePrice < MaxStrike and\ x.ID.Date > MinExpiry and\ x.ID.Date < MaxExpiry] if len(filtered_options) == 0: return added_contracts = [] for x in filtered_options: option = self.AddOptionContract(x, Resolution.Minute) optionsymbol = self.Securities[option.Symbol] added_contracts.append(optionsymbol) #added_contracts.append(option) sorted_options=sorted(added_contracts,key=sortedfunction,reverse=reverse) selected = sorted_options[0] for x in sorted_options: if x != selected: self.RemoveSecurity(x.Symbol) return selected