How Machine Learning Is Used To Predict Stocks

Jonathan Schein
4 min readAug 3, 2020

--

Predicting stocks is one of the biggest gambles anyone can take on. People spend their lives trying to understand the stock market and make the most money. Everyone tries to come up with their own strategies and/or algorithms to beat the market. And although everyone is confident that their strategy is the best one, they are often wrong. Individuals and companies have come up with thousands of strategies and experiments to test out their ideas while ultimately only a few of them succeed. These people take many features into consideration such as behavioral economics, supply and demand, market conditions and many more variables to make their predictions. In this blog post, I am going to discuss how machine learning can be used to make predictions in the stock market.

Introduction to Machine Learning

Machine learning is the process of creating algorithms that improve themselves over time. The machine learning model is based on training data that makes predictions without being programmed directly to make those decisions. Machine learning can be used in many ways from predicting the price of cars or filtering spam emails from non-spam emails. However, in this blog, I would like to discuss how machine learning is used specifically in the case of predicting the stock market.

Technical Analysis

First I would like to introduce one of the fundamentals behind creating a machine learning model, Technical Analysis. This method takes into account what the stockholder believes the outcome of the market will be based on the price and the volume of the stocks. The main idea behind this method is to follow trends in the stock and try to identify patterns that will help you make predictions.

Machine Learning Models

Although many people believe that data science is the answer to creating the best model to predict the market, no model is objectively proven to be perfect. However, after testing and hypothesizing many models, some of the most popular techniques are Moving Average and Linear Regression.

  1. Moving Average: The idea behind Moving Average begins with taking the daily average of each stock over a period of time. The most common types of Moving Average take into account the daily average price of stocks between 30 and 90 days, but each model is unique and is up to the data scientist to use whichever amount of days he or she believes will be the most accurate. The machine learning model will then use something called a “neural network” which is a computer system that is modeled on the human brain. This neural network discovers patterns in the stock that other models do not detect.

2. Linear Regression: A Linear Regression Model is the second most popular technique to analyze trends in the market. The idea behind a linear regression model is that it takes one or more independent variables that the data scientist believes will impact the market and plots those variables against a dependent variable, usually the price of the stock. The model will then return an equation that will clearly relay back to the user the relationship between all those variables. The equation is then used for forecasting, predicting the trends and future outcomes of the stock market. A big disadvantage of using this model is that overfitting is often the result and therefore cannot make an accurate prediction.

3. K Nearest Neighbors The third type of machine learning model that is used to predict the stock market is K Nearest Neighbors. This model takes the independent variables to try and predict a data point. For example, if we wanted to calculate the weight of person x and we already had a scatter plot with ten other people which showed their height and age. We would then take the average weight of the k nearest neighbors on the scatter plot to determine the person x’s weight.

Conclusion

In this blog I introduced three very common and simple machine learning algorithms that are used by people every day to make predictions in the stock market. Predicting the stock market is one of the most tedious and essential skills for any finance expert out there, but the payoff could be very big. Many models exist to make predictions but each data scientist has his or her own model or models that they prefer to use. There is no perfect model out there and no one can predict the market with 100% certainty, but understanding basics about these machine learning algorithms can certainly give you a slight advantage.

Future Studies

  • Auto ARIMA
  • Long Short Term Memory

Sources

https://www.analyticsvidhya.com/blog/2018/10/predicting-stock-price-machine-learningnd-deep-learning-techniques-python/

--

--

Jonathan Schein
Jonathan Schein

Written by Jonathan Schein

Data Scientist, Brandeis University Alum and Flatiron School Alum

No responses yet