image_output_1.png
from statsmodels.tsa.arima_model import ARIMA

import matplotlib.pyplot as plt

model_ar = ARIMA(df.ftse, order=(1, 0, 0))
results_ar = model_ar.fit()

start_date = '2014-07-16'
end_date = '2015-01-01'

model_ret_ar = ARIMA(df.ret_ftse[1:], order=(5, 0, 0))
results_ret_ar = model_ret_ar.fit()

df_pred_ret_ar = results_ret_ar.predict(start=start_date, end=end_date)

model_ret_ma = ARIMA(df.ret_ftse[1:], order=(0, 0, 5))
results_ret_ma = model_ret_ma.fit()

df_pred_ret_ma = results_ret_ma.predict(start=start_date, end=end_date)

model_ret_arma = ARIMA(df.ret_ftse[1:], order=(4, 0, 5))
results_ret_arma = model_ret_arma.fit()
df_pred_ret_arma = results_ret_arma.predict(start=start_date, end=end_date)

model_ret_armax = ARIMA(df.ret_ftse[1:], exog=df[['ret_spx', 'ret_dax', 'ret_nikkei']][1:], order=(1, 0, 1))
results_ret_armax = model_ret_armax.fit()
df_pred_ret_armax = results_ret_armax.predict(start=start_date, end=end_date, exog=df_test[['ret_spx', 'ret_dax', 'ret_nikkei']][start_date:end_date])

df_test['int_ftse_ret'] = df_test.ftse.diff(1)

model_arima = ARIMA(df.ret_ftse[1:], order=(1, 1, 1))
results_arima = model_arima.fit()
df_pred_arima = results_arima.predict(start=start_date, end=end_date)
df_pred_arima[start_date:end_date].plot(figsize=(20, 5), color='red')
df_test.ret_ftse[start_date:end_date].plot(color='blue')
plt.title('Predictions vs Actuals(Returns) | ARIMA', size=24)
plt.show()