Predicting forex rates with high accuracy using MCMC with Bayesian structural time-series
library(bsts)
library(ggplot2)
library(scales)
library(forecast)
This notebook contains code for log-term prediction of daily forex currency pair rates. However, instructions are included in the notebook for using a dataset with smaller than 24hr candles.
- You can find the compiled notebook containing all of the results here.
-
The data is loaded, preprocessed, and split into training and testing automatically.
-
A number of different models are defined (using the
bsts
library) to fit the training data and make predictions:
The performance of different models are plotted and compared with each other regarding their fit (in training):
and accuracy (in prediction):
- The optimal model with the highest accuracy is used on another currency pair to examine its performance.
- Finally, the performance of the Bayesian models are compared with that of popular time-series forecasting models such as ARIMA.
- The Bayesian models outperformed the ARIMA model, yielding a prediction accuracy of
98.3%
as apposed to75.7%
.
[1] Scott, Steven & Varian, Hal. (2014). Predicting the Present with Bayesian Structural Time Series. Int. J. of Mathematical Modelling and Numerical Optimisation. 5. 4 - 23. 10.1504/IJMMNO.2014.059942.
[2] Scott, Steven. (2020). The "bsts" Package Manual,