Zipline scheduling - in backtests - monthly rebalance does not work

A zipline algo, has the following setup… that triggers monthly rebalance.
On Quantopian rebalance_stocks_monthly functions runs correctly - with Quatrocket it runs every day instead - see CSV output below. It seems there is a bug in the Quatrocket backtesting code:

Rebalance daily / monthly

schedule_function(rebalance_daily, date_rules.every_day(), time_rules.market_open(hours=1))
schedule_function(rebalance_stocks_monthly, date_rules.month_start(), time_rules.market_open(hours=2))

def rebalance_stocks_monthly(context, data):
record_signal(“MONTHLY TRADE”)
buy_secs = buy_list(context, data)

CSV output from the recorded file - shows trades daily vs. in the beginning of the month:

|2018-01-02 00:00:00+00:00 |MONTHLY TRADE|
|2018-01-03 00:00:00+00:00 |MONTHLY TRADE|
|2018-01-04 00:00:00+00:00 |MONTHLY TRADE|
|2018-01-05 00:00:00+00:00 |MONTHLY TRADE|
|2018-01-08 00:00:00+00:00 |MONTHLY TRADE|
|2018-01-09 00:00:00+00:00 |MONTHLY TRADE|
|2018-01-10 00:00:00+00:00 |MONTHLY TRADE|

Monthly rebalance works fine. You haven’t provided a full example, so here’s a full example proving it works.


# /codeload/zipline/

import zipline.api as algo

def initialize(context):

def rebalance(context, data):
    print(f"rebalancing at {algo.get_datetime()}")


$ quantrocket zipline backtest test-monthly-rebalance -s 2020-01-15 -e 2020-06-15

Detailed log output

        quantrocket_zipline_1|rebalancing at 2020-02-03 16:30:00+00:00
        quantrocket_zipline_1|rebalancing at 2020-03-02 16:30:00+00:00
        quantrocket_zipline_1|rebalancing at 2020-04-01 15:30:00+00:00
        quantrocket_zipline_1|rebalancing at 2020-05-01 15:30:00+00:00
        quantrocket_zipline_1|rebalancing at 2020-06-01 15:30:00+00:00

I suggest checking your code for bugs.

When reporting a suspected QuantRocket bug, please try to simplify your code to the bare minimum necessary to demonstrate the bug and then post that full, simplified example so that the bug can be reproduced. Creating a small, reproducible example is the best way to determine whether there really is a bug in QuantRocket. Sometimes you will find that the simplified example works (like in this case) and this should help you pinpoint where the bug in your code is.