Overall Statistics
Total Orders
2
Average Win
0%
Average Loss
0%
Compounding Annual Return
0.419%
Drawdown
0.100%
Expectancy
0
Start Equity
500000
End Equity
500095.5
Net Profit
0.019%
Sharpe Ratio
-2.43
Sortino Ratio
-4.904
Probabilistic Sharpe Ratio
96.142%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.005
Beta
0.003
Annual Standard Deviation
0.001
Annual Variance
0
Information Ratio
-14.994
Tracking Error
0.044
Treynor Ratio
-1.22
Total Fees
$2.00
Estimated Strategy Capacity
$82000.00
Lowest Capacity Asset
GOOCV 30IZW3B2LIVC6|GOOCV VP83T1ZUHROL
Portfolio Turnover
0.05%
from AlgorithmImports import *

class PutCalendarSpreadStrategy(QCAlgorithm): 
    def initialize(self):
        self.set_start_date(2017, 2, 1)
        self.set_end_date(2017, 2, 20)
        self.set_cash(500000)

        option = self.add_option("GOOG", Resolution.MINUTE)
        self.symbol = option.symbol
        option.set_filter(self.universe_func)

    def universe_func(self, universe):
        return universe.include_weeklys().put_calendar_spread(0, 30, 60)

    def on_data(self, data):
        # avoid extra orders
        if self.portfolio.invested: return

        # Get the OptionChain of the self.symbol
        chain = data.option_chains.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.short_put_calendar_spread(self.symbol, atm_strike, near_expiry, far_expiry)
        # We open a position with 1 unit of the option strategy
        self.buy(option_strategy, 1)
        
    def on_end_of_algorithm(self):
        for symbol, sec in self.securities.items():
            self.log(f"{symbol} :: {sec.price}")