Overall Statistics |
Total Trades 21 Average Win 0.02% Average Loss 0% Compounding Annual Return 274.715% Drawdown 12.500% Expectancy 0 Net Profit 13.738% Sharpe Ratio 5.044 Probabilistic Sharpe Ratio 65.981% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 1.664 Beta 1.827 Annual Standard Deviation 0.518 Annual Variance 0.268 Information Ratio 7.456 Tracking Error 0.281 Treynor Ratio 1.43 Total Fees $20.00 |
from datetime import timedelta class OptionBot1(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 6, 1) self.SetEndDate(2020,9,1) self.SetCash(100000) self.spy = self.AddEquity("SPY", Resolution.Minute) self.option = self.AddOption("SPY",Resolution.Minute) self.symbol = self.option.Symbol self.option.SetFilter(-2,-1,timedelta(0),timedelta(60)) self.SetBenchmark(self.spy.Symbol) self.options_sold = 0 def OnData(self, data): for kvp in data.OptionChains: if kvp.Key != self.symbol: continue optionchain = kvp.Value put = [x for x in optionchain if x.Right == OptionRight.Put] price = optionchain.Underlying.Price contracts = [x for x in put if price - x.Strike > 0] contracts = sorted(contracts, key = lambda x: x.Expiry, reverse = True) if len(contracts) == 0: continue symbol = contracts[0].Symbol self.Sell(symbol, 1) self.Plot('Option Strike', 'Option Strike', contracts[0].Strike) self.Plot('Option Ask', 'Option Ask', contracts[0].AskPrice) self.Plot('Option Bid', 'Option Bid', contracts[0].BidPrice) self.Plot('Option Price', 'Option Price', contracts[0].UnderlyingLastPrice) self.Plot('Options Profit', 'Options Profit', sum([x.UnrealizedProfit for x in self.Portfolio.Values if x.Type == SecurityType.Option])) self.Plot('Assets Held', 'Assets Held', len([x for x in self.Portfolio.Values if x.Invested])) self.Plot('Non-options Assets Held', 'Non-options Assets Held', len([x for x in self.Portfolio.Values if x.Invested and x.Type != SecurityType.Option])) self.Plot('Options Sold', 'Options Sold', self.options_sold) self.Plot('Option Assets Held', 'Option Assets Held', len([x for x in self.Portfolio.Values if x.Invested and x.Type == SecurityType.Option])) def OnOrderEvent(self, orderEvent): if orderEvent.Symbol.SecurityType == SecurityType.Option: self.options_sold += -orderEvent.FillQuantity self.Log(f'Options Sold: {self.options_sold}')