Overall Statistics
Total Orders
3
Average Win
0%
Average Loss
0%
Compounding Annual Return
-6.520%
Drawdown
0.700%
Expectancy
0
Start Equity
100000
End Equity
99619
Net Profit
-0.381%
Sharpe Ratio
-2.723
Sortino Ratio
-1.938
Probabilistic Sharpe Ratio
14.881%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.053
Beta
0.124
Annual Standard Deviation
0.023
Annual Variance
0.001
Information Ratio
0.21
Tracking Error
0.055
Treynor Ratio
-0.496
Total Fees
$3.00
Estimated Strategy Capacity
$40000000.00
Lowest Capacity Asset
GOOCV 30JDODNXWB9VQ|GOOCV VP83T1ZUHROL
Portfolio Turnover
4.16%
# region imports
from AlgorithmImports import *
# endregion

class ProtectiveCollarOptionStrategy(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2017, 4, 1)
        self.set_end_date(2017, 4, 23)
        self.set_cash(100000)
        
        equity = self.add_equity("GOOG", Resolution.MINUTE)
        option = self.add_option("GOOG", Resolution.MINUTE)
        self.symbol = option.symbol
        option.set_filter(lambda universe: universe.include_weeklys().protective_collar(30, -1, -10))

    def on_data(self, data):
        # avoid extra orders
        if self.portfolio.invested: return

        # Get the OptionChain of the self.symbol
        chain = data.option_chains.get(self.symbol, None)
        if not chain: return

        # choose the furthest expiration date within 30 days from now on
        expiry = sorted(chain, key = lambda x: x.expiry)[-1].expiry
        # filter the call options contracts
        call = [x for x in chain if x.right == OptionRight.CALL and x.expiry == expiry]
        # filter the put options contracts
        put = [x for x in chain if x.right == OptionRight.PUT and x.expiry == expiry]

        if not call or not put: return

        # select the strike prices of call and put contracts
        call_strike = sorted(call, key = lambda x: x.strike)[-1].strike
        put_strike = sorted(put, key = lambda x: x.strike)[0].strike

        protective_collar = OptionStrategies.protective_collar(self.symbol, call_strike, put_strike, expiry)
        self.buy(protective_collar, 1)

    def on_end_of_day(self, symbol):
        if symbol.value == "GOOG":
            self.log(f"{self.time}::{symbol}::{self.securities[symbol].price}")