Currently I'm generating a DateTimeIndex using a certain function, zipline.utils.tradingcalendar.get_trading_days
. The time series is roughly daily but with some gaps.
My goal is to get the last date in the DateTimeIndex
for each month.
.to_period('M')
& .to_timestamp('M')
don't work since they give the last day of the month rather than the last value of the variable in each month.
As an example, if this is my time series I would want to select '2015-05-29' while the last day of the month is '2015-05-31'.
['2015-05-18', '2015-05-19', '2015-05-20', '2015-05-21', '2015-05-22', '2015-05-26', '2015-05-27', '2015-05-28', '2015-05-29', '2015-06-01']
df.groupby([df.index.year,df.index.month]).last()
give what you want? – Giustino