Overall Statistics
Total Trades
2
Average Win
0%
Average Loss
0%
Compounding Annual Return
247.266%
Drawdown
63.000%
Expectancy
0
Net Profit
51.412%
Sharpe Ratio
3.724
Probabilistic Sharpe Ratio
56.955%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
5.442
Beta
-2.928
Annual Standard Deviation
1.581
Annual Variance
2.499
Information Ratio
3.114
Tracking Error
1.94
Treynor Ratio
-2.011
Total Fees
$3104.66
Estimated Strategy Capacity
$30000000.00
Lowest Capacity Asset
SPY 31KBXAXFTE8SM|SPY R735QTJ8XC9X
class TransdimensionalPrism(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)  # Set Start Date
        self.SetEndDate(2020, 5, 1)
        self.SetCash(10000000)  # Set Strategy Cash
        
        #SPY DATA
        spy = self.AddEquity("SPY", Resolution.Minute)
        spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.spy = spy.Symbol
        self.spycontract = None
        
        #TQQQ DATA
        tqqq = self.AddEquity("TQQQ", Resolution.Minute)
        tqqq.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.tqqq = tqqq.Symbol
        self.tqqqcontract = None
        
        self.uNos = {
            self.spy  : self.spycontract
            #self.tqqq : self.tqqqcontract
        }
        

    def OnData(self, data): 
        
        if not self.Portfolio[self.spy].Invested:
            self.SetHoldings(self.spy, 0.9)
            
        # DO HEDGE
        '''
        for contract in self.uNos.values():
            if contract is None:
                contract = self.GetContract()
        return
        '''
        self.getContract()
        
        self.timeDC()
        
        self.setContracts()
        
        self.exerciseContracts()
        
        self.trial()
        
    def getContract(self):
        
        for underlying,contract in self.uNos.items():
            if contract is None:
                targetStrike = (self.Securities[underlying].Price * 0.6) - (self.Securities[underlying].Price * 0.6)%5
                xcontracts = self.OptionChainProvider.GetOptionContractList(underlying, self.Time)
                puts = [x for x in xcontracts if x.ID.OptionRight == OptionRight.Put]
                puts = sorted( sorted(puts, key = lambda x: x.ID.Date, reverse = True),
                       key = lambda x: x.ID.StrikePrice)
                puts = [x for x in puts if x.ID.StrikePrice == targetStrike]
                puts = [x for x in puts if 270 < (x.ID.Date - self.Time).days <= 420]
                if len(puts) == 0:
                    return None
                self.AddOptionContract(puts[0], Resolution.Minute)
                self.uNos[underlying] = puts[0]

    def timeDC(self):
        
        if self.spycontract is None:
            return
        if (self.spycontract.ID.Date - self.Time).days < 180:
            self.Liquidate(self.spycontract)
            self.RemoveSecurity(self.spycontract)
            self.spycontract = None
            return
    
    
    def setContracts(self):
        for underlying, contract in self.uNos.items():
            if contract is None:
                continue
            if not self.Portfolio[contract].Invested:
                self.SetHoldings(contract, 0.1)
    
    
    def exerciseContracts(self):
        for underlying, contract in self.uNos.items():
            if contract is None:
                continue
            
            #Exercise When reach strike price
            if self.Securities[underlying].Price < contract.ID.StrikePrice:
                self.Debug("check")
                #self.Liquidate(contract)
                #self.RemoveSecurity(contract)
                self.ExerciseOption(contract, 100)
                self.RemoveOptionContract(contract)
                self.uNos[underlying] = None
                
            
                
    def trial(self):
        pass