Overall Statistics
Total Trades
4
Average Win
0%
Average Loss
-2.80%
Compounding Annual Return
30.815%
Drawdown
25.800%
Expectancy
-1
Net Profit
93.449%
Sharpe Ratio
1.51
Probabilistic Sharpe Ratio
68.630%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.09
Beta
0.826
Annual Standard Deviation
0.214
Annual Variance
0.046
Information Ratio
0.383
Tracking Error
0.106
Treynor Ratio
0.391
Total Fees
$3.00
Estimated Strategy Capacity
$45000000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
class AlertSkyBlueCaterpillar(QCAlgorithm):


    def Initialize(self):
        self.SetStartDate(2019, 1, 1)
        #self.SetEndDate(2009, 1, 1)
        self.SetCash(10000) 
        spy = self.AddEquity("SPY", Resolution.Minute)
        spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.spy = spy.Symbol
        self.symbol = self.AddOption("SPY", Resolution.Minute).Symbol
        
        # 
        qqq = self.AddEquity("QQQ", Resolution.Minute)
        self.qqq = qqq.Symbol
        
        #Options Contracts
        self.contract40 = None
        
        
    def OnData(self, data):
        
        
        if not self.Portfolio[self.spy].Invested:
            self.SetHoldings(self.spy, 0.5)
            self.SetHoldings(self.qqq, .45)
            

        if self.contract40 is None:
            self.getContracts()
            return
        
        investedoptions = [x for x in self.Portfolio.Values if x.Type == SecurityType.Option and x.Invested]
        if len(investedoptions) == 0:
            #self.SetHoldings(self.contract10, .05)
            self.SetHoldings(self.contract40, .05)
        
        
        #OTM liquidation
        if self.Securities[self.spy].Price < self.contract40.ID.StrikePrice * 1.3:
            self.Liquidate(self.contract40)
            self.RemoveSecurity(self.contract40)

    
    def getContracts(self):
        
        #spyprice = self.CurrentSlice[self.spy].Close
        spyprice = self.Securities[self.spy].Price
        
        #Get the OTM options
        OTM40 = (spyprice*.6) - (spyprice*.6)%5
        
        #Get symbol objects contain option chais for given symbnol
        contracts = self.OptionChainProvider.GetOptionContractList(self.spy, self.Time)
        
        #10 OTM 1 year exipiration date
        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)
                        
        #Grabbing the specific strike price
        #puts = [x for x in puts if x.ID.StrikePrice == OTM40]

        
        #Filtering for optins that fit our date criteria
        #puts10 = [x for x in puts if x.ID.StrikePrice >= OTM10 and (x.ID.Date -  self.Time).days > 365]
        puts40 = [x for x in puts if x.ID.StrikePrice == OTM40 and (x.ID.Date -  self.Time).days > 365]
        if len(puts40) > 0:
            self.contract40 = puts40[0]
            
        
        self.AddOptionContract(self.contract40, Resolution.Minute)