Overall Statistics
Total Orders
412
Average Win
0.99%
Average Loss
-0.88%
Compounding Annual Return
1.079%
Drawdown
13.500%
Expectancy
0.123
Start Equity
100000
End Equity
122096.88
Net Profit
22.097%
Sharpe Ratio
-0.282
Sortino Ratio
-0.119
Probabilistic Sharpe Ratio
0.001%
Loss Rate
47%
Win Rate
53%
Profit-Loss Ratio
1.12
Alpha
-0.015
Beta
0.076
Annual Standard Deviation
0.044
Annual Variance
0.002
Information Ratio
-0.279
Tracking Error
0.151
Treynor Ratio
-0.162
Total Fees
$2304.45
Estimated Strategy Capacity
$400000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
6.05%
#region imports
from AlgorithmImports import *
#endregion


class PreHolidayEffectAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2000, 1, 1)  
        self.set_end_date(2018, 8, 1)    
        self.set_cash(100000)           
        self.add_equity("SPY", Resolution.DAILY)

    def on_data(self, data):
        calendar1 = self.trading_calendar.get_days_by_type(TradingDayType.PUBLIC_HOLIDAY, self.time, self.time+timedelta(2))
        calendar2 = self.trading_calendar.get_days_by_type(TradingDayType.WEEKEND, self.time, self.time+timedelta(2))
        holidays = [i.date for i in calendar1]
        weekends = [i.date for i in calendar2]
        # subtract weekends in all holidays
        public_holidays = list(set(holidays) - set(weekends))

        if not self.portfolio.invested and len(public_holidays) > 0:
            self.set_holdings("SPY", 1)
        elif self.portfolio.invested and len(public_holidays) == 0:
            self.liquidate()