| Overall Statistics |
|
Total Trades 4 Average Win 0% Average Loss -4.61% Compounding Annual Return -1.530% Drawdown 25.600% Expectancy -1 Net Profit -0.378% Sharpe Ratio 0.311 Probabilistic Sharpe Ratio 36.084% Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.139 Beta -0.969 Annual Standard Deviation 0.629 Annual Variance 0.396 Information Ratio 0.207 Tracking Error 1.226 Treynor Ratio -0.202 Total Fees $2.00 |
from datetime import timedelta
class LongStrangleAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 2, 1)
self.SetEndDate(2020, 4, 30)
self.SetCash(100000)
equity = self.AddEquity("GOOG", Resolution.Minute)
option = self.AddOption("GOOG", Resolution.Minute)
self.symbol = option.Symbol
# set our strike/expiry filter for this option chain
option.SetFilter(-15, 15, timedelta(30), timedelta(60))
# use the underlying equity GOOG as the benchmark
self.SetBenchmark(equity.Symbol)
def OnData(self,slice):
if self.Portfolio.Invested:
return
optionchain = slice.OptionChains
for i in optionchain:
if i.Key != self.symbol: continue
chain = i.Value
# sorted the optionchain by expiration date and choose the furthest date
expiry = sorted(chain,key = lambda x: x.Expiry, reverse=True)[0].Expiry
# filter the call options from the contracts expires on that date
call = [i for i in chain if i.Expiry == expiry and i.Right == 0]
# sorted the contracts according to their strike prices
call_contracts = sorted(call,key = lambda x: x.Strike)
if len(call_contracts) == 0: continue
# choose the deep OTM call option
self.call = call_contracts[-1]
# select the put options which have the same expiration date with the call option
# sort the put options by strike price
put_contracts = sorted([i for i in chain if i.Expiry == expiry and i.Right == 1], key = lambda x: x.Strike)
# choose the deep OTM put option
self.put = put_contracts[0]
self.Buy(self.call.Symbol ,1)
self.Buy(self.put.Symbol ,1)
def OnOrderEvent(self, orderEvent):
self.Log(str(orderEvent))
def OnEndOfDay(self):
quantity = self.Securities["GOOG"].Holdings.Quantity
self.Plot("Holdings", "GOOG", quantity)
if quantity == 0:
self.Plot("Put", "Strike", self.put.Strike)
self.Plot("Put", "Price", self.Securities["GOOG"].Price)