This article discuss the implementation of Auto-Regressive (AR) Model as a forecasting trading strategy, then backtest the preformance in ALGOGENE Research Lab.
Library to use:
The discussion below adopts a widely used Statistics Python package 'statsmodels'.
In addition to estimating the parameters of a model, the library can also do forecasting, both in-sample and out-of-sample using 'statsmodels'. The in-sample is a forecast of the next data point using the data up to that point, and the out-of-sample forecasts any number of data points in the future. These forecasts can be made using either the predict() method if you want the forecasts in the form of a series of data, or using the plot_predict() method if you want a plot of the forecasted data. You supply the starting point for forecasting and the ending point, which can be any number of data points after the data set ends.
- Import the class 'ARMA' in the module 'statsmodels.tsa.arima_model'
- Create an instance of the ARMA class called 'mod' using the backtest data series data_1 and the order (p,q) of the model (in this case, for an AR(1) order=(1,0)
- Fit the model mod using the method '.fit()' and save it in a results object called res
- Start the forecast 5 data points before the end of the 30 point series at 25, and end the forecast 5 data points after the end of the series at point 35
Suppose we apply an AR(1) for daily Hang Seng Index CFD closing price, over the year of 2018.
- Based on a sliding window approach to collect the last 30 closing price
- Fit an AR(1) model, and forecast the next 5 closing price
- Submit a buy order if the 5th forecast price is above current level; else submit a sell order
- Set the holding period to 5 days for each position opening
- Repeat the process until the backtest period end