| Overall Statistics |
|
Total Trades 2 Average Win 0% Average Loss 0% Compounding Annual Return 0.747% Drawdown 0.000% Expectancy 0 Net Profit 0.014% Sharpe Ratio 6.242 Probabilistic Sharpe Ratio 93.349% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.006 Beta -0.003 Annual Standard Deviation 0.001 Annual Variance 0 Information Ratio 0.159 Tracking Error 0.323 Treynor Ratio -2.204 Total Fees $2.00 Estimated Strategy Capacity $52000000.00 Lowest Capacity Asset AAPL XYME7HUNIMKM|AAPL R735QTJ8XC9X |
from AlgorithmImports import *
class LongCallCalendarSpreadStrategy(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2022, 4, 27)
self.SetEndDate(2022, 5, 3)
self.SetCash(500000)
option = self.AddOption("AAPL", Resolution.Minute)
self.symbol = option.Symbol
option.SetFilter(self.UniverseFunc)
def UniverseFunc(self, universe):
return universe.IncludeWeeklys().Strikes(-1, 1).Expiration(timedelta(4),timedelta(50))
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