Introduction
Pre-holiday days on the market are often characterized with lower liquidity as a lot of market participants are not involved in the market or they lower their exposure. Historical research shows that stock prices often behave in a specific manner in each of the two trading days preceding these holidays. This anomaly in Equities is often called the pre-holiday effect. It is the market in-efficiency for short-term traders to gain on the final trading day before a holiday. In this algorithm, we'll construct a simple strategy to exploit this pre-holiday effect in the Equity market.
Method
The TradingCalendar class can help us find all the available holidays during a period of time.
GetDaysByType returns trading days of the specified TradingDayType
that contains trading events associated with the range of dates.
Here we choose the type to be TradingDayType.PUBLIC_HOLIDAY
and list all holidays from today to the next two days. As PublicHoliday
includes weekends,
we use the type TradingDayType.WEEKEND
to subtract weekend holidays.
def on_data(self, data):
calendar1 = self.trading_calendar.get_days_by_type(TradingDayType.PUBLIC_HOLIDAY, self.time, self.time+timedelta(days=2))
calendar2 = self.trading_calendar.get_days_by_type(TradingDayType.WEEKEND, self.time, self.time+timedelta(days=2))
holidays = [i.date for i in calendar1]
weekends = [i.date for i in calendar2]
public_holidays = list(set(holidays) - set(weekends))
The investment vehicle is SPDR S&P500 ETF. The algorithm will trade the ETF if there are holidays within the next two days and stays in cash during other trading days.
if not self.portfolio.invested and len(holidays)>0:
self.set_holdings("SPY", 1)
elif self.portfolio.invested and len(holidays)==0:
self.liquidate()
Derek Melchin
See the attached backtest for an updated version of the algorithm in PEP8 style.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jing Wu
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!