Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Best way to debug

Hi there, I am currently trying to learn quantopian framework but am having difficulty wrapping my head around the whole thing. There seems to be many resources but lots of them seem to be out of date, for example I really want to backtest a certain futures trading strategy and am trying to familiarise myself with futures syntax of quantopian by reading the lectures, but trying to run one of the example algorithms (https://www.quantopian.com/lectures/example-pairs-trading-on-futures), it actually returns an error:

AttributeError: 'NoneType' object has no attribute 'root_symbol'
USER ALGORITHM:126, in rebalance_pairs
context.current_weights[future_x_contract] = context.long_term_weights[future_x_contract.root_symbol]

I am not too sure how to debug it, I can put a breakpoint on line 126, but it only breaks after it passed certain date and since the whole thing is a giant loop (Based on my understanding the offending code is run daily), it will be hundreds of iterations before I come to the point of interest

This is just one of example case of tens of errors I face during the last few days. Are there any tips on how to debug ?

thanks

2 responses

First off, welcome to Quantopian, and yes, the platform can seem a be a bit daunting at first.

Quantopian hasn't been updating futures data since November 2018. That is the latest data which one can backtest against. Futures analysis and backtesting functionality is still supported, however with this limited data availability. That may answer a lot of your questions. Backtests after November 2018 won't work properly. Specifically, the NoneType error is probably caused from not being able to find a current contract (because data stopped). No object was returned and therefore one couldn't get the root_symbol.

One 'trick' I use when de-bugging sporadic errors, is to use a try except statement. Put the offending code in the try portion then a single 'log' statement in the except portion. Set a breakpoint at that 'log' statement. That way it will only break when there is an error and one can examine any variables in the offending code at that time. I also typically first check the 'type' of the variables. Very often one is expecting one type (eg a scaler value) and it's really another (eg an array).

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 Dan thank you for your answer, I guess that explains a lot of my errors in the past few days.

Are there any reasons futures data are not updated ? Will there be continuous support for it in the future? To give a background, I have a futures strategy I have created in R with DIY backtesting, but I want something a bit more robust and with more bells and whistles, hence the thinking of moving it across to quantopian, but if there will not be support in the futures, maybe I should not do that after all.

Also, are there any ways to code it in that if there is no data just stop the backtest then and there, instead of returning error

thank you very much !