| Overall Statistics |
|
Total Trades 2 Average Win 0% Average Loss 0% Compounding Annual Return -2.004% Drawdown 0.100% Expectancy 0 Net Profit -0.092% Sharpe Ratio -7.72 Probabilistic Sharpe Ratio 0.032% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.01 Beta -0.002 Annual Standard Deviation 0.002 Annual Variance 0 Information Ratio -15.394 Tracking Error 0.044 Treynor Ratio 4.821 Total Fees $2.00 Estimated Strategy Capacity $2100000.00 Lowest Capacity Asset GOOCV WIXFALAHKNC6|GOOCV VP83T1ZUHROL |
from AlgorithmImports import *
class LongCallCalendarSpreadStrategy(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017, 2, 1)
self.SetEndDate(2017, 2, 19)
self.SetCash(500000)
option = self.AddOption("GOOG", Resolution.Minute)
self.symbol = option.Symbol
option.SetFilter(self.UniverseFunc)
def UniverseFunc(self, universe):
return universe.Strikes(-1, 1).Expiration(timedelta(0), timedelta(62))
def OnData(self, data):
# avoid extra orders
if self.Portfolio.Invested: return
# Get the OptionChain of the self.symbol
chain = data.OptionChains.get(self.symbol, None)
if not chain: return
# get at-the-money strike
atm_strike = sorted(chain, key=lambda x: abs(x.Strike - chain.Underlying.Price))[0].Strike
# filter the call options from the contracts which is ATM in the option chain.
calls = [i for i in chain if i.Strike == atm_strike and i.Right == OptionRight.Call]
if len(calls) == 0: return
# sorted the optionchain by expiration date
expiries = sorted([x.Expiry for x in calls], key = lambda x: x)
# select the farest expiry as far-leg expiry, and the nearest expiry as near-leg expiry
near_expiry = expiries[0]
far_expiry = expiries[-1]
option_strategy = OptionStrategies.CallCalendarSpread(self.symbol, atm_strike, near_expiry, far_expiry)
# We open a position with 1 unit of the option strategy
self.Buy(option_strategy, 1)
# self.Sell(option_strategy, 1) if short call calendar spread