Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help: Algo does not send orders

I have done this algo and it works well until 2009, but after that it stops making orders.
I have checked in the debugger and in this code the variables context.long_list and context.weigths are correctly populated.
So i cannot understand why it stops working.

    for long_stock in context.long_list:  
        if long_stock in data:  
            if long_stock in context.dont_buys:  
                continue  
            order_target_percent(long_stock, context.weigths.loc[long_stock])  
8 responses

Hi Giuseppe,

It looks like the issue is that your rebalance() method is scheduled to run at month's end, but the timeframe in the backtest you shared ends on Jan. 24th!

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.

Thanks Jamie you are absolutely right, unfortunately the problem perstist in longer timeframes as well BUT only after 2009..
What i find strange is that the list with stocks to buy are not empty and weigths too, but the algo just stop working after 2009 and i cannot understand the reason why...

here an example

I took another look, and it appears as though context.long_list is an empty list during the period of your algo with no trades!

If you add:

print len(context.long_list)  

right underneath the update_universe() function, you'll notice that in November 2008, it prints 0.

yes it's true, but for 2008, i hve added the length_long_list record and in this attachment you can see that it's 0 from 2008 untill the end, but it sould not be like this, infact if i do another backtest just changing the start date and the end date for the same algo, same code, i have different results (with correct values this tiem) as u can see..

and this is the other backtest, just a few months of 2010, now it do the trades with length_long_list non zero.

Hi Giuseppe,

Ah, I see what you're saying. This is caused by a bug where if you end up with an empty universe at some point in your backtest, any bar from that point on will skip handle_data and all of your scheduled functions. The length of your context.long_list actually goes back up to non-zero at the end of 2009 but since your handle_data was being skipped, the record() function wasn't working properly (I confirmed non-zero values with logging).

I've implemented a workaround in your code that adds a dummy stock (SPY) to your universe when it would otherwise be empty, and sets a flag context.run to false in this case. Then, handle_data and your scheduled functions are skipped by your code instead of by the bug, and when you end up with non-zero length context.long_list, it will resume trading.

Again, this is a bug on our end. We'll have to get it fixed.

Let me know if you have any questions!

Thank you very much Jamie!
Everything clear :)