The Wolf of Wall Street | Predicting Stock Prices

Random Nerds
Oct 10, 2017 · 3 min read

Back in 2013, we all wanted to be in the shoes of Leonardo DiCaprio with stacks of money around us. Matter of fact is that there are people around us who does melt that kind of money from stock market every other day while we just keep daydreaming about it. Certainly, JP Morgan or Goldmann Sachs are not going to share their trade secrets with us in public forums or do we expect Warren Buffet to disclose his Bitcoin investment strategy. We know that is not going to happen so how about we take inspiration from them & try to make our own strategy to understand and predict stock market variations.

All we need to have is an inquisitive mind to understand the analogies as I paste the code to duplicate. We require all three dragons of Daenerys Targaryen, which in our case are: 1. Installing Dependencies 2. Collecting relevant data 3. Write magic lines of code. Once done, we can relax with our coffee mug while I explain the patterns of the variations. Let us drill down into 2016 data of Apple Inc. and Microsoft with this simple set of code:

Stock value Return on Apple & Microsoft for 2016

This will fetch us an insight of the returns that investors received on their venture in 2016. If we wish to visualize it for some other year, or span of years, we just need to alter ‘start’ and ‘end’ parameters in this piece of code. And then we can have a nice colorful plot of insights like this:

Graphical correlation of Returns on Investment in 2016

With that part of analysis been done, we still have an important task in hand as we need to create value with the insight that is available. Thinking of actions that can be taken, we can do: 1. Sentiment Analysis on company opinions 2. Past Stock Prices 3. Dividend 4. Sales Growth. Knowing the fact that changes in stock prices are not at random, good traders utilize predictive Machine Learning models as a tool before making an investment. To make all of us efficient with this, allow me to furnish an easy-to-use code that I have drafted again in Python that just needs to be cloned to get desirable insight before making an investment. But this time, to avoid complexity for beginners, I will use data only for one company and build three models on top of it, so lets ask Apple Inc. to “Show me the money!

We already have our libraries imported so let us start by creating two empty list that would contain our data: date = [] and stock_price = [] , followed by this two simple functions that I will define before calling them to get predicted values:

Creating 3 SVR models to predict Stock values of Apple Inc. in 2017

print(predict_price) is the magic keyword for us at the end to get 3 different types of plot for associated 2017 stock value predictions. Let us have a closer look at this graphical representation:

We can easily figure out looking at this graph that it is the Radio basis function (rbf) kernel that best fits our data so we have our key right here to obtain best of predictions. I don’t disagree with the efficient market hypothesis that states Stock prices are unpredictable BUT again it is better to have effective Machine Learning model predictions than just investing randomly. Good Luck investing!

For entire code or any suggestion/feedback to it, please visit my GitHub.

Deep Learning

This publication encompasses Deep Learning concepts that influence resolution of business or real-life problems that a beginner/professional can relate to or reference any time. Every now & then Applied Statistics also feature to enhance understanding of those concepts.

Random Nerds

Written by

Data Science Consultant

Deep Learning

This publication encompasses Deep Learning concepts that influence resolution of business or real-life problems that a beginner/professional can relate to or reference any time. Every now & then Applied Statistics also feature to enhance understanding of those concepts.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade