Stock Price Prediction Using Machine Learning
The AI strategy discussed on this page is the foundation for all the other stcok stragtegies we list on this site. For this strategy, we basically feed the AI
as much stock pricing data as possible and have it learn from that to make up or down predictions. If we give it daily data it will predict the prices for the next day, if we give it hourly data it will predict the price for the next hour. In addition to the raw open/high/low/close prices, we create hundreds of what data scientists call "features", which in this case are technical indicators showing patterns such as trends and momentum.
The problem with a system like this is that thousands of other day traders, investment banks, and hedge funds are already doing all of this, so the goal has to be to try to do something they are not doing. There are 2 ways on this site that we do this:
1. There are dozens of different machine learning algorithms, with new ones being invented daily. Each has a different level of accuracy, so we try as many as possible to find the best ones.
2. A popular gambling strategy is to bet on a "sure thing". With stocks, this means only entering the trade if it has a much higher predicted profit than usual. Otherwise, if you trade on every predection the AI makes, it is very hard to cover the cost of commissions, fees, and the spread (the difference between the bid and the ask price). The AI is forced to always make a prediction, but much of the time it really is making no better than a random guess at which direction the price will move.
Before worrying about which ML tool to use, we needed some data, so we downloaded historical stock prices from Alphavantage (they offer free stock data). We then added indicators such as moving averages and oscillators, as this helps the AI make better predictions The final step was data cleaning (dealing with missing rows, outliers, and scaling), because machine learning needs the data in a standard format.
To get a baseline accuracy, we used an algorithm named Logistic Regression, which is fast and simple and we have found does really well for stock prediction. In additon to accuracy, we backtested it, which means we simulated how much profit or loss it would have made if we had been trading our AI trading strategy in the past (only time periods the AI model was not trained on, so it is all unseen data). This is a good indication of how well the strategy would do in live trading for real.
Results: In our 2 year backtest, the AI model's accuracy (up or down prediction) was 51.44%.
The profit/loss backtest had a Profit Factor (PF) of 1.05 and is shown in the table and chart below. A PF greater than 1 means it would have made a profit. This backtest does not include commissions or the bid/ask
You can run this backtest yourself in our free Google Colab notebook: Pickstocks.com - Machine Learning. It uses our open-source GitHub repo at
Pickstocks GitGub. You can also change the data or AI strategy yourself if you want and then backtest it using our repo.
In the other pages on this site, we try more sophisticated strategies to improve on the baseline ML results. Our goal was not to make money from this basic AI strategy, it was to use it as a starting point for something more, so please look at the rest of the pages on this site to see what else we tried.