Stock Prices
Apply time series analysis techniques to forecast stock prices.
We'll cover the following...
Context
We'll work with stock prices from an American gaming retailer called GameStop Corp. to predict its close price.
Let's start by taking a look at the data to gather some basic information.
import pandas as pdimport matplotlib.pyplot as pltdf = pd.read_csv('data.csv')# Changing the datatypedf["date"] = pd.to_datetime(df['date'], format='%Y-%m-%d')# Looking at the dataframeprint(df.head())print(df.tail())# Setting the Date as indexdf = df.set_index('date')# Choosing the variable we will work withclose_price = df['close_price']# Plottingfig, ax = plt.subplots(figsize=(7, 4.5), dpi=300)ax.plot(close_price)# Labellingplt.xlabel("Date")plt.ylabel("Price (USD)")plt.title("GameStop stock close price")fig.savefig("output/output.png")plt.close(fig)
There's much relevant information we can get from this first look.
There doesn't seem to be a trend.
There doesn't seem to be a seasonal pattern.
There's one huge outlier at the very end.
Data is daily, and it goes from 2002 to 2021.
The first thing we need to do is get rid of that outlier. After a quick online search, we see that there was indeed an outstanding event in January 2021 that made that specific stock price soar. That means we are dealing with a different kind of outlier—one that is a true value. Not only that, but we have no data after that peak, so it gets harder to ...