Back to Community
Need help using Pipeline to calculate correlations

I am trying to use the Pipeline framework to calculate correlations between all assets in my universe and a single Equity that I can choose. Ideally, I would like to input an asset_id representing my selected Equity and then return a Pipeline result with a column of values representing all correlations. Below, I have chosen SPY as my single Equity (for now). However, I keep getting errors.

Any ideas on what I'm doing wrong? Thanks very much!

Loading notebook preview...
Notebook previews are currently unavailable.
4 responses

Hi Robert,

There are builtin Pipeline factors and factor methods to help you do just this. I attached a notebook that computes the Pearson R in Pipeline using 2 different approaches (yields the same result).

The documentation for these Factors and Factor methods can be found here:
- RollingPearsonOfReturns
- Factor.pearsonr

I hope this helps.

Loading notebook preview...
Notebook previews are currently unavailable.
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 very much- this is very helpful!

Hey I was a bit confused on how to implement this with new data importer function. How would I get the correlation between the two columns, and add that correlation into a new column in the pipeline. I would really appreciate any help.

Loading notebook preview...
Notebook previews are currently unavailable.

This is an updated notebook with the output of the initial pipeline

Loading notebook preview...
Notebook previews are currently unavailable.