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 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 |
from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Common") from System import * from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Securities.Option import OptionPriceModels from datetime import timedelta, datetime from collections import deque class BasicTemplateOptionsAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2018, 7, 20) self.SetEndDate(2018, 7, 27) self.SetCash(100000) self.symbols = ["SPY"] self.option_symbols = [] # register equities and corresponding options for symbol in self.symbols: option = self.AddOption(symbol, Resolution.Minute) option.SetFilter(-10, +10, timedelta(30), timedelta(60)) # preselect strikes and expiry timeframes option.PriceModel = OptionPriceModels.BinomialJoshi() # needed for implied volatility self.option_symbols.append(option.Symbol) self.SetWarmUp(TimeSpan.FromDays(50)) def DailyEvent(self, slice): self.Log("called during warmup") for i in slice.OptionChains: self.Log("not called during warmup") if i.Key not in self.option_symbols: continue chain = i.Value # select closest expiry date expiry = sorted(chain, key = lambda x: x.Expiry)[0].Expiry # select all calls and puts of this expiry date calls = [x for x in chain if x.Right == 0 and x.Expiry == expiry] puts = [x for x in chain if x.Right == 1 and x.Expiry == expiry] def OnData(self, slice): if self.Time.hour == 16: self.DailyEvent(slice)