| Overall Statistics |
|
Total Trades 9 Average Win 1.97% Average Loss -1.50% Compounding Annual Return -6.585% Drawdown 1.100% Expectancy -0.074 Net Profit -1.107% Sharpe Ratio -3.299 Probabilistic Sharpe Ratio 0.217% Loss Rate 60% Win Rate 40% Profit-Loss Ratio 1.32 Alpha -0.003 Beta -0.042 Annual Standard Deviation 0.014 Annual Variance 0 Information Ratio -8.103 Tracking Error 0.131 Treynor Ratio 1.097 Total Fees $6.00 Estimated Strategy Capacity $25000.00 Lowest Capacity Asset GOOCV WKNGGL4W0OYU|GOOCV VP83T1ZUHROL |
#region imports
from AlgorithmImports import *
#endregion
from datetime import timedelta
class ButterflySpreadAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017, 4, 1)
self.SetEndDate(2017, 5, 30)
self.SetCash(150000)
equity = self.AddEquity("GOOG")
option = self.AddOption("GOOG")
self.symbol = option.Symbol
# set our strike/expiry filter for this option chain
option.SetFilter(-9, 9, 30, 60)
# use the underlying equity GOOG as the benchmark
self.SetBenchmark(equity.Symbol)
def OnData(self,slice):
# if there is no securities in portfolio, trade the options
if self.Portfolio.Invested:
return
chain = slice.OptionChains.get(self.symbol)
if not chain:
return
# 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
calls = [i for i in chain if i.Expiry == expiry and i.Right == OptionRight.Call]
if not calls:
return
# sorted the contracts according to their strike prices
calls = sorted(calls, key=lambda x: x.Strike)
# choose OTM call
otm_call = calls[-1].Symbol
# choose ITM call
itm_call = calls[0].Symbol
# choose ATM call
atm_call = sorted(calls, key=lambda x: abs(chain.Underlying.Price - x.Strike))[0].Symbol
self.Sell(atm_call, 2)
self.Buy(itm_call, 1)
self.Buy(otm_call, 1)
def OnOrderEvent(self, orderEvent):
self.Log(f'{orderEvent}')