Skip to content

Commit 09a8e1b

Browse files
Update README.md
1 parent a212214 commit 09a8e1b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Predicting stock prices using a TensorFlow LSTM (long short-term memory) neural
44

55
## 1) Introduction
66

7-
Predicting stock prices is a cumbersome task as it does not follow any specific pattern. Changes in the stock prices are purely based on the supply and demand during a period of time. In order to learn the specific characteristics of a stock price, we can use deep learning to identify these patterns through machine learning. One of the most well-known networks for series forecasting is [LSTM](https://www.researchgate.net/publication/13853244_Long_Short-term_Memory) (long short-term memory) which is a Recurrent Neural Network (RNN) that is able to remember information over a long period of time, thus making them extremely useful for predicting stock prices. RNNs are well-suited to time series data and they are able to process the data step-by-step, maintaining an internal state where they cache the information they have seen so far in a summarised version. The successful prediction of a stock's future price could yield significant profit.
7+
Predicting stock prices is a cumbersome task as it does not follow any specific pattern. Changes in the stock prices are purely based on supply and demand during a period of time. In order to learn the specific characteristics of a stock price, we can use deep learning to identify these patterns through machine learning. One of the most well-known networks for series forecasting is [LSTM](https://www.researchgate.net/publication/13853244_Long_Short-term_Memory) (long short-term memory) which is a Recurrent Neural Network (RNN) that is able to remember information over a long period of time, thus making them extremely useful for predicting stock prices. RNNs are well-suited to time series data and they are able to process the data step-by-step, maintaining an internal state where they cache the information they have seen so far in a summarised version. The successful prediction of a stock's future price could yield a significant profit.
88

99
## 2) Stock Market Data
1010

@@ -313,11 +313,11 @@ Options
313313
('2020-07-02', '2020-07-10', '2020-07-17', '2020-07-24', '2020-07-31', '2020-08-07', '2020-08-21', '2020-09-18', '2020-11-20', '2020-12-01', '2020-12-18', '2021-01-15', '2021-06-18', '2022-01-21', '2022-06-17')
314314
```
315315

316-
The data has a json document which we could use later on to create our Security Master if we ever wanted to store this data somewhere to keep track of the Securities we are going to trade with. As the data could come with different fields, my suggestion is to store them on a Data Lake so we can build it from multiple sources withouth having to worry to much on the way the data is structured.
316+
The data has a JSON document that we could use later on to create our Security Master if we ever wanted to store this data somewhere to keep track of the Securities we are going to trade with. As the data could come with different fields, my suggestion is to store them on a Data Lake so we can build it from multiple sources without having to worry too much about the way the data is structured.
317317

318318
### 2.2) Market Data Download
319319

320-
The previous step helps us to identify several characteristiques of a given ticker symbol so we can use its properties to define some of the charts I'm showing below. Note that the yFinance library only requires the stock to download via ticker symbol, the start date and end date of the period we want to get. Additionally, we can also specify the granularity of the data using the interval parameter. By default the interval is 1 day and this is the one I will use for my training.
320+
The previous step helps us to identify several characteristics of a given ticker symbol so we can use its properties to define some of the charts I'm showing below. Note that the yFinance library only requires the stock to download via ticker symbol, the start date and end date of the period we want to get. Additionally, we can also specify the granularity of the data using the interval parameter. By default, the interval is 1 day and this is the one I will use for my training.
321321

322322
To download the data we can use the following command:
323323

@@ -408,23 +408,23 @@ Note that is important to mention the start date correctly just to ensure we are
408408

409409
Now that we have the data that we want to use, we need to define what defines our traning and validation data. As stocks could vary depending on the dates, the function I have created requires 3 basic arguments:
410410
- Ticker Symbol: **GOOG**
411-
- Start Date: Date as to when they started, in this case it was **2004-Aug-01**.
412-
- Validation Date: Date as to when we want the validation to be considered. In this case we specify **2017-01-01** as our data point.
411+
- Start Date: Date as to when they started, in this case, it was **2004-Aug-01**.
412+
- Validation Date: Date as to when we want the validation to be considered. In this case, we specify **2017-01-01** as our data point.
413413

414-
Note that you will need to have configured [TensorFlow](https://www.tensorflow.org/), Keras and a GPU in order to run the samples below.
414+
Note that you will need to have configured [TensorFlow](https://www.tensorflow.org/), Keras ,and a GPU in order to run the samples below.
415415

416416
In this exercise, I'm only interested in the [closing price](https://www.investopedia.com/terms/c/closingprice.asp) which is the standard benchmark regarding stocks or securities.
417417

418418
Below you can find the chart with the division we will create between Training Data and Validation Data:
419419
![](https://github.com/JordiCorbilla/stock-prediction-deep-neural-learning/raw/master/TrainingDataValidationData.png)
420420

421-
Also the histogram showing the distribution of the prices:
421+
Also, the histogram showing the distribution of the prices:
422422

423423
![](https://github.com/JordiCorbilla/stock-prediction-deep-neural-learning/raw/master/DataHistogram.png)
424424

425425
### 3.2) Data Normalization
426426

427-
In order to normalise the data, we need to scale it between 0 and 1 so we talk in a common scale. To accomplish this, we can use the preprocessing tool [MinMaxScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html) as seen below:
427+
In order to normalise the data, we need to scale it between 0 and 1 so we talk on a common scale. To accomplish this, we can use the preprocessing tool [MinMaxScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html) as seen below:
428428

429429
```python
430430
min_max = MinMaxScaler(feature_range=(0, 1))
@@ -433,7 +433,7 @@ In order to normalise the data, we need to scale it between 0 and 1 so we talk i
433433

434434
### 3.3) Adding Timesteps
435435

436-
LSTM network needs the data imported as a 3D array. To translate this 2D array into a 3D one, we use a short [timestep](http://colah.github.io/posts/2015-08-Understanding-LSTMs/) to loop through the data and create smaller partitions and feed them into the model. The final array is then reshaped into training samples, x number of timesteps and 1 feature per step. The code below represents this concept:
436+
LSTM network needs the data imported as a 3D array. To translate this 2D array into a 3D one, we use a short [timestep](http://colah.github.io/posts/2015-08-Understanding-LSTMs/) to loop through the data and create smaller partitions and feed them into the model. The final array is then reshaped into training samples, x number of timesteps, and 1 feature per step. The code below represents this concept:
437437

438438
```python
439439
time_steps = 3
@@ -526,7 +526,7 @@ Once we have defined the model, we need to specify the metrics we want to use to
526526
callbacks=[callback])
527527
```
528528

529-
This model is slightly fined tuned to reach the lowest validation loss. In this example, we reach a validation loss of 0.20% with an MSE (Mean Square Error) of 0.14% which is relatively good, providing us with a very accurate result.
529+
This model is slightly fined tuned to reach the lowest validation loss. In this example, we reach a validation loss of 0.14% with an MSE (Mean Square Error) of 0.14% which is relatively good, providing us with a very accurate result.
530530

531531
The training result can be seen below:
532532

@@ -565,7 +565,7 @@ MSE : 0.0014113366
565565

566566
Now it is time to prepare our testing data and send it through our deep-learning model to obtain the predictions we are trying to get.
567567

568-
First we need to import the test data using the same approach we used for the training data using the time steps:
568+
First, we need to import the test data using the same approach we used for the training data using the time steps:
569569

570570
```python
571571
# Testing Data Transformation
@@ -590,7 +590,7 @@ With the validation loss and validation MSE metrics:
590590

591591
# 4) Usage
592592

593-
This has been built using python 3.6.8 version.
593+
This has been built using Python 3.6.8 version.
594594

595595
Download the source code and install the following packages:
596596

0 commit comments

Comments
 (0)