Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Backtesting based on rank in SP500

I want to try a strategy like based on ranking on SP500 with a particular stats like trailing sharpe ratio, monthly gain and select 10 from SP500 holds for like three monthes with equal money. And rebalance every three monthes. Is there any example code available like this?

7 responses

Quantopian does not offer point-in-time S&P 500 stocks, so you'll need to concoct a proxy if you really need to pull from the S&P 500.

What about if user provides a list of stock by copying the symbol in the code like copying all the Dow 30 stocks in code. And backtesting based on the top 5 in that 30 stocks? My question focuses more on how to do rank selections with quantpian. It does not need to be SP500 stocks.

Yes, you could certainly use a fixed list of stocks supplied by you, and even a list with drop/add timestamps (e.g. backtest the Dow versus time). For example, you could use this:

https://en.wikipedia.org/wiki/Historical_components_of_the_Dow_Jones_Industrial_Average

You can always estimate sp500 by selecting 500 largest equities by market cap via pipeline. The rotation will probably be a bit off but it will be quite close to reality in historical terms.

I am more looking for some code examples on ranking or rotations in a set of symbols based on some stats rank. SP500 is just an example i use.

One option is to screen securities based on their liquidity, using the dollar volume filter: https://www.quantopian.com/posts/dollar-volume-pipeline

Or you can simulate different indices to create your algo's universe: https://www.quantopian.com/posts/simulating-s-and-p-500-russell-1000-russell-3000-in-research

To rebalance every 3 months, use a schedule_function with a custom date: https://www.quantopian.com/posts/scheduler-overide-beyond-1-month#56cbe2be773f61bbe200038f

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.

Alisa: Thanks a lot for answering my question and give me examples.