Overall Statistics
Total Orders
6
Average Win
0.00%
Average Loss
-0.01%
Compounding Annual Return
-2.485%
Drawdown
0.300%
Expectancy
-0.312
Start Equity
500000
End Equity
498944
Net Profit
-0.211%
Sharpe Ratio
-11.119
Sortino Ratio
-11.371
Probabilistic Sharpe Ratio
0.038%
Loss Rate
33%
Win Rate
67%
Profit-Loss Ratio
0.03
Alpha
-0.009
Beta
-0.047
Annual Standard Deviation
0.003
Annual Variance
0
Information Ratio
-8.131
Tracking Error
0.061
Treynor Ratio
0.649
Total Fees
$3.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
0.15%
#region imports
from AlgorithmImports import *
#endregion
# https://quantpedia.com/Screener/Details/20


class VolatilityRiskPremiumStrategy(QCAlgorithm): 

    def initialize(self):
        self.set_start_date(2017, 2, 1)
        self.set_end_date(2017, 3, 5)
        self.set_cash(500000)

        option = self.add_option("SPY", Resolution.MINUTE)
        self._symbol = option.symbol
        option.set_filter(self._universe_func)

    def _universe_func(self, universe):
        return universe.include_weeklys().strikes(-20, 20).expiration(timedelta(0), timedelta(31))

    def on_data(self, slice: Slice) -> None:
        if self.portfolio.invested: 
            return

        # Get the OptionChain
        chain = slice.option_chains.get(self._symbol, None)
        if not chain: 
            return

        # Get the nearest expiration date of the contracts
        expiry = sorted(chain, key = lambda x: x.expiry)[0].expiry
        
        # Select the put Option contracts
        puts = [i for i in chain if i.expiry == expiry and i.right == OptionRight.PUT]
        if len(puts) == 0: 
            return

        # Select the ATM strike price from the remaining contracts
        underlying_price = chain.underlying.price
        atm_strikes = sorted([x.strike for x in puts], key=lambda x: abs(x - underlying_price))[0]

        option_strategy = OptionStrategies.straddle(self._symbol, atm_strikes, expiry)
        # Select 15% OTM put
        otm_put = sorted(puts, key=lambda x: abs(x.strike - 0.85*underlying_price))[0]
        self.buy(option_strategy, 1)
        self.sell(otm_put.symbol, 1)