Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Is it possible to extract backtesting data?

Greetings Quantopians,

I'm wondering if it's possible to pass the backtest data into a Dataframe to create my own visuals (Backtest has some nice visuals, but I would rather recreate them myself visually. ) Has anyone tried to do so?

2 responses

Hi Vladimir, thanks for the response. Thanks actually very useful to know, but I was more wondering the actual dataframes that plot those visuals.

All the data about a backtest such as orders placed, end of day positions, daily performance, and much more can be accessed in the research environment through attributes of the AlgorithmResult object. The first step is to get a reference to this object using the get_backtest method. This returns a AlgorithmResult object from which one can then reference the various attributes. For example, if one wanted a complete list of positions held at the end of each day then something like this would work

my_backtest_id = '5d6551e306688560ea8bb80c'  
my_backtest = get_backtest(my_backtest_id)

# Display a dataframe of the backtest's end of day positions.  
my_backtest.positions

The above will return a dataframe with all the current positions including cost basis, amount, and some other data. Ensure you put in the correct backtest_id. The dataframe can then be copied, manipulated, plotted, and analyzed. There is a complete list of algorithm result attributes and methods in the docs (https://www.quantopian.com/docs/api-reference/research-api-reference#algorithm-results).

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.