Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Simple local min / max algo with nearly 600% return on AAPL over 10 years

I'm a software Operations guy, not a quant, so when I sat down to write my first algo, I was mostly ignorant about commonly used strategies. What I came up with was a simple local minimum / maximum strategy.

The idea is simple... Keep track of the 7-day moving average for the past five days, buy if we've just passed a local minimum, and sell if we've just passed a local maximum.

I define local maximum as the price on day 3 being higher than both day 1 and day 5, and local maximum as the price on day 3 being lower than both day 1 and day 5.

To limit potential damage from a single transaction, I buy or sell only 10% of the current value of my portfolio in each transaction.

This code also shows a simple technique for driving my algorithm on a daily rather than minute-by-minute basis. Each time through the handle_data function, I check if the day has changed, and if so, run my calculations and then stash the current day so I won't run them again until tomorrow.

I'd love to hear people's thoughts.

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.

4 responses

not as good as buy and hold

Wayne brings up a good point, and it leads to a simple, but powerful, feature request: ability to define the benchmark security(-ies) that are most relevant for your algo.

Like with Fawce's gold stat arb, perhaps the best benchmark would be GLD instead of a generic total market benchmark.

@Andrew, +1 for flexible benchmarking. I'd also like to see what this algorithm does with a less high flying stock or better yet a broader index ETF.

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.

Curiosity got the better of me, and I tried the same algo on the SPY... didn't generate the same kind of returns, and actually underperformed the S&P 500.