Overall Statistics
Total Orders
4
Average Win
0%
Average Loss
0%
Compounding Annual Return
-14.000%
Drawdown
1.000%
Expectancy
0
Start Equity
100000
End Equity
99136
Net Profit
-0.864%
Sharpe Ratio
-3.537
Sortino Ratio
-2.2
Probabilistic Sharpe Ratio
1.804%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.111
Beta
0.095
Annual Standard Deviation
0.033
Annual Variance
0.001
Information Ratio
-0.726
Tracking Error
0.062
Treynor Ratio
-1.25
Total Fees
$4.00
Estimated Strategy Capacity
$8000000.00
Lowest Capacity Asset
GOOCV 30JDOCMJ7422U|GOOCV VP83T1ZUHROL
Portfolio Turnover
0.35%
# region imports
from AlgorithmImports import *
# endregion

class OptionStrategyShortButterfly(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2017, 4, 1)
        self.set_end_date(2017, 4, 23)
        self.set_cash(100000)

        option = self.add_option("GOOG", Resolution.MINUTE)
        self._symbol = option.symbol

        # set strike/expiry filter for the option chain
        option.set_filter(lambda x: x.include_weeklys().iron_butterfly(30, 10))

    def on_data(self, slice: Slice) -> None:
        if self.portfolio.invested:
            return
        
        # current time-slice option chain
        chain = slice.option_chains.get(self._symbol, None)
        if not chain:
            return
        
        # choose the longest expiry within the pre-filtered chain
        expiry = max([x.expiry for x in chain])

        # butterfly legs
        calls = [i for i in chain if i.right == OptionRight.CALL and i.expiry == expiry]
        puts = [i for i in chain if i.right == OptionRight.PUT and i.expiry == expiry]
        if not calls or not puts:
            return

        # ATM and OTM strike prices
        atm_strike = sorted(calls, key = lambda x: abs(x.strike - chain.underlying.price))[0].strike
        otm_put_strike = min([x.strike for x in puts])
        otm_call_strike = 2 * atm_strike - otm_put_strike
        otm_call_strike = max([x.strike for x in calls])

        short_iron_butterfly = OptionStrategies.short_iron_butterfly(self._symbol, otm_put_strike, atm_strike, otm_call_strike, expiry)
        self.buy(short_iron_butterfly, 1)