Back to Community
Clustering of stocks to find trend for pairs trading

Hey everybody,

I was thinking of performing a clustering analysis of all the S&P 500 stocks, so that I could find stocks having the same properties, which will help me identify the stocks that I need to trade with using the pairs trading strategy. I want to know is there any way that I could get the historical data for all S&P 500 stocks having information like the valuation ratios in addition to the prices on Quantopian.

Any help is appreciated :)

4 responses

Quantopian doesn't have the S&P 500 stocks as a list, but you could try their Q500US/Q1500US built-in universes (see https://www.quantopian.com/help#built-in-filters ) along with Morningstar fundamentals (see the help page and https://www.quantopian.com/help/fundamentals ).

Thanks for your reply Grant.

Is there any way I can just store the fundamental data into a dataframe? I want to use this dataframe for performing a k means clustering.

I'm pretty sure something along those lines should be doable, but I'm not so familiar with fundamentals/pipeline. Maybe someone else can post an example?

If you go into My Code --> Notebooks, and click on Tutorials and Documentation, you'll see one that starts you on loading corporate fundamentals into research.

I also recommend checking out the Lectures in general, and the "Case Study: Traditional Value Factor" in particular to see how the data can be used.

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.