Overall Statistics
Total Trades
43
Average Win
0.07%
Average Loss
0%
Compounding Annual Return
1.043%
Drawdown
5.000%
Expectancy
0
Net Profit
1.425%
Sharpe Ratio
0.179
Probabilistic Sharpe Ratio
16.149%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.013
Beta
-0.006
Annual Standard Deviation
0.068
Annual Variance
0.005
Information Ratio
-0.522
Tracking Error
0.285
Treynor Ratio
-2.016
Total Fees
$55.00
import numpy as np
from datetime import timedelta

class HorizontalOptimizedShield(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 1, 1)
        self.SetCash(100000)
    
        self.equity = self.AddEquity("MSFT", Resolution.Minute)
        self.Securities["MSFT"].SetDataNormalizationMode(DataNormalizationMode.Raw)

    def OnData(self, data):
        if self.Portfolio.Invested: 
            return
        
        if not data.ContainsKey(self.equity.Symbol):
            return
        
        contracts = self.OptionChainProvider.GetOptionContractList(self.equity.Symbol, data.Time)
        self.underlyingPrice = self.Securities[self.equity.Symbol].Price
        under = self.underlyingPrice - 0.1 * self.underlyingPrice
        
        otm_puts = [i for i in contracts if i.ID.OptionRight == OptionRight.Put and 
                                            i.ID.StrikePrice <= under and 
                                            10 < (i.ID.Date - data.Time).days < 30]
                                            
        if len(otm_puts) == 0:
            return
        
        contract = sorted(sorted(otm_puts, key = lambda x: x.ID.Date), 
                                            key = lambda x: x.ID.StrikePrice)[0]
    
        
        self.AddOptionContract(contract, Resolution.Minute)

        self.MarketOrder(contract, -10)