Introducing the problem statement
The stock market is a place where you can buy and sell units of ownership in the company, which we call stocks. If the company performs well and increases its profit, then you will earn some profit as well because you have the stocks of the company, but if the company's profit goes down, then you will lose the money you have with the company. So if you invest your money in the right company at the right time, it could lead to you earning quite a lot of money. The question is which company's stock should you buy? Is there any way we can predict the future prices of the stock of any company given the historical prices of the company's stock so that we can have higher chances of getting good returns? The answer is yes. This is what we will explore in this chapter.
If you invest in the stock market, then you may have heard that stock prices are completely random and unpredictable. This is called the efficient market hypothesis, but a majority of the big financial firms, such as JP Morgan, Citigroup, and Goldman Sachs, have mathematical and quantitative analysts who are trying to develop predictive models to help these big firms decide when to invest and in which stock.
Before investing in any stock, we do some basic research regarding the company's profile. We try to understand its business model. We also check the balance sheets of the company to get to know what the profit and loss of the company is. What are the products that the company will launch in the next couple of months? What kind of news is coming in about the company? What are the current industry trends? After researching all these parameters, we will invest our money in a particular company's stock if we feel we will gain some profit; otherwise, we won't invest in that company.
We depend on various sources of information to get an idea about whether we need to buy stocks or sell stocks. Don't you think all this analysis takes a lot of our time? I want to put two questions in front of you. First, can we use some of the data points discussed here and build a system that will help us find out future stock prices? And can we use historical stock prices to predict future stock prices? The answer to both of these questions is yes, definitely: we can build a system that will use historical stock prices and some of the other data points so that we can predict the future prices of stock. As per the efficient market hypothesis, by using historical prices of stock and various other data points, we can obtain the future prices of the stock, which will be better than a random guess. In this chapter, we will build a predictive model, which will predict the close price of the stock. In the next section, we will look at how to collect the dataset in order to build the model. So, let's get started!