Overall Statistics
Total Trades
2
Average Win
0%
Average Loss
0%
Compounding Annual Return
7.379%
Drawdown
23.900%
Expectancy
0
Net Profit
159.830%
Sharpe Ratio
0.861
Probabilistic Sharpe Ratio
26.873%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.047
Beta
0.307
Annual Standard Deviation
0.091
Annual Variance
0.008
Information Ratio
-0.159
Tracking Error
0.157
Treynor Ratio
0.256
Total Fees
$55.20
class UncoupledTransdimensionalPrism(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2007, 1, 1)  # Set Start Date
        # self.SetEndDate(2020, 1, 1)
        self.SetCash(1000000)  # Set Strategy Cash
        spy = self.AddEquity("SPY", Resolution.Minute)
        spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.tlt = self.AddEquity('TLT', Resolution.Minute).Symbol
        self.spy = spy.Symbol
        self.contract = None

    def OnData(self, data): 
        
        if not self.Portfolio[self.spy].Invested:
            self.SetHoldings(self.spy, 0.6)
        if not self.Portfolio[self.tlt].Invested:
            self.SetHoldings(self.tlt, 0.4)
        return
        # DO HEDGE
        if self.contract is None:
            self.contract = self.GetContract()
            return
        
        if (self.contract.ID.Date - self.Time).days < 180:
            self.Liquidate(self.contract)
            self.RemoveSecurity(self.contract)
            self.contract = None
            return
        
        if not self.Portfolio[self.contract].Invested:
            self.SetHoldings(self.contract, 0.01)
        
        if self.Securities[self.spy].Price < self.contract.ID.StrikePrice * 1.3:
            self.Liquidate(self.contract)
            self.RemoveSecurity(self.contract)
    
    def GetContract(self):
        targetStrike = (self.Securities[self.spy].Price * 0.6) - (self.Securities[self.spy].Price * 0.6)%5
        contracts = self.OptionChainProvider.GetOptionContractList(self.spy, self.Time)
        puts = [x for x in contracts 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)
        return puts[0]