Zipline Backtest Order Instructions

Brian - in the Usage Guide section discussing Zipline Live trading the documentation indicates the following:

"An end-of-day strategy can be run anytime after the data bundle has been updated with the prior day's data, and before the following day's close. For example, to run an end-of-day strategy after the Wednesday session, update your data bundle with Wednesday's data and run your trading strategy anytime before Thursday's close.

In backtesting, Zipline fills orders for end-of-day strategies at the next day's closing price. For example, orders placed using Wednesday's data are filled at Thursday's closing price. If you want to replicate this behavior in live trading, you can run your trading strategy shortly before the following day's close and/or use market-on-close/limit-on-close orders."

I had assumed the default behavior in a Zipline backtest was for the rebalance to occur at the next days Open but if I'm reading the documentation correctly that is not the case.

In order to have the rebalance of a daily strategy take place at the open is it as simple as the following?

algo.schedule_function(
        weekly_rebalance,
        algo.date_rules.week_start(days_offset=0),  
        algo.time_rules.market_open(),
    )

    # check static stop loss every day
    algo.schedule_function(
        check_static_stop_loss,
        algo.date_rules.every_day(),
        algo.time_rules.market_open()
    )

In general do Zipline Backtest enable specific order instructions? If yes, what is the best place to find examples?

Thank you.

To trade on the open, you can use MarketOnOpen or LimitOnOpen orders. The documentation you reference was not updated to reflect the recent addition of on-open orders. It has now been updated to be clearer. Please see this section and this section.

schedule_function determines when functions are called in intraday strategies but doesn't have an effect on daily strategies, where everything runs at once. (See docs.)

1 Like

Great. Thank you.