Overall Statistics
Total Orders
4
Average Win
0%
Average Loss
0%
Compounding Annual Return
-24.993%
Drawdown
1.800%
Expectancy
0
Start Equity
100000
End Equity
98384.8
Net Profit
-1.615%
Sharpe Ratio
-3.154
Sortino Ratio
-1.934
Probabilistic Sharpe Ratio
1.782%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.183
Beta
0.216
Annual Standard Deviation
0.063
Annual Variance
0.004
Information Ratio
-1.641
Tracking Error
0.077
Treynor Ratio
-0.919
Total Fees
$5.20
Estimated Strategy Capacity
$2400000.00
Lowest Capacity Asset
GOOCV 30JDODNXWB9VQ|GOOCV VP83T1ZUHROL
Portfolio Turnover
0.65%
# 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.include_weeklys().iron_condor(30, 5, 10))

    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) < 2 or len(put_contracts) < 2:
            return

        # Select the strategy legs
        near_call = call_contracts[0]
        far_call = call_contracts[1]
        near_put = put_contracts[1]
        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)