Overall Statistics
Total Orders
4
Average Win
0%
Average Loss
0%
Compounding Annual Return
-6.817%
Drawdown
0.700%
Expectancy
0
Start Equity
100000
End Equity
99601
Net Profit
-0.399%
Sharpe Ratio
-2.773
Sortino Ratio
-2.877
Probabilistic Sharpe Ratio
16.685%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.062
Beta
0.021
Annual Standard Deviation
0.023
Annual Variance
0.001
Information Ratio
0.154
Tracking Error
0.061
Treynor Ratio
-3.097
Total Fees
$4.00
Estimated Strategy Capacity
$90000.00
Lowest Capacity Asset
GOOCV WJVVYXAVCD6U|GOOCV VP83T1ZUHROL
Portfolio Turnover
0.13%
# region imports
from AlgorithmImports import *
# endregion

class ShortButteflyOptionStrategy(QCAlgorithm):

    def initialize(self):
        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 our strike/expiry filter for this option chain
        option.set_filter(lambda x: x.strikes(-5, +5).expiration(timedelta(0), timedelta(30)))

    def on_data(self, slice):
        if self.portfolio.invested:
            return

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

        # Select expiry
        expiry = max([x.expiry for x in chain])

        # Separate the call and put contracts
        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

        # Get the 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

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