You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this article, we will explore time series data extracted from the **stock market**, focusing on prominent technology companies such as Apple, Amazon, Google, and Microsoft. Our objective is to equip data analysts and scientists with the essential skills to effectively manipulate and interpret stock market data.
17
+
In this article, we will explore time series data extracted from the **stock market**, focusing on prominent technology companies such as Apple, Amazon, Google, and Microsoft. Our objective is to equip data analysts and scientists with the essential skills to effectively manipulate and interpret stock market data.
19
18
20
19
To achieve this, we will utilize the *yfinance* library to fetch stock information and leverage visualization tools such as Seaborn and Matplotlib to illustrate various facets of the data. Specifically, we will explore methods to analyze stock risk based on historical performance, and implement predictive modeling using **GRU/ LSTM** models.
21
20
@@ -27,16 +26,20 @@ Throughout this tutorial, we aim to address the following key questions:
27
26
4. What is the **correlation** between different stocks?
28
27
5. How can we forecast future stock behavior, exemplified by predicting the closing price of Apple Inc. using LSTM or GRU?"
29
28
30
-
***
29
+
---
31
30
32
31
## Getting Data
32
+
33
33
The initial step involves **acquiring and loading** the data into memory. Our source of stock data is the **Yahoo Finance** website, renowned for its wealth of financial market data and investment tools. To access this data, we'll employ the **yfinance** library, known for its efficient and Pythonic approach to downloading market data from Yahoo. For further insights into yfinance, refer to the article titled [Reliably download historical market data from with Python](https://aroussi.com/post/python-yahoo-finance).
34
34
35
35
### Install Dependencies
36
+
36
37
```bash
37
38
pip install -qU yfinance seaborn
38
39
```
40
+
39
41
### Configuration Code
42
+
40
43
```python
41
44
import pandas as pd
42
45
import numpy as np
@@ -62,13 +65,16 @@ data = yf.download("MSFT", start, end)
62
65
```
63
66
64
67
## Statistical Analysis on the price
68
+
65
69
### Summary
70
+
66
71
```python
67
72
# Summary Stats
68
73
data.describe()
69
74
```
70
75
71
76
### Closing Price
77
+
72
78
The closing price is the last price at which the stock is traded during the regular trading day. A stock’s closing price is the standard benchmark used by investors to track its performance over time.
Volume is the amount of an asset or security that _changes hands over some period of time_, often over the course of a day. For instance, the stock trading volume would refer to the number of shares of security traded between its daily open and close. Trading volume, and changes to volume over the course of time, are important inputs for technical traders.
93
+
85
94
```python
86
95
plt.figure(figsize=(14, 5))
87
96
plt.plot(data['Volume'], label='Volume')
@@ -92,8 +101,8 @@ plt.show()
92
101
```
93
102
94
103
### Moving Average
95
-
The moving average (MA) is a simple **technical analysis** tool that smooths out price data by creating a constantly updated average price. The average is taken over a specific period of time, like 10 days, 20 minutes, 30 weeks, or any time period the trader chooses.
96
104
105
+
The moving average (MA) is a simple **technical analysis** tool that smooths out price data by creating a constantly updated average price. The average is taken over a specific period of time, like 10 days, 20 minutes, 30 weeks, or any time period the trader chooses.
97
106
98
107
```python
99
108
ma_day = [10, 20, 50]
@@ -112,7 +121,9 @@ plt.show()
112
121
```
113
122
114
123
## Statistical Analysis on the returns
124
+
115
125
Now that we've done some baseline analysis, let's go ahead and dive a little deeper. We're now going to analyze the risk of the stock. In order to do so we'll need to take a closer look at the daily changes of the stock, and not just its absolute value. Let's go ahead and use pandas to retrieve teh daily returns for the **Microsoft** stock.
GRU-based model shows a bit better results both graphically and on MSE. However, this does not tell us anything about the actual profitability of these models.
264
+
212
265
## Possible trading performance
266
+
267
+
The strategy implementation is:
268
+
269
+
* BUY: if prediction > actual_price
270
+
* SELL: if prediction < actual_price
271
+
272
+
To close a position the next candle _close_ is waited. However, LSTM and GRU has some offset that does not allow a proper utilization of this strategy.
273
+
274
+
Hence, the **returns** of the predictions are adopted.
As showed in the previous section, these two simple Deep Learning models exhibits interesting positive results both regarding regression and trading metrics.
307
+
The latter is particularly important, indeed a return of **5%** is obtained while the stock price decreased of approximately 4%. This also lead to a very high sharpe and colmar ratio.
<h5class="card-title">Microsoft Stock Prediction using LSTM or GRU</h5>
305
-
<pclass="card-text post-summary">Pick a stock commodity ’ … '
306
-
Statistical Analysis on the price Statistical Analysis on the returns GRU Model Init Training Testing Metrics mean squared error LSTM Comparison Possible trading performance </p>
304
+
<h5class="card-title">MSFT Stock Prediction using LSTM or GRU</h5>
305
+
<pclass="card-text post-summary">Introduction In this article, we will explore time series data extracted from the stock market, focusing on prominent technology companies such as Apple, Amazon, Google, and Microsoft. Our objective is to equip data analysts and scientists with the essential skills to effectively manipulate and interpret stock market data.
306
+
To achieve this, we will utilize the yfinance library to fetch stock information and leverage visualization tools such as Seaborn and Matplotlib to illustrate various facets of the data.</p>
307
307
</a>
308
308
309
309
<divclass="tags">
@@ -326,7 +326,7 @@ <h5 class="card-title">Microsoft Stock Prediction using LSTM or GRU</h5>
<description>Pick a stock commodity &rsquo; &hellip; '
16
-
Statistical Analysis on the price Statistical Analysis on the returns GRU Model Init Training Testing Metrics mean squared error LSTM Comparison Possible trading performance </description>
15
+
<description>Introduction In this article, we will explore time series data extracted from the stock market, focusing on prominent technology companies such as Apple, Amazon, Google, and Microsoft. Our objective is to equip data analysts and scientists with the essential skills to effectively manipulate and interpret stock market data.
16
+
To achieve this, we will utilize the yfinance library to fetch stock information and leverage visualization tools such as Seaborn and Matplotlib to illustrate various facets of the data.</description>
0 commit comments