Overall Statistics
Total Orders
65411
Average Win
1.72%
Average Loss
-17.68%
Compounding Annual Return
0%
Drawdown
100.000%
Expectancy
-0.726
Start Equity
100000
End Equity
-40.95
Net Profit
-100.041%
Sharpe Ratio
-0.579
Sortino Ratio
-0.368
Probabilistic Sharpe Ratio
0.000%
Loss Rate
75%
Win Rate
25%
Profit-Loss Ratio
0.10
Alpha
-0.66
Beta
-1.786
Annual Standard Deviation
1.633
Annual Variance
2.667
Information Ratio
-0.672
Tracking Error
1.643
Treynor Ratio
0.529
Total Fees
$2824.12
Estimated Strategy Capacity
$24000000.00
Lowest Capacity Asset
SPY 2ZT6E32N68Z1I|SPY R735QTJ8XC9X
Portfolio Turnover
781.96%
# region imports
from AlgorithmImports import *
# endregion

class RetrospectiveGreenCaribou(QCAlgorithm):
    def initialize(self):
        self.add_chart(Chart("Portfolio Margin"))
        self.set_start_date(2013,10, 7)  #Set Start Date
        self.set_end_date(2014,10,11)    #Set End Date
        self.set_cash(100000)           #Set Strategy Cash
        # Find more symbols here: http://quantconnect.com/data
        self.add_equity("SPY", Resolution.MINUTE)

        option = self.add_option("SPY")
        self.option_symbol = option.symbol
        option.set_filter(lambda u: (u.strikes(-2, +2).expiration(0, 180)))
        self.bought_option = False

    def on_data(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.

        Arguments:
            data: Slice object keyed by symbol containing the stock data
        '''
        if not self.portfolio.invested:
            self.set_holdings("SPY", 1)

        if self.time.year < 2014:
            return

        chain = data.option_chains.get_value(self.option_symbol)
        if chain is None or self.bought_option:
            return

        # we sort the contracts to find at the money (ATM) contract with farthest expiration
        contracts = sorted(sorted(sorted(chain, \
            key = lambda x: abs(chain.underlying.price - x.strike)), \
            key = lambda x: x.expiry, reverse=True), \
            key = lambda x: x.right, reverse=True)

        # if found, trade it
        if len(contracts) == 0: return
        symbol = contracts[0].symbol
        self.market_order(symbol, 1)