Previously I've invoked
date_rules.month_end().get_nth_to_last_trading_day_of_month(aDatetime)
but there was a change in the Quantopian API and now you have also to pass to that method the TradingEnvironment as argument.
See this extract from zipline:
def get_last_trading_day_of_month(self, dt, env):
self.month = dt.month
if dt.month == 12:
# Roll the year foward and start in January.
year = dt.year + 1
month = 1
else:
# Increment the month in the same year.
year = dt.year
month = dt.month + 1
self.last_day = env.previous_trading_day(
dt.replace(year=year, month=month, day=1)
).date()
return self.last_day
The problem is, that I don't know how the get the TradingEnvironment and I need for my algo exactly the last trading day of the month as computed by Quantopian.
May somebody help me please?
Thanks
Costantino