Overall Statistics
Total Orders
4
Average Win
0%
Average Loss
0%
Compounding Annual Return
-14.227%
Drawdown
1.300%
Expectancy
0
Start Equity
100000
End Equity
99134.8
Net Profit
-0.865%
Sharpe Ratio
-3.211
Sortino Ratio
-2.581
Probabilistic Sharpe Ratio
7.142%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.108
Beta
0.139
Annual Standard Deviation
0.037
Annual Variance
0.001
Information Ratio
-0.732
Tracking Error
0.061
Treynor Ratio
-0.85
Total Fees
$5.20
Estimated Strategy Capacity
$21000.00
Lowest Capacity Asset
GOOCV WJVVXYXTEWYU|GOOCV VP83T1ZUHROL
Portfolio Turnover
0.20%
# region imports
from AlgorithmImports import *
# endregion

class ShortIronCondorOptionStrategy(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 or not self.is_market_open(self._symbol):
            return

        chain = slice.option_chains.get(self._symbol)
        if not chain:
            return

        # Find put and call contracts with the farthest expiry       
        expiry = max([x.expiry for x in chain])
        chain = sorted([x for x in chain if x.expiry == expiry], key = lambda x: x.strike)

        put_contracts = [x for x in chain if x.right == OptionRight.PUT]
        call_contracts = [x for x in chain if x.right == OptionRight.CALL]

        if len(call_contracts) < 3 or len(put_contracts) < 3:
            return

        # Select the strategy legs
        near_call = call_contracts[-3]
        far_call = call_contracts[-1]
        near_put = put_contracts[2]
        far_put = [x for x in put_contracts if x.Strike == near_put.strike - far_call.strike + near_call.strike][0]

        short_iron_condor = OptionStrategies.short_iron_condor(
            self._symbol, 
            far_put.strike,
            near_put.strike,
            near_call.strike,
            far_call.strike,
            expiry)

        self.buy(short_iron_condor, 2)