Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to know if the next day it is a trading day?

I need to be able to to re-balace no later than the 15th day of each month. The Q schedule function only allows the offset in the rules. Anyone knows how to know if the day 15 it is on the weekend and then rebalance on the previous trading day?

                      schedule_function(rebalance,  
                      date_rule=date_rules.month_start(days_offset=10),  
                      # date_rule=date_rules.month_end(days_offset=0),  
                      # date_rule=date_rules.every_day(),  
                      time_rule=time_rules.market_close())  

EG

2 responses

Hi Erick,

Zipline has some functionality that may be useful:

https://github.com/quantopian/zipline/blob/master/zipline/utils/tradingcalendar.py

I've used it in an algo to determine days when the market closes early. See attached for an example.

I'll have to ruminate on how to "re-balance no later than the 15th day of each month" but I see that tradingcalendar has a function get_non_trading_days, so maybe there is some way to test if the 15th day of the month is a trading day, and if not, then test the 14th, etc. until the trading day closest to or on the 15th day is found.

Grant

OK Thanks Grant, Let me explore the zipline code.