How would i add x-business days to a date. I am trying to compute change in earnings across quarters. What is the best and easiest way to do it?
How would i add x-business days to a date. I am trying to compute change in earnings across quarters. What is the best and easiest way to do it?
One easy way to add business days is with the pandas BDay method. Take a look at these links.
https://pandas.pydata.org/pandas-docs/stable/timeseries.html
https://pandas-docs.github.io/pandas-docs-travis/generated/pandas.tseries.offsets.DateOffset.html
https://pandas-docs.github.io/pandas-docs-travis/generated/pandas.tseries.offsets.BDay.html
It would work something like this (see attached notebook).
# Import pandas. Probably want to use a lot of methods so get them all
import pandas as pd
# Import the BDay method from 'offsets'
from pandas.tseries.offsets import BDay
# Make a date
# Put it into the pandas datetime format
start_date = pd.to_datetime("12-20-2018")
# Add 5 business days to the date using BDay
start_date_plus_5 = start_date + BDay(5)
A couple of things to consider. First, the BDay method doesn't include any holidays by default. (Note the above code assumes Christmas is a business day.) One could add holidays but this generally isn't needed to simply calculate quarters. Second, most of the data in Quantopian assumes 'days' are 'trading days' already. So, just add days since it is already assumed to be trading days. Maybe no need to convert to business days.
However, the larger issue of determining a change in fundamentals across quarters or years is a bit involved. Look at these posts for ideas.
https://www.quantopian.com/posts/change-in-fundamental-data-in-research
https://www.quantopian.com/posts/eps-ttm
Good luck.