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:
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:
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:
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.