Overall Statistics
Total Orders
132
Average Win
1.10%
Average Loss
-1.17%
Compounding Annual Return
4.922%
Drawdown
5.600%
Expectancy
0.351
Start Equity
10000
End Equity
13078.15
Net Profit
30.782%
Sharpe Ratio
0.521
Sortino Ratio
0.278
Probabilistic Sharpe Ratio
24.355%
Loss Rate
30%
Win Rate
70%
Profit-Loss Ratio
0.94
Alpha
0.005
Beta
0.199
Annual Standard Deviation
0.046
Annual Variance
0.002
Information Ratio
-0.774
Tracking Error
0.091
Treynor Ratio
0.12
Total Fees
$132.00
Estimated Strategy Capacity
$330000.00
Lowest Capacity Asset
OEF RZ8CR0XXNOF9
Portfolio Turnover
6.43%
#region imports
from AlgorithmImports import *
#endregion


class OptionExpirationWeekEffectAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2013, 1, 1)
        self.set_end_date(2018, 8, 1)
        self.set_cash(10000)
        self.add_equity("OEF")
        option = self.add_option("OEF")
        option.set_filter(-3, 3, timedelta(0), timedelta(60))
        self.schedule.on(self.date_rules.every(DayOfWeek.MONDAY, DayOfWeek.MONDAY), self.time_rules.at(10, 0), self._rebalance)
        self._lastest_expiry = datetime.min
        self.set_benchmark("OEF")

    def on_data(self, slice):        
        if self.time.date() == self._lastest_expiry.date():
            self.liquidate()

    def _rebalance(self):
        calendar = self.trading_calendar.get_days_by_type(TradingDayType.OPTION_EXPIRATION, self.time, self.end_date)
        expiries = [i.date for i in calendar]
        if not expiries: 
            return
        self._lastest_expiry = expiries[0]

        if (self._lastest_expiry - self.time).days <= 5:
            self.set_holdings("OEF", 1)