In May of 2018 Morgan Stanley presented a report from their research department. The report was written by Tony Small and Matthew Hornbach. The information presented validated the idea of seasonality in the markets. The writers/researchers gathered all the data going back to 1984 on the ten-year futures and all the federal holidays going back over the same span of time. They then analyzed either going long or short M days prior to the holiday and exiting N days before the holidays. They also did the same thing after the holiday – entering M days after and exiting N days after. The boundary was set to five days before and after. This report was sent to me by one of my clients. The conclusion of the article was that there seemed to be a seasonality component to the days prior and after a major holiday. And that it seemed this component did indeed provide a technical advantage (on the surface.) Here is their conclusion.
“Given the risk of data mining, investors should accept this analysis with some degree of caution,” Small and Hornbach said. “There is no guarantee that historical seasonality and past price performance will continue in the future.”
How would one test this idea on their own?
Tools needed:
Python with NumPy installed.
An AI chatbot such as ChatGPT.
Access to TY futures data going back to 1984 (actual non-Panama adjusted data would be preferable.)
A testing platform that allows future leak such as George’s own TradingSimula-18. Excel would work too but would require a bunch of work.
Some programming knowledge.
Create output for all of the federal holidays going back to January 1984. This list must also include Good Fridays. This list should have two fields – the date and the name of the holiday.
TS-18 came in handy because I read the file that was created from step 1 and whenever I came across or spanned a holiday date, I created a loop that calculated the ROC for the prior five days and also for the five days that followed. I created a nomenclature to quickly recognize the ROC span.
B54 – ROC between 5 days before and 4 days before – 1 day
B53 – ROC between 5 days before and 3 days before – 2 days
B52 – ROC between 5 days before and 2 days before – 3 days
B51 – ROC between 5 days before and 1 days before – 4 days
B43 – ROC between 4 days before and 3 days before – 1 day
B42 – ROC between 4 days before and 2 days before – 2 days
B41 – ROC between 4 days before and 1 days before – 3 days
B32 – ROC between 3 days before and 2 days before – 1 day
B31 – ROC between 3 days before and 1 days before – 2 days
B21 – ROC between 2 days before and 1 days before – 1 day
A12 – ROC between 1 days after and 2 days after – 1 day
A13 – ROC between 1 days after and 3 days after – 2 days
A14 – ROC between 1 days after and 4 days after – 3 days
A15 – ROC between 1 days after and 5 days after – 4 days
A23 – ROC between 2 days after and 3 days after – 1 day
A24 – ROC between 2 days after and 4 days after – 2 days
A25 – ROC between 2 days after and 5 days after – 3 days
A34 – ROC between 3 days after and 4 days after – 1 day
A35 – ROC between 3 days after and 5 days after – 2 days
A45 – ROC between 4 days after and 5 days after – 1 day
This process created a file that looked like this:
With this data I summed up each ROC calculation (B54 thru A45). From this you could pick an entry and exit day combination. The best results were wrapped around Memorial Day. Here was where I ran into a small but highly aggravating scenario. Most of the holidays had similar numbers, but there were a few that had some really strange values. I knew I couldn’t use regular adjusted futures data, because many times these values can go below zero and when doing division with these price adjustments, the values are simply not accurate. So, I used continuous non adjusted data, but ran into a problem with the rollover gap. Some of the holidays occurred really close to rollover dates. The calculations that bridged a rollover was not accurate. I then remembered Pinnacle data also includes Ratio Adjusted Data or RAD. I applied the looping algorithm to this data, and it SEEMED to fix the problem.
I was able to pick a B(n,m) or A(m,n) for each market. If the magnitude of ROC was sufficiently negative, you could use the dates to short the market.
ChatGPT and Python and Numpy to the rescue
I asked ChatGPT to provide python code to generate a list of all federal holidays from 1984.
from pandas.tseries.holiday import USFederalHolidayCalendar from datetime import datetime,timedelta import numpy as np # Create a calendar for U.S. federal holidays cal = USFederalHolidayCalendar()
# Get the holidays for the year 2014 holidays_2014 = cal.holidays(start='1984-01-01', end='2024-12-31').to_pydatetime()
federalHolidays = [] date_list = holidays_2014.astype(datetime).tolist() for n in range(len(date_list)): dateString = f'{date_list[n]:%Y%m%d}' federalHolidays.append(int(dateString))
Create a list of federal holidays
This worked great, but I had to convert the NumPy datetime construct to a string. I like to keep things simple. You will see this in the code. I started to get to work on the second part of the task when I discovered there were no dates for GOOD FRIDAYS – argh! ChatGPT to rescue once again.
def good_friday_dates(start_year, end_year): good_friday_dates = [] for year in range(start_year, end_year + 1): # Calculate the date of Easter Sunday for the given year easter_sunday = calculate_easter_date(year)
# Good Friday is two days before Easter Sunday good_friday = easter_sunday - timedelta(days=2)
# Add the Good Friday date to the list good_friday_dates.append(good_friday)
return good_friday_dates
def calculate_easter_date(year): # Algorithm to calculate the date of Easter Sunday a = year % 19 b = year // 100 c = year % 100 d = b // 4 e = b % 4 f = (b + 8) // 25 g = (b - f + 1) // 3 h = (19 * a + b - d - g + 15) % 30 i = c // 4 k = c % 4 l = (32 + 2 * e + 2 * i - h - k) % 7 m = (a + 11 * h + 22 * l) // 451 month = (h + l - 7 * m + 114) // 31 day = ((h + l - 7 * m + 114) % 31) + 1 easter_date = datetime(year, month, day) return easter_date
# Generate Good Friday dates from 1984 to 2024 good_friday_dates_1984_to_2024 = good_friday_dates(1984, 2024)
Hope this code is right for Good Fridays
Good Friday, as Easter, is all over the map. Tomorrow is Good Friday. The code looks pretty gross, so I just accepted it. It may not be 100% accurate, but if ChatGPT says so…. Once I had a list of all holidays, I was able to start cooking (MLK was added in 1986 and Juneteenth in 2021.) Since Juneteenth is relatively new it did not offer a statistically significant number of observations.
Future Leak comes in Handy.
Every quant needs some software that will look through data and do some calculations. I did this project with EasyLanguage, but it was a little difficult. I had to do a two-pass process (well I did the same with Python too.) I first created an indicator that imported the holiday dates and then outputted the close (or open of next bar) for close[5], close[4], close[3], close[2], close[1] and then waited 1, 2, 3, 4 and 5 bars after the date and printed out those respective closing prices. I did not do this step in EasyLanguage. I actually create EasyLanguage as my output. Here is what it looked like:
Future leak allows you to peak into the future and this comes in super handy when doing research like this. Here is some python code in TS-18 that does all these calculations in one sweep.
# The date of the holiday and the holiday name are stored in lists # Each Holiday has its own date and 20 ROC calculations # These calculations are stored in lists as well tempDate = int(extraData[extraCnt][0]) #first field in the csv file whichHoliday = extraData[extraCnt][1] #second field in the csv file if date[D] == tempDate or (date[D] > tempDate and date[D1] < tempDate): foundJ = 99 for j in range(12): if whichHoliday == listOfHolidayClass[j].holidayName: foundJ = j listOfHolidayClass[foundJ].holidayDates.append(tempDate); for j in range(-5,-1): #Before Holiday for k in range(j+1,0): denom = close[D+j] listOfHolidayClass[foundJ].rocList.append((close[D+k] - close[D+j])/denom) for j in range(0,4): #After Holiday - here is the future leak for k in range(j+1,5): denom = close[D+j] listOfHolidayClass[foundJ].rocList.append((close[D+k] - close[D+j])/denom) extraCnt = extraCnt + 1
Python code using future leak to calculate the 20 ROC from before and after holiday
I then printed this out to a csv file and imported into Excel (see above) and found out the best combination of days for each holiday. Now that I had the B(n,m) or the A(m,n) values, I need a process to tell TS-18 which day to buy/short and exit. Here is some code that, again uses future leak, to print out the five dates before the holiday and the five dates after the holiday.
tempDate = int(extraData[extraCnt][0]) whichHoliday = extraData[extraCnt][1] if date[D] == tempDate or (date[D] > tempDate and date[D1] < tempDate): for j in range(12): if whichHoliday == listOfHolidayClass[j].holidayName: foundJ = j print(date[D],end=',') print(whichHoliday,end=',') for j in range(-5,6): print(date[D+j],end=',') print("",end = '\n') extraCnt = extraCnt + 1
# Here is what the file looked like 19840103,NewYear,19831223,19831227,19831228,19831229,19831230,19840103,19840104,19840105,19840106,19840109,19840110, 19840221,PresidentsDay,19840213,19840214,19840215,19840216,19840217,19840221,19840222,19840223,19840224,19840227,19840228, 19840423,GoodFriday,19840413,19840416,19840417,19840418,19840419,19840423,19840424,19840425,19840426,19840427,19840430, 19840529,MemorialDay,19840521,19840522,19840523,19840524,19840525,19840529,19840530,19840531,19840601,19840604,19840605, 19840705,July4th,19840627,19840628,19840629,19840702,19840703,19840705,19840706,19840709,19840710,19840711,19840712, 19840904,LaborDay,19840827,19840828,19840829,19840830,19840831,19840904,19840905,19840906,19840907,19840910,19840911, 19841008,ColumbusDay,19841001,19841002,19841003,19841004,19841005,19841008,19841009,19841010,19841011,19841012,19841015, 19841112,VeteransDay,19841105,19841106,19841107,19841108,19841109,19841112,19841113,19841114,19841115,19841116,19841119, 19841123,Thanksgiving,19841115,19841116,19841119,19841120,19841121,19841123,19841126,19841127,19841128,19841129,19841130,
Create the dates that occur in the date B4 and after holiday
Now read the data in and pick how many days before to b/s and before to exit or after to b/s and to exit
#structure of holidayDatesData list - all strings # 0.) Holiday Date # 1.) Holiday Name # 2.) 5-Before # 3.) 4-Before # 4.) 3-Before # 5.) 2-Before # 6.) 1-Before # 7.) 0-Before/After # 8.) 1-After # 9.) 2-After # 10.) 3-After # 11.) 4-After # 12.) 5-After #Below I pick 1 day after to buy and 4 days after to exit [8,11] for j in range(numHolidayDates): if holidayDatesData[j][1] == "MemorialDay": holidayBuyDates.append(int(holidayDatesData[j][8])) holidayXitDates.append(int(holidayDatesData[j][11]))
# Okay Let's put in some logic to create a long position if not(long) and canTrade and date[D] == holidayBuyDates[gfCnt]: price = close[D] tradeName = "Hol-A1Buy" posSize = 1 tradeTicket.append([buy,tradeName,posSize,price,mkt]) # Long Exits if long and canTrade and date[D] == holidayXitDates[gfCnt]: price = longExit tradeName = "Hol-A4Xit" tradeTicket.append([exitLong,tradeName,curShares,price,mkt]) gfCnt = gfCnt + 1
Here are the results for the Morgan Stanley analysis in 2018
My analysis covered the same period plus all of 2018, 2019, 2020, 2021, 2022, and 2023. My combos were very similar in most cases, but the last few years moved the needle a little bit. However, the results still showed a technical edge.
Backtesting with [Trade Station,Python,AmiBroker, Excel]. Intended for informational and educational purposes only!
Get All Four Books in the Easing Into EasyLanguage Series - The Day Trade Edition is now Available!
Announcement – A Day Trade Edition will be added to my Easing Into EasyLanguage Series this year! This edition will be the fourth installment and will utilize concepts discussed in the Hi-Res and Advanced Topics editions. I will show how to develop and program algorithms that will enter after the open of the day and get out before the market closes. Hence, no overnight exposure. Most examples will be carried out on the mini Dow, Nasdaq, S&P500 and Russel. The programming skills that you will learn can be carried to any market that provides enough bang for the buck to day trade. Look for this edition later this year. But get geared up for it by reading the first three editions in the series now. Get your favorite QUANT the books they need!
Hello to All! The Easing Into EasyLanguage Series is now complete with the publication of the Advanced Topics Edition. This series includes three educational editions. Start out with the Foundation Edition. It is designed for the new user of EasyLanguage or for those you would like to have a refresher course. There are 13 tutorials ranging from creating Strategies to PaintBars. Learn how to create your own functions or apply stops and profit objectives. Ever wanted to know how to find an inside day that is also a Narrow Range 7 (NR7?) Now you can, and the best part is you get over 4 HOURS OF VIDEO INSTRUCTION – one for each tutorial. All source code is available too, and if you have TradeStation, so are the workspaces. Plus you can always email George for any questions. george.p.pruitt@gmail.com.
This book is for those that have read the Foundation Edition or have some experience working with EasyLanguage and the various functions that help make a trading decision. This book’s audience will be those programmers that want to take an idea, that requires an observation of intraday market movements to make a trading decision, and program it accurately. If you have programmed daily bar systems, and you want to drill down and add some components that require additional market information (like what came first – the high or the low), then you have come to the right place. If you want to buy and sell short in the same day and use trade management principles such as profit targets and stop losses then The Hi-Res Edition is the book you need. There are two paradigms that EasyLanguage covers: daily and intraday bar programming. It’s the same language, but the move from daily to intraday programming can be quite difficult. Learn all the essentials and shortcuts with this edition. 5 HOURS OF VIDEO INSTRUCTION in this Hi-Res edition – one for each tutorial. All source code is available too, and if you have TradeStation, so are the workspaces. Plus you can always email George for any questions. george.p.pruitt@gmail.com.
Advanced Topics (AT) could cover a vast amount of ideas and concepts and be the length of “War and Peace” on steroids. Since this book is part of the series, I wanted to cover a handful of concepts that included the follow programming constructs. Arrays and their manipulation. Buffers (fixed length arrays) and the tools to maintain buffer elements with formulas for extraction and sorting. Finite State Machines using the switch-case construct and range based case values. Using original text graphic objects and retrieving and analyzing their properties to determine X and Y coordinate values of text location. Seasonality: The Ruggiero/Barna Universal Seasonal and the Sheldon Knight Seasonal methods. In AT, you will also find an introduction to EasyLanguage’s Project Concept and the steps to create one by adding/deleting component files. TradeStation now provides access to fundamental data such as Commitment of Traders – learn how to convert the Net Change indicator into a strategy utilizing the FundValue functionality. If you wanted to find out how to merge multiple time frames into a single indicator, you are in luck! Create a MTF indicator for yourself.
Day Trading (DT) – This is a surprise installment in my Easing into EasyLanguage Series, as I had only intended on three books. However, I think it will fit well with the other books. Daytrading is a very popular approach as overnight risk is eliminated. Don’t worry there is plenty of risk during the day too! However, it can be very difficult to accurately program a trading idea on higher resolution data such as five- or one-minute bars. Like my other books, there is no “Holy Grail” included. And if you are looking for a book that gets in and out of a trade in a few seconds, this is not the one for you. I discourage trading more than a handful of trades per day – this is best left up to the professionals. But, if you want to learn about volatility-based break outs, pyramiding, scaling out, zone-based trading, accurate trade accounting and having a peek at algorithms that once ruled the systematic daytrading industry, then this is the book for you. A beginner might have a little difficulty in following along with the tutorials. If you have read the first two books (Foundation and Hi-Res) in this series, you are good to go. Or if you have some experience working with EasyLanguage and minute data, you will be OK as well.
Pick up your copies today – e-Book or paperback format – at Amazon.com