Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
schedule function triggered time

Hi all, when set market_open(hours=0, minutes=2)), in backtest page under transaction column it shows trade happens at 9:33 AM. So when the actual trade happens?(function is called at 9:32 or 9:33 AM), thanks

9 responses

Quantopian has minute bars as the lowest resolution (I.e. not tick level), so depending on what slippage model you’re using, you effectively get filled during this minute (9:32 - 9:33) based on the traded volume and volume weighted average price (I think) during this minute.

schedule_function(ordering_logic,date_rule=date_rules.every_day(),time_rule=time_rules.market_open(hours=0, minutes=2)) @Joakim assuming my underlying is very liquid and my account is only small value such as 10K, then does it mean the function will be called at 9:32 AM?
if so, why the backtest shows it's always called at 9:33 AM? Plz check below plot, thank you.

called time shows in backtest

I would think it would need to be called at 9:33 in order to simulate fills in the previous minute. Otherwise you’d have look ahead issues in the simulation. Your simulated fills would be based on data from 9:32 though.

The schedule function expects a minute value greater than or equal to 1. As @Joakim mentioned, when a function is scheduled to run time_rule=time_rules.market_open(hours=0, minutes=2)) then it will execute in the interval between 2 and 3 minutes after open (ie 9:32-9:33). It has access to data before 9:32. Orders are evaluated at the end of that interval at time 9:33 but before any functions which are scheduled at minute=3 .

The default slippage model fills orders based on the close price of the previous interval (ie the interval 9:32 - 9:33). In other words, orders placed at minute x are filled at minute x+1. The function is not called at 9:33 (it's called at 9:32) that is when the orders are executed.

A lot of words there so hope it makes sense.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Why is minutes=0 (9:30am) prevented?

@Viridian Hawk A function cannot be scheduled at minute=0 (9:30) because scheduled functions look at data from the previous minute. There isn't any data before minute 0 (ie the markets are closed) so functions wouldn't have any data to work with. As a practical matter, the function would return the same results as if it were run from before_trading_start.

Thanks @Dan!

time_rule=time_rules.market_open()is allowed though, is that the same as time_rule=time_rules.market_open(hours=0, minutes=1)?

is that the same

Yes. So the earliest you can get a fill is 9:32, since placing orders during before_trade_start is not supported as well. (Not that you'd want to get a fill at 9:32, due to the crazy spreads.) I guess with Q's move away from the backtester and to EOD positions it's no longer an issue, but I used to wonder why they didn't modify the zipline to support opening and closing auction orders.

@Joakim yes, the default is minutes=1. time_rule=time_rules.market_open() is the same as time_rule=time_rules.market_open(hours=0, minutes=1)