Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Can I schedule before_trading_start not to run daily?

pipeline_output has to be called in before_trading_start, but I only need that information on the days where I rebalance. If I have an algo that doesn't rebalance every day, running before_trading_start takes a lot of time. I can do a funny hack of counting days and skipping computation every x days but was wondering if there's a proper way of doing this.

2 responses

Hello Tom,

I had the same observation awhile back, thinking that I could only run pipeline-based computations on an as-needed basis (presumably that's what we're talking about here). Unfortunately, I was told that's not the way it works, and there would be no performance advantage to conditionally executing the code with before_trading_start.

Alternatively, if you have some of your own non-pipeline code that you are calling, then you can run it on an as-needed basis. One common way is to use schedule_function.

That's strange because if I put logging statements in before_trading_start I can see them getting printed and clearly it's taking computational resources to do that, unless they have some code inspection telling them to skip execution if the output is not used. Oh well, not a huge issue in any case.