Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Q2 - Where does before_trading_start code belong in a daily algo?

EDIT: After reviewing the docs, it seems before_trading_start is a once per day function, not a once per bar function.

Please ignore the following question:

===ORIGINAL POST===

My Q1 algo ran in daily mode and collected fundamentals data via
before_trading_start and then did some trading type stuff in
handle_data. Since we're now going to use scheduled functions rather
than handle_data for daily trading should it seems like I should
move my code to collect fundamentals data into my daily_trade
function.

However, when I try to implement that I get:
FunctionCalledOutsideOfTradingStart: 0069 'get_fundamentals' only permitted within before_trading_start function

-So, it seems I'm now being forced to collect new fundamentals data every minute even though I only need it once a day.-

No wonder my algo now takes hours upon hours to run. It used to take
less than 5m.

Having said that, I'm at a loss as to why my 5m execution in Q1 went to tens of hours in Q2. I'll go back to reveiwing my code now.

3 responses

Hey Chris,
We're happy to help if you want to share your code.

We've also shared some performance best practices here. I expect you are doing things in handle data (like recording variables) that can be moved into scheduled functions.

KR

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.

Hi Chris, I'm glad you figured out the before_trading_start question. If you would like help figuring out why your algo slowed down in Q2, feel free to email in to [email protected]. I'm curious myself and I'd be happy to help!

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.

I expect you are doing things in handle data (like recording variables) that can be moved into scheduled functions.

Exactly. Got all of my handle_data code moved over and now my algo is back in business. Thanks.