Overall Statistics
Total Trades
20
Average Win
0.03%
Average Loss
-0.60%
Compounding Annual Return
-2.768%
Drawdown
19.800%
Expectancy
-0.524
Net Profit
-2.760%
Sharpe Ratio
-0.013
Probabilistic Sharpe Ratio
15.545%
Loss Rate
55%
Win Rate
45%
Profit-Loss Ratio
0.05
Alpha
-0.048
Beta
0.967
Annual Standard Deviation
0.223
Annual Variance
0.05
Information Ratio
-2.086
Tracking Error
0.024
Treynor Ratio
-0.003
Total Fees
$1629.26
class TailHedge(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2011, 1, 1)
        self.SetEndDate(2011, 12, 31)
        self.SetCash(1000000)
        spy = self.AddEquity("SPY", Resolution.Minute)
        spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.SetSecurityInitializer(lambda x: x.SetMarketPrice(self.GetLastKnownPrice(x)))
        self.spy = spy.Symbol
        self.contract = None
        self.SetWarmUp(200)
        self.Schedule.On(self.DateRules.MonthStart("SPY"), self.TimeRules.AfterMarketOpen("SPY", 90), self.Rebalance)
    
    def OnData(self, data):
        if self.IsWarmingUp:
            return
    
    def Rebalance(self):
        self.Log("SpecificTime: Fired at : {0}".format(self.Time))

        self.SetHoldings(self.spy, 0.99)
        self.Debug(str(self.Portfolio[self.spy].HoldingsValue))
        
        if self.contract is None:
            self.contract = self.GetContract()
            if not self.contract is None:
                self.SetHoldings(self.contract, 0.01)
                self.Debug(str(self.Portfolio[self.contract].HoldingsValue))
            return
        
        if not self.contract is None:
            self.Liquidate(self.contract)
            self.RemoveSecurity(self.contract)
            self.contract = None
            self.contract = self.GetContract()
            if not self.contract is None:
                self.SetHoldings(self.contract, 0.01)
                self.Debug(str(self.Portfolio[self.contract].HoldingsValue))
            return

    def GetContract(self):
        targetStrike = self.Securities[self.spy].Price * 0.7
        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) >= 0
            and (x.ID.StrikePrice - targetStrike) < 6]
        puts = [x for x in puts if 50 < (x.ID.Date - self.Time).days <= 90]
        if len(puts) == 0:
            return None
        self.AddOptionContract(puts[0], Resolution.Minute)
        return puts[0]