8 Machine Learning Algorithms That Can Help in Trading

Artificial Intelligence is quietly revolutionizing our lives. With the recent successes in auto driven cars, the future of Artificial Intelligence looks very bright. Artificial intelligence is a favorite theme with many science fiction movies in which robots are shown as more smart than humans. You must have watched a few Hollywood movies in which artificial intelligence has been shown with destructive powers. We may not have reached that stage of development where machine can take over humans. But we definitely have developed the capacity to make the machine learn from experience in selected problems only.

What is Machine Learning?

Machine learning is the heart of Artificial Intelligence. Machine Learning algorithms are designed to learn from past experiences. Today we are living in the world of big data. All big businesses, companies, corporations and banks are employing data analysts whose job is to analyze the data and find patterns that can be used to make profitable decisions. On MT4 I can download last 10 years of price data for dozens of pairs very easily in a csv file in just a few seconds. The thing that is lacking is how to find the patterns in that data that can be used to make profitable decisions. We are going to do just that in this post. We are going to discuss how we can use machine learning to extract patterns in that data that can then be used in making profitable buy/sell decisions.  Machine learning is a discipline that combines maths with statistics, computer science, coding and information technology and extracts predictive patterns from big data.

This is something that is now being exploited by hedge funds in developing a new generation of automated trading strategies. Quantitative trading is on the rise. Hedge funds and big banks are employing PhDs in maths and physics known as Quants. The job of a quant is to develop quantitative models of markets that can be used to make predictions. These predictions are then been used in trading and investing. Renaissance Technologies is one such hedge fund that is being run by a billionaire mathematician John Simons. John Simons employed a number of mathematician and used them to mathematically model the markets. These models have helped John Simons Renaissance Technologies make an average return of 71% annually over the period of 1994 to 2014. When most hedge funds were going belly up in the aftermath of the severe financial crisis of 2008, Renaissance Technologies made a staggering 98% return that year. So you can well imagine the power of mathematical and statistical models in making correct predictions. Below is an infographic of the 8 machine learning algorithms that we are going to discuss in this post.

8 Machine Learning Algorithms Helpful in Trading

If you have been trading for a while you must have learned by now that most traditional indicators have stopped working. MACD worked great in 1980s and early 1990s. But now it gives large number of false signals. Similarly Stochastic, RSI and other indicators used to work in the past but are not working any more. Candlestick patterns like engulfing pattern, harami and doji are mostly giving false signals. Why is this so? You see there is a feedback loop in the market. Whatever we do as traders and investors markets learn from that and soon adopt themselves to our trading strategies meaning our trading strategies stop working. Does this mean markets are more intelligent then us? Know this markets are just us. We are the buyers and sellers.

Markets are just a depiction of our collective crowd behavior. You can think of the markets are large number of people buying and selling in a crowd. So these people make decisions. When these buy/sell decisions don’t work they change their decision making to something that works. We learn from each other. So when something starts working we all try to do that. This is the feedback loop that I was talking about. This feedback loop ensures that what works only works for sometime before it becomes too much public. Then it loses its efficacy. This is one reason that John Simons is very secretive about his hedge funds strategies. Once the secret is out, it is no more a secret. What you need to understand is that markets change and you also need to change. Richard Dennis is a trading legend. His Turtle Trading System worked so well in 1980s that it made many millionaires. His Turtle Trading System made him around $200 million. But if you try to trade it in today’s market, it will only generate one losing trade after another. So don’t try to trade with it today. In this post we are going to discuss 10 Machine Learning Algorithms that can help in day trading as well as swing trading. Did you download your copy of Traders World Magazine?

Are Markets Really Efficient?

Try to understand markets are highly intelligent just like us. Why? Because we are the markets. Markets know how to beat us. Why? Once again because markets are us. You must have heard the saying: ” In trading, your biggest enemy is your yourself.” Since we are the markets you are most of the time competing against your own self. So we are responsible for our self destruction most of the time. As said above today almost all the sophisticated players in the market are using quantitative methods in trading. As technical traders we know there are certain price patterns that predict the future short term price very well. As technical traders we also know that past price has some information about the future price. We were told that markets are efficient meaning there is no chance we can beat the market.

Market efficiency means that price reflects all the available information and it is impossible to extract any useful information from the present price about the future. This is the basis of random walk. But we also know that there are people who have consistently beaten the market over and over again for a very long period. One such person is Warren Buffet. This makes efficient market hypothesis somewhat doubtful. Today we know that markets are not efficient in the short term but maybe efficient in the long term. This explains why a trading strategy works in the short term but stops working in the long term. Why? Markets are efficient in the long term. This efficient market hypothesis has been used by academia to discredit technical analysis for a long time. But today this hypothesis has been proven to be not true at least in the short term.

There are patterns in price that can be used to predict the market. These patterns are not easy to distinguish from market noise. This explains why majority of us do not make money on a consistent basis. Only those who can predict these price patterns can make money. There are many types of these patterns that are hidden from our naked eyes. The job of technical analysis was to find those patterns. Some succeeded in finding a pattern that worked. They made a lot of money from it. But when the pattern became public knowledge it lost its predictive power. Why? Markets became more efficient and learned how to nullify that pattern. Now we use machine learning to find those hidden patterns that can predict the price. Let’s discuss the 8 machine learning algorithms that have been shown in the above infographic.

Neural Networks

The first algorithm that we are going to discuss is the Neural Network. Neural Network is a simple connection of nodes. Each node is used to combine the inputs from the previous nodes using a Sigmoid function. A few decades back it was difficult to train these networks due to lack of computational power. But today we have powerful computers and we can use their computational power to train these networks. Back Propagation algorithm was a breakthrough that allowed easy computation of these networks. Many trading systems are using neural networks. Hedge funds love neural networks. The problem with neural networks is that they are black boxes that are used to find the linear relationship between the input and output. Most of the time there is no easy explanation of how this relationship works. Another problem with Neural Networks is that they have a tendency to get stuck up at a local minima. When a neural network gets stuck up with a local minima it starts giving a different result each time you run it. If you want to use neural networks , you need a lot of experience. Neural networks can be used for both regression as well as classification. There is expensive neural network software that is being sold in the market with the claim that it can predict the markets accurately.

Support Vector Machines

Support Vector Machines (SVMs) is another algorithm that can be used in trading. Did you read my post on how to predict the stock market using Support Vector Machines?  In this post I have explained in detail how you can use a support vector machine to predict the market direction. If you know the market direction, you can cut your losses to half. When you know the market has a high probability of moving up, you will avoid entering into a sell trade. Unlike Neural Networks, SVMs don’t get stuck up with local minima meaning it always gives you a unique solutions. SVMs can be used for classification as well as regression. Logistic regression is a special case of SVM. SVM uses a kernel to transform the data onto a higher plane where it is easy to separate the data and different classes. The best kernel is radial basis kernel.

Decision Trees

As said above Neural Networks and Support Vector Machines are black boxes which are difficult to understand. These black boxes are able to model highly non linear relationships but we often lack the ability to interpret the predictions. Decision Trees uses a tree like graph or model that gives you the different paths events can take. Decision Trees can be applied to trading especially we can use decision trees to model candlestick patterns as well as other trading systems. Overfitting is a frequent problem with decision trees. There are a number of decision tree algorithms that can automatically prune the tree and make it much simpler. Combining a number of decision trees in an expert system can give good results.

Fuzzy Logic

Human decisions are always vague. There is nothing black and white in this world. We are always dealing with probabilities. We are never sure. Fuzzy logic is ideal in modelling human decisions. There are no crisp values in fuzzy sets. Did you read the post on how to trade with the only candlestick pattern you will ever need? Candlestick patterns are great when it comes to predicting the market. But trading with these candlestick patterns requires a lot of experience. There are many false patterns that can trap you into losing trades. You need to look at each pattern carefully in context of the big picture. Fuzzy Candlestick Trading Patterns have been successfully used to predict the market with 80% accuracy. We develop a fuzzy candlestick model that is then used in a decision tree or a neural network to make predictions. Researchers have reported good results. Fuzzy logic can have both subjective as well as an objective approach. Objective fuzzy logic approach as has been proposed by Takagi and Sugeno has been used in candlestick modelling and has produced impressive results.

Genetic Algorithm

Genetic Algorithm is a constraint optimization problem that has been inspired by the process of natural selection in biological evolution. Genetic Algorithm can be used to find the most optimal values of a trading strategy. Genetic algorithms use a process of initialization, selection, crossover and then mutation to find the best possible solution to an optimization problem. Genetic Algorithm has been used to find the trading rules for S&P 500 as well as in stock selection. Genetic algorithm has also been used in predicting market accuracy with impressive results. In the past genetic algorithms were computationally intensive. But with the increase computational power now available with most computers, it is possible to use these algorithms.

Kalman Filter

Kalman Filter was originally developed for control systems. It was successfully used in the Apollo Space mission. It is now part of the regular time series textbooks that now use it to smooth out a random walk. Stock prices are modeled as random walk. This random walk is then smoothed using a Kalman Filter. Kalman Filter uses the concept of system states. The system is supposed to go from one state to another state. In between the 2 states the system makes transition from one state to another state. Bayesian analysis is also used a lot in predicting how the system is going to transition from one state to another state. This is accomplished by developing system state equation and the observation state equation along with with Bayesian analysis as said above. There are now a number of econometric models that have been developed based on this filter. These models have been reported to give good results in predicting the weekly candle as well as the daily candle. Hedge funds use Kalman Filter a lot. But retail traders have no idea that his filter exists and is very popular with the hedge funds and the big institutions. Did you read our post on how to model a stock price time series using ARIMA and GARCH models? Kalman filter is being used to dynamically smooth these ARIMA models and GARCH models. Kalman Filter is a dynamic linear model and has been used extensively in statistical modelling.

Particle Filter

Particle Filter is a Sequential Monte Carlo algorithm. In Kalman Filtering we assume a normal Gaussian distribution of the random errors. This is the traditional assumption in most of time series analysis that the random errors have normal Gaussian distributions. But in reality we know that stock price is not normally distributed meaning it is not bell shaped rather is flat tailed. Flat tail has strong implication. It means that outliers are more frequent in stock prices. This is precisely what we observe as traders on daily basis. In the past modelling non normal distributions was not possible. But with massive increase in the computational power in the last decade, it became possible to develop non linear models especially this Sequential Monte Carlo Algorithm known as Particle Filtering. Particle Filtering has been used to predict the high and low of a stock price with impressive results.


Wavelets are being loved by hedge funds. It has been reported that hedge funds ask  a lot about wavelet modelling in their quant job interviews. Normal waves are continuous and extend on both sides. However wavelets are short disturbances that die done after a short period of time. Time series has been applied extensively to financial price data. But the results have not been very good. Wavelets is a new approach that has been developed to overcome the limitations that are inherent in traditional time series analysis. Wavelets are small waves that are of finite duration. Haar Transform gives much better results than the Fast Fourier Transform. In future, I will write a detailed post on how to use wavelets in predicting the market.


This was just a short introduction to 8 machine learning algorithms that can help you in trading. As said above technical indicators that were developed in 1970s and before are no longer useful in trading. We need a set of new indicators that can correctly model today’s markets. These are powerful machine learning algorithms that take into account the inherent randomness that we encounter in stock prices unlike the traditional indicators that we have been using which simply disregard uncertainty. As traders we know uncertainty is the number one rule in trading. Now if you want to learn and apply these machine learning algorithms in your trading you will need to learn R or Python language. Don’t be afraid of making an effort. Learning R and Python is not difficult at all. Just need some effort. Don’t miss your chance of learning these algorithms. Soon these machine learning algorithms will get superseded by deep learning algorithms that have become possible with the massive computational power that is now available with most computers. Today you can also take advantage of cloud computing in making real time calculations using these algorithms. You can read our post on how to design quantitative trading strategies using R. R is a powerful data analysis and machine learning language. So is Python. Welcome to the new world of Quantitative Trading.

About The Author


I have done masters from Harvard University. I am interested in day trading currencies, options and stocks.