I am trying to use an ARIMA model to predict stock price data, specifically, I am using auto_arima. My goal is to predict the next 30 days of stock prices and compare it to the test data.
I am unable to predict the data correctly as seen in the graph below.
Here is the code I used:
#general
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
%matplotlib inline
import yfinance as yf
ticker = "0118.KL"
data = yf.Ticker(ticker)
df = data.history(start="2019-01-01",end="2020-04-30")
df = df.filter(items=['Close'])
train = df[:-30]
test = df[-30:]
from pmdarima import auto_arima
model = auto_arima(train,trace=True,m=7,error_action='ignore', suppress_warnings=True)
model.fit(train)
forecast = model.predict(n_periods=30)
forecast = pd.DataFrame(forecast,index = test.index,columns=['Prediction'])
plt.plot(test, label='Valid')
plt.plot(forecast, label='Prediction')
plt.show()
Any idea on how to get a better fit? Thank you for reading.