Stock Market Analysis And Forecasting Using Deep Learning
Original Source Here
Stock Market Analysis And Forecasting Using Deep Learning
the dataset is taken from Google, Microsoft, IBM, Amazon
Introduction:
This is the project of Stock Market Analysis And Forecasting Using Deep Learning. Here we use python, pandas, matplotlib, numpy, plotly, pytprch to implement our model.
A stock market, equity market, or share market is the aggregation of buyers and sellers of stocks (also called shares), which represent ownership claims on businesses; these may include securities listed on a public stock exchange, as well as stock that is only traded privately, such as shares of private companies which are sold to investors through equity crowdfunding platforms. Investment in the stock market is most often done via stock brokerages and electronic trading platforms. Investment is usually made with an investment strategy in mind.
The task of stock prediction has always been a challenging problem for statistics experts. The main reason behind this prediction is buying stocks that are likely to increase in price and then selling stocks that are probably to fall. Generally, there are two ways for stock market prediction. Fundamental analysis relies on a company’s technique and fundamental information like market position, expenses, and annual growth rates. The second one is the technical analysis method, which concentrates on previous stock prices and values.
We can see that the stock market is a profitable resource for a person but there are some risk factors too. The share market is continuously getting ups and downs in this field. So we have to be very conscious about the market price and the stock increment & decrement factor. For that, we need a broker, who has a strong acquaintance with the share market policy.
But after the evolution of data science, deep learning, and time series analysis the task of a stock buyer has become comprehensively easy. He or she can easily search in Google and get the necessary information of stock market policy for the felicity of data science.
In the first part of our project, we will try to analyze the data. and in the second part, we will forecast the stock market.
Dataset:
Here we will use multiple stock market datasets such as
- Google(2006–2018)
- Microsoft(2006–2018)
- IBM(2006–2018)
- Amazon(2006–2018)
There are a total of 3019 rows and 4 columns in this dataset.
Stock Market Analysis:
We will find the followings:-
- describe
- the distribution of close and open.
- correlation between close and open.
- visualize the attributes[Open, High, Low, Close, volume] of our datasets.
- compare the “High” and “Close” of each dataset.
- at last, the trend and seasonality in the dataset.
Describe:
After describing the google dataset, there is a high difference between the minimum and maximum values. And 75% of the value is close to the mean.
Also same for the Microsoft dataset, there is a high difference between the minimum and maximum values. And 75% of the value is close to the mean.
Also same for the Amazon dataset, there is a high difference between the minimum and maximum values. And 75% of the value is close to the mean.
But for the IBM dataset, we can see all the value is nearly close to the mean.
Distribution of Close & Open:
Correlation between close and open:
There is a very high correlation between “Open” and “Close”. As we can see from the scatter plot.
Compare the “High” and “Close” of each dataset:
As we can see here Microsoft’s “High” value is very slowly increasing straight line. IBM’s “High” value and Amazon’s “High” value started from the approx same stage, even Amazon’s “High” value was a bit lower but after 2012 Amazon’s “High” value started to exponentially increase and slight drop for IBM’s “High” value. Since 2016 there is a high fight going between Google’s “High” value and Amazon’s “High” value at 2018 Amazon’s “High” value also beat Google’s “High” value.
In Microsoft data, we can see in 2009 “High” value was under mean for a long time, so we can say there was some loss.
Same for Google data, we can see in 2009 “High” value was under mean for a long time, so we can say there was some loss. But it was not an as huge loss as Amazon.
Same for IBM data, we can see in 2009 “High” value was under mean for a long time, so we can say there was some loss. And after 2013 again a drop then in 2016 there was a huge loss but after that, they were doing well. After just some profit again in between 2017, there was another drop.
For Amazon’s “High” value the case is different they also face loss in 2009 but for a very little margin. And after that their growth is in exponential order.
Here we can see every company faced a loss in 2009, maybe that’s because of the economic slowdown.
Trend and Seasonality:
There is a very slow increasing trend until 2012, but after 2012 there was an exponential high trend. And very high seasonality.
Same for Microsoft data, there is a very slow increasing trend until 2012, but after 2012 there was an exponential high trend. And very high seasonality.
IBM data has a very slow increasing trend until 2008, but after 2009 there was an exponential high trend until 2013, then a high drop until 2016 then a very slow increasing trend. And very high seasonality.
Amazon data is similar to Google data.
Because there have a very strong correlation between Close and High, if we can plot the Close value then we will be able to see the trend and seasonality is very similar.
From the previous lines, we can see the analysis of the stock market. Now we are gonna see the forecasting procedures.
Prediction:
In this procedure, there are some train data & test data and we have to fit these data with the actual data. From the resulting graph, we can see that the data are too much fit that we can’t distinguish between the actual data and the predicted data (the 3 graph lines are perfectly matched).
Time Series Forecasting:
Time series forecasting uses information regarding historical values and associated patterns to predict future activity. Most often, this relates to trend analysis, cyclical fluctuation analysis, and issues of seasonality. As with all forecasting methods, success is not guaranteed.
Deep Learning:
Deep learning (also known as deep structured learning) is part of a broader family of machine learning methods based on artificial neural networks with representation learning. Learning can be supervised, semi-supervised or unsupervised.
Deep-learning architectures such as deep neural networks, deep belief networks, graph neural networks, recurrent neural networks, and convolutional neural networks have been applied to fields including computer vision, speech recognition, natural language processing, machine translation, bioinformatics, drug design, medical image analysis, material inspection, and board game programs, where they have produced results comparable to and in some cases surpassing human expert performance.
Artificial neural networks (ANNs) were inspired by information processing and distributed communication nodes in biological systems. ANNs have various differences from biological brains. Specifically, neural networks tend to be static and symbolic, while the biological brain of most living organisms is dynamic (plastic) and analog.
The adjective “deep” in deep learning refers to the use of multiple layers in the network. Early work showed that a linear perceptron cannot be a universal classifier, but that a network with a nonpolynomial activation function with one hidden layer of unbounded width can. Deep learning is a modern variation that is concerned with an unbounded number of layers of bounded size, which permits practical application and optimized implementation while retaining theoretical universality under mild conditions. In deep learning the layers are also permitted to be heterogeneous and to deviate widely from biologically informed connectionist models, for the sake of efficiency, trainability, and understandability, whence the “structured” part.
GRU Model:
Gated recurrent unit is essentially a simplified LSTM. It has the exact same role in the network. The main difference is in the number of gates and weights — GRU is somewhat simpler. It has 2 gates. Since it does not have an output gate, there is no control over the memory content. The update gate controls the information flow from the previous activation, and the addition of new information as well, while the reset gate is inserted into the candidate activation.
Results with Graph:
After all forecasting and analysis, we get the following resultant graphs.
(1) In the graph of Amazon stock prediction we can see that the three lines [Train prediction, Test prediction, Actual Value] are aptly submerged with each other. From that, we can say that the prediction is apt.
(2) In the graph of Google stock prediction we can see that the three lines [Train prediction, Test prediction, Actual Value] are aptly submerged with each other. From that, we can say that the prediction is apt.
(3) In the graph of IBM stock prediction we can see that the three lines [Train prediction, Test prediction, Actual Value] are aptly juxtaposed with each other. From that, we can say that the prediction is apt.
(3) In the graph of Microsoft stock prediction we can see that the three lines [Train prediction, Test prediction, Actual Value] are aptly juxtaposed with each other. From that, we can say that the prediction is apt.
Challenges:
In this project, we might have to face some challenges like a fitting problem. Like this, a time-series analysis fitting the model may be notorious but once you are able to fix it and find the right parameters it will be a very easy forward job to do. So this is the main hindrance to this project.
Project Link:
https://github.com/soham2707/Stock-Market-Analysis-And-Forecasting-Using-Deep-Learning.git
AI/ML
Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot
via WordPress https://ramseyelbasheer.io/2021/06/27/stock-market-analysis-and-forecasting-using-deep-learning/