Overall Statistics
Total Trades
2
Average Win
0%
Average Loss
0%
Compounding Annual Return
-1.983%
Drawdown
0.100%
Expectancy
0
Net Profit
-0.091%
Sharpe Ratio
-7.302
Probabilistic Sharpe Ratio
0.156%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.009
Beta
-0.004
Annual Standard Deviation
0.002
Annual Variance
0
Information Ratio
-15.375
Tracking Error
0.044
Treynor Ratio
2.838
Total Fees
$2.00
Estimated Strategy Capacity
$5500000.00
Lowest Capacity Asset
GOOCV 30I1FG19OUGPY|GOOCV VP83T1ZUHROL
from AlgorithmImports import *

class PutCalendarSpreadStrategy(QCAlgorithm): 
    def Initialize(self):
        self.SetStartDate(2017, 2, 1)
        self.SetEndDate(2017, 2, 20)
        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 put options from the contracts which is ATM in the option chain.
        puts = [i for i in chain if i.Strike == atm_strike and i.Right == OptionRight.Put]
        if len(puts) == 0: return

        # sorted the optionchain by expiration date
        expiries = sorted([x.Expiry for x in puts], 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.PutCalendarSpread(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 put calendar spread
        
    def OnEndOfAlgorithm(self):
        for symbol, sec in self.Securities.items():
            self.Log(f"{symbol} :: {sec.Price}")