Prediction of Currency Exchange Rate using Neural Networks
In this example, data consist of the daily exchange rates of the British
pound and the German mark compared to the U.S. dollar from the beginning
of 1987 to the end of 1997. The data was contributed by Agustin Leon,
Quantitative Research, Rotella Capital Management, whose contribution is
Networks, the additional Mathematica standard add-on
package, and the data.
Two time series have now been loaded. The variable ybr contains the
exchange rate for the British pound, and ydeu contains the rate for
the German mark.
Check the time-series dimensions.
Exchange rates from approximately 2850 days are available. There are four
rates given for each day, representing the opening, high, low, and closing
Concentrate now on the German mark.
Plot the high price of the German mark versus the day number.
Suppose you want to predict the opening price using the exchange rates
from the previous day. Therefore, the opening price is defined as the
output of the process, which will be stored in y, and the three
other rates are defined as inputs and will be stored in u.
Divide the columns into input and output.
The predictor model can be described by the following equation:
Here (t) is the prediction of the output
y(t), the function g is the neural network model, theta
represents the parameters of the model, and x(t) is the model's
regressor. The regressor is given by the following equation:
To have a fair test of the predictor, the data set is divided into
training data and validation data. The second data set will be used to
validate and compare the different predictors. The following commands
write the training data into matrices ue and ye and the
validation data into uv and yv.
Divide the data into training and validation data.
NeuralARX is the appropriate neural model for this problem. Such a network
is initialized and estimated by the command NeuralARXFit as described in
Chapter 8, Dynamic Neural Networks. First, a linear predictor model will be
estimated. To find this prediction, choose FeedForwardNet without hidden
neurons. To obtain the regressor in the form Eq. (12.1), the regressor
indices have to be chosen as follows:
Estimate a linear model for the currency prediction.
A linear model is just a linear combination of the regressor components
and a DC-level parameter; that is, a linear model in Eq. (12.0) can be
If you look at the parameters of the trained model, you see that is close to 1 and the rest of the parameters are close
to 0. This means that the opening exchange rate is most closely correlated
with the closing rate of the day before. This seems to be a very natural
feature and you can, therefore, have some faith in the model.
Before a nonlinear model is trained on the data, the one-step prediction
on the validation data is evaluated. Since the market is changing with
time, the prediction is evaluated only on the 100 days following the
Evaluate the one-step prediction on validation data.
The plot shows the predicted rate together with the true rate. The two
curves are so close that you can hardly see any difference between them.
The RMSE of the prediction is also given, and you can also use it as a
measure of the quality of the predictor. It is now time to try nonlinear
models to see if they can predict better than the linear one. A
feedforward network with two hidden neurons is chosen. The regressor
chosen is the same as for the linear model. A linear model is included in
parallel with the network. Because the validation data is included in the
following training, the estimate is obtained with stopped search.
Train a feedforward network with two neurons on the exchange rate data.
The improvement of the neural network during the training is very small
because the initialization of the network uses
least-squares to fit the linear parameters.
Compute the one-step prediction on the same data interval used for the
The RMSE is slightly lower for the nonlinear model than for the linear
one. Thus, the prediction is slightly better. It is typical for the
improvement of economic data to be small. Otherwise, it would be too easy
to make money.
Now consider a radial basis function network. Keep the same arguments used
for the feedforward network, except change to an RBF network with two
Initialize and train an RBF on the exchange rate data.
The performance of the RBF network on validation data became worse during
the training, causing the initialized RBF network to be returned.
Evaluate the one-step prediction with the RBF network.
The RBF network is slightly better than the linear network, but not as
good as the feedforward network. If you reevaluate the example, the result
might change slightly due to the randomness in the initialization.
You can repeat the example changing several options, such as the
Change the number of neurons.
Change the regressor to contain more past values.
Exclude some of the input signals from the regressor.
You can also change the data interval used in the training and in the
validation. Also, try to predict the British pound instead of the German
The example illustrates that it is possible to predict the opening
exchange rate using the rates from the previous day. The relationship is
obviously nonlinear, since the nonlinear models based on feedforward and
RBF networks performed slightly better than the linear model.