Overall Statistics
Total Orders
310
Average Win
1.01%
Average Loss
-0.86%
Compounding Annual Return
1.208%
Drawdown
13.600%
Expectancy
0.237
Start Equity
100000
End Equity
134905.66
Net Profit
34.906%
Sharpe Ratio
-0.421
Sortino Ratio
-0.125
Probabilistic Sharpe Ratio
0.001%
Loss Rate
43%
Win Rate
57%
Profit-Loss Ratio
1.16
Alpha
-0.015
Beta
0.041
Annual Standard Deviation
0.032
Annual Variance
0.001
Information Ratio
-0.37
Tracking Error
0.155
Treynor Ratio
-0.328
Total Fees
$1511.30
Estimated Strategy Capacity
$1100000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
3.37%
# https://quantpedia.com/strategies/pre-holiday-effect/
# 
# Investors use some simple investment vehicles to gain exposure to US equity market (ETF, fund, CFD or future) only during days 
# preceding holiday days (New Year’s Day, Martin Luther King Jr. Day, President’s Day, Good Friday, Memorial Day, Independence Day,
# Labor Day, Election Day, Thanksgiving Day, Christmas Day). Investors stay in cash during other trading days. The anomaly isn’t
# limited only to the US market but seems to work well also in other countries; therefore, it could be broadened to include 
# pre-holiday days for local holidays in other markets

from AlgorithmImports import *

class PreHolidayEffect(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2000, 1, 1)  
        self.SetCash(100000)           
        
        self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol

    def OnData(self, data):
        calendar1 = self.TradingCalendar.GetDaysByType(TradingDayType.PublicHoliday, self.Time, self.Time+timedelta(days=2))
        calendar2 = self.TradingCalendar.GetDaysByType(TradingDayType.Weekend, self.Time, self.Time+timedelta(days=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.SetHoldings(self.symbol, 1)
        elif self.Portfolio.Invested and len(public_holidays)==0:
            self.Liquidate()