Overall Statistics
Total Trades
7
Average Win
0%
Average Loss
0%
Compounding Annual Return
-47.338%
Drawdown
2.300%
Expectancy
0
Net Profit
-1.684%
Sharpe Ratio
-7.389
Probabilistic Sharpe Ratio
0.000%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.342
Beta
0.123
Annual Standard Deviation
0.06
Annual Variance
0.004
Information Ratio
2.349
Tracking Error
0.166
Treynor Ratio
-3.615
Total Fees
$7.00
import numpy as np
from datetime import date
class MultidimensionalVerticalReplicator(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 9, 15)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.AddEquity("SPY", Resolution.Minute)
        option = self.AddOption("SPY", Resolution.Minute)
        
        self.longest_expiration = 31
        option.SetFilter(-2, 2, timedelta(1), timedelta(self.longest_expiration))
        
        self.curr_day = -1
        
    def OnData(self, data):
        if self.curr_day == self.Time.day:
            return
        
        self.curr_day = self.Time.day
        
        for chain in data.OptionChains.Values:
            contracts = sorted([c for c in chain], key=lambda x:x.Expiry, reverse=True)
            contract = contracts[0]
            self.MarketOrder(contract.Symbol, 1)
            
        for security in self.Securities.Values:
            if security.Invested and security.Symbol.SecurityType == SecurityType.Option:
                days_till_expiry = (security.Expiry - self.Time).days
                self.Log(f'Days till expiry: {days_till_expiry}')
                
                trading_days_till_expiry = list(self.TradingCalendar.GetDaysByType(TradingDayType.BusinessDay, self.Time, self.Time + (security.Expiry - self.Time)))
                self.Log(f'Trading Days till expiry: {len(trading_days_till_expiry)}')
                
                # do buying/selling logic here