Sometimes I wonder if or when I should buy a stock, and I’ll get a stock trading algorithm in my head. Would it beat holding the stock? How risky is it?
One way to access that is testing the algorithm on past market data. Here, I do just that.
- Use API to pull stock data
- Methods to analyze stock data
- Crossover trading
- Backtest crossover trading strategy
While this Notebook follows another blog post, I made significant changes to the code and added better visualizations.
Stock Trading Algorithm Testing
- Test the Crossover trading algorithm on all the stocks in the S&P 500
- Analyze results
Crossover algorithm often exceeding hold when hold results in loss.
Disclaimer: This is in no way financial advice. I am not a financial adviser. This post and code were done as a data analysis exercise only.