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 |
class BasicTemplateOptionsAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2015, 12, 24) self.SetEndDate(2016, 1, 27) self.SetCash(100000) option = self.AddOption("GOOG") self.option_symbol = option.Symbol # set our strike/expiry filter for this option chain option.SetFilter(-2, +2, timedelta(0), timedelta(180)) # use the underlying equity as the benchmark self.AddEquity('GOOG', Resolution.Minute) self.equity_symbol = "GOOG" def OnData(self,slice): if self.Portfolio.Invested: return chain = slice.OptionChains.GetValue(self.option_symbol) if chain is None: return # we sort the contracts to find at the money (ATM) contract with farthest expiration contracts = sorted(sorted(sorted(chain, \ key = lambda x: abs(chain.Underlying.Price - x.Strike)), \ key = lambda x: x.Expiry, reverse=True), \ key = lambda x: x.Right, reverse=True) # if found, trade it if len(contracts) == 0: return for contract in contracts: self.ConditionalOrderFunction(contract) def ConditionalOrderFunction(self, optionContract): self.Log(f'Last GOOG Price: {self.Securities[self.equity_symbol].Price}') self.Log(f'Contract Underlying Price: {optionContract.UnderlyingLastPrice}') if (self.Securities[self.equity_symbol].Price < optionContract.UnderlyingLastPrice): self._buyTicket = self.Buy(optionContract.Symbol, 10) self.Log(f'Buy ticket opened for {optionContract.Symbol}') def OnOrderEvent(self, orderEvent): self.Log(str(orderEvent))