Utilize Decision Trees in Machine Learning to Predict Stock Movements

Machine Learning is the new buzz word today and some of the tech companies are doing wonderful unimaginable things with it. Today, we’re going to show you, how you can predict stock movements (that’s either up or down) with the help of ‘Decision Trees’, one of the most commonly used ML algorithms.

Decision trees are used for building classification and regression models to be used in data mining and trading. A decision tree algorithm performs a set of recursive actions before it arrives at the end result and when you plot these actions on a screen, the visual looks like a big tree, hence the name ‘Decision Tree’.

Here’s an example of a simple decision tree.

Basically, a decision tree is a flowchart to make you help decisions. Machine Learning uses the same technique to make better decisions, let’s find out how.

Visualizing a sample dataset and decision tree structure

Now let’s come to the point, we want to predict which way your stock will go using decision trees. We’ll need past data of the stock for that. Consider a sample stock dataset as shown in the table below. The dataset comprises of Open, High, Low, Close Prices and Volume indicators (OHLCV). You can download historical data for any stock using Yahoo finance or Google finance.

We will be doing this exercise in R programming language, you’ll have to install the supporting software on your mac/pc. Here is a link to help you with that. And here’s the code for importing this data onto –

And here’s visual representation of the data.

Let us add some technical indicators (RSI, SMA, LMA, ADX) to this dataset. Technical indicators are calculated using basic stock values (OHLC) in our case and they help us predict stock movements. Our machine learning algorithm will make use of the values from the technical indicators to make more accurate predictions. We lag the technical indicator values to avoid look-ahead bias.

We also add the “Class” column which signifies the daily returns based on the close price of the stock. In the “Class” column, “Up” denotes positive return, whereas “Down” signifies a negative return. Here’s the code for the same

Read the original article at: http://ow.ly/f2tZ30fU0Gs