Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Specific returns in Research?

Is there a way to see the specific returns in Research (a notebook)?
I can reconstruct it from the style and sector loadings, however if there is an existing API or notebook it would save me some time. Is there an API or notebook that does this? I did not find one.
Thanks for the help.

3 responses

Yes, the specific returns, along with a number of attributed returns, can easily be retrieved as a pandas dataframe from the backtest AlgorithmResult object. There's documentation on this attributed_factor_returns attribute in the docs (
https://www.quantopian.com/docs/api-reference/research-api-reference#quantopian.research.AlgorithmResult.attributed_factor_returns)

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 dataframe of the returns, something like this should work (make sure you use your own backtest ID) .

# replace with your backtest ID  
my_backtest_id = '5dd3f9dc2c781c4bfeaae1b0'  
bt = get_backtest(my_backtest_id)  
attributed_returns = bt.attributed_factor_returns  
specific_returns = attributed_returns.specific_returns

The above will fetch a dataframe with the attributed returns as columns. One of the columns is 'specific_returns'. The dataframe can be copied, manipulated, plotted, and analyzed as desired. 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).

Hope that helps.

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,

What if I don’t have a backtest ID and am just running a pipeline factor in Research? Can I still get the specific returns from the factor?

@Joakim Alphalens currently doesn't have methods to extract specific returns. There is the method alphalens.performance.factor_alpha_beta (https://quantopian.github.io/alphalens/alphalens.html#alphalens.performance.factor_alpha_beta) which can extract alpha. This alpha is the excess returns above the market (beta). It's not though, returns not attributed to all common exposures.

One could make a simple algo which uses a single factor. This algo then could be backtested and then specific returns analyzed.