Last active
June 16, 2020 14:03
-
-
Save jlopezper/a39beffb518fb3fecac35101392ceed3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas_datareader as pdr | |
import matplotlib.pyplot as plt | |
from statsmodels.tsa.stattools import adfuller | |
from statsmodels.graphics.tsaplots import plot_acf | |
import seaborn as sns | |
import warnings | |
from statsmodels.tsa.arima_model import ARIMA | |
from sklearn.metrics import mean_squared_error | |
warnings.filterwarnings("ignore") | |
# Download the information of closing prices from Yahoo Finance | |
start_date = '01-Jan-08' | |
end_date = '14-Feb-20' | |
ticker = 'V' # Set the ticker (Visa in this example) | |
data = pdr.get_data_yahoo(ticker, start_date, end_date)['Adj Close'] | |
# Plot the Adjusted Close Price | |
plt.rcParams["figure.figsize"] = (10, 7) | |
plt.style.use('seaborn-darkgrid') | |
# Splitting data into train and test set | |
split = int(len(data)*0.90) | |
train_set, test_set = data[:split], data[split:] | |
# Convert test set into dataframe and compute the lag | |
tst = test_set.to_frame() | |
tst['Lag'] = test_set.shift(1, fill_value=0) | |
error = mean_squared_error(tst[1:]['Adj Close'],tst[1:]['Lag']) | |
print('Test MSE: {mse}'.format(mse=error)) | |
plt.plot(tst[1:]['Adj Close']) | |
plt.plot(tst[1:]['Lag'], color='red') | |
plt.title('Visa Stock Price') | |
plt.xlabel('Date') | |
plt.ylabel('Price in dollars') | |
plt.legend(['test_set','test_set (lag1)']) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment