0% found this document useful (0 votes)
111 views14 pages

Neural Networks Project Report

The document discusses using an artificial neural network to predict currency exchange rates. Specifically, it proposes using a nonlinear autoregressive exogenous neural network (NARX) that takes in previous exchange rate values and six quantitative parameters like consumer price index and interest rates. The network is trained on 30 years of Indian currency data to predict exchange rates up to a given date against other currencies. It represents the network structure and training process. The goal is to accurately predict exchange rates for improved investment decisions.

Uploaded by

Archit Sahay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views14 pages

Neural Networks Project Report

The document discusses using an artificial neural network to predict currency exchange rates. Specifically, it proposes using a nonlinear autoregressive exogenous neural network (NARX) that takes in previous exchange rate values and six quantitative parameters like consumer price index and interest rates. The network is trained on 30 years of Indian currency data to predict exchange rates up to a given date against other currencies. It represents the network structure and training process. The goal is to accurately predict exchange rates for improved investment decisions.

Uploaded by

Archit Sahay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

CURRENCY EXCHANGE RATE PREDICTION USING ARTIFICIAL NEURAL

NETWORKS
Archit Sahay
Roll Number: 16EE207
Department of Electrical and Electronics Engineering, National Institute of Technology
Karnataka Surathkal, Mangaluru
ABSTRACT
Predicting currency exchange rates is necessary in many ways. I proposed to use an artificial
neural network approach to achieve the same. Artificial neural networks with the powerful
computational and prediction capabilities would be a handy tool to accurately predict complexity
of exchange rates over various time durations. Here I propose to use an NARX, that is a
nonlinear autoregressive exogenous neural network to predict future values of exchange rates.
This uses previous values of exchange rates and six quantifiable input parameters to make its
prediction. The output is displayed in the form of a graph showing values of exchange rates until
the desired date.
INTRODUCTION
International currency exchange rates are important in today's global economy. Knowing the
value of our home currency in relation to different foreign currencies helps investors to analyze
investments priced in foreign currency. For example, for an Indian investor, knowing the dollar
to rupee exchange rate is valuable when choosing European investments. A declining INR could
increase the value of foreign investments, just as an increasing INR value could hurt the value of
foreign investments. The international currency exchange rate is an important determinant of the
health of an economy, and is one of the most watched and analyzed macro factor on a global
scale. Exchange rates play a vital role in a country's level of trade, which is critical to most
every free market economy in the world. For this reason, exchange rates are among the most
watched, analyzed and governmentally manipulated economic measures. But exchange rates
matter on a smaller scale as well: they impact the real return of an investor's portfolio. Here, we
look at some of the major forces behind exchange rate movements.
Consumer Price Index: Weighted average of prices of a basket of consumer goods and
services, such as transportation, food and medical care.
Real Interest Rates: The weighted average rate of interest an investor, saver or lender
receives (or expects to receive) after allowing for inflation in a particular country.
Government Debt: Debt ratio is the amount of a country's total gross government debt as a
percentage of its GDP.
Current Account Balance: Index consisting of the balance of trade, net primary
income or factor income (earnings on foreign investments minus payments made to foreign
investors) and net cash transfers that have taken place over a given period of time.
Purchasing Power Parity: Adjustments needed to be made in the exchange rates of two
currencies to make them at par with the purchasing power of each other.
Terms of Trade Index: Ratio of export prices to import prices in a particular year.

Therefore, the objective is to accurately predict currency exchange rate values this given
parameters for weekdays up to a given date.
Therefore, I thought of creating e a neural network that takes into account these parameters.
There can be other parameters also for the same, however due to possible overlap with them and
unsuitable quantification made me limit the parameters to six. The neural network used as
mentioned is a nonlinear autoregressive exogenous one. The network is trained using previous
values of currency exchange rates for weekdays over a definite period of time. The input series
consists of a single series created from which of these 6 parameters over the same period of time
and also mathematically extended to the requisite future time until when the prediction is
required. The training function used is Bayesian regularization.
Using this particular model prediction can be made up to a daily resolution considering business
days only. The training, validation and testing is done over 30 year time India's data. To predict
exchange rates of Indian currency with any other foreign currency this particular data set is used
to form the input series and the training data series is formed by the previous exchange rate
values between the two currencies. Suppose exchange rates of two currencies are to be predicted
none of which is India, then a 2 step process is used. Exchange rate values of the particular
currencies are calculated with respect to Indian currency and the common factor of Indian rupee
value is removed to get the exchange rate between those two currencies. This is done for the
convenience of having only one data set for the formation of input series. Otherwise the process
of acquiring data becomes pretty cumbersome. The results are displayed in the form of a graph
where values up to the required resolution can be seen until the desired date.
The neural network used is one for time series prediction. The only modification is that it also
considers values of an input series for making its forecast. This neural network takes only one
input time series and one training series. For the sake of good performance and after several trial
and error sessions network used feedback delays and 20 input delays along with 10 hidden
layers. This was considered to be optimal taking into account several factors such as time and
accuracy. Once trained the loop of the network is closed to make predictions.
Fig1: Diagrammatic Representation of NARX network

LITERATURE REVIEW
From the referenced literature, it can be summarized that there are many kinds of forecasting
methods are developed by thousands of researches and experts. Technical and fundamental
analysis are among the major forecasting methods which are popularly used in the financial area.
Foreign exchange rates are affected by many highly correlated factors. These factors could be
economic, political and even psychological factors. The interaction of these factors is in a very
complex fashion. Therefore, to forecast the change of foreign exchange rates is generally very
difficult. Neural networks are an emerging and challenging computational technology and they
offer a new avenue to explore the dynamics of a variety of financial applications. Actually, they
are simulated networks with interconnected `neurons' which try to mimic the function of the
brain's central nervous system. Neural networks have been shown to have great potential for
financial forecasting. Feed-forward backpropagation networks are the most commonly used
networks and meant for the widest variety of applications. Over the past two decades, a number
of studies have been conducted for forecasting exchange rates using neural networks. Here, a
brief review is given in the references:-
Adewole adetunji et.al.[1] present a neural network system for foreign exchange rate prediction.
The authors observe the performance of the proposed method for USA dollar, European
Currency (EURO), Great Britain Pound (GB) and Japanese Currency (Yen) against Nigerian
Money (Naira). Athanasios Sfetsos et al. [2] have introduced a system to compare four methods
including random walk , linear regression, auto regression integrated moving average and
artificial neural network in forecasting exchange rate between US dollar and GB pound. Carney
et al. [3] have suggested that neural network models are better than the conventional model
methods in predicting foreign exchange rates on Deutsche marks, British pounds, Swedish krona
and U.S. dollars. The authors employed two methods single-step predictions and multi-step
predictions. They discovered multi-step models had more accurate predictions than the single-
step models. Diebold et al. [4] have investigated ten weekly spot rates and did not find any
significant difference in both in-sample fit and out-of-sample forecasting across these exchange
rate series. Hann et al .[5] have presented a new approach to compare neural network models
with linear monetary model in forecasting exchange rate between U.S. dollar and Deutsch mark.
Jingtao Yao et al. [6] have developed a system using neural network for prediction. Time series
data and simple technical indicators, such as moving average, are fed to the neural networks to
catch the movement in currency exchange rates between American dollars and five other major
currencies. The authors indicate that without using extensive market data, useful predictions can
be made and a paper profit can be achieved for out-of-sample data with a simple technical
indicator. Joarder Kamruzzaman et al. [7] have investigated artificial neural networks based
prediction modeling of foreign currency rates using three learning algorithms, namely, Standard
Back propagation (SBP), Scaled Conjugate Gradient (SCG) and Back propagation with Bayesian
Regularization (BPR).The authors have shown that SCG based model outperforms other models
when measured on two commonly used metrics and attains comparable results with BPR based
model on other three metrics. Kuan et al. [8] have developed a new technique for predicting
foreign exchange rate. The authors also examined the performance of feed-forward neural and
recurrent neural. Lavanya et al. [9] have discussed various back propagation algorithm to predict
foreign exchange rate between Australia dollar and Chinese yen. The authors said that LM based
algorithm can predict accurately than other algorithms. It also has smallest mean square error.
Prem Chand Kumar et al. [10] presents two neural network models for cash forecasting for a
bank. One is daily model and other is weekly model. They have shown that the proposed system
performs better than other forecasting systems. It can be scaled for all branches of a bank in an
area by including historical data from these branches.

DATASET USED

For the input series:-


The dataset used consisted of values of the six parameters; i.e. CPI, Interest Rate, Current
Account Balance, Government Debt, PPP and Terms of Trade Index. The values of these were
used for India over a period of 30 years from 1988 to 2017. 1988 was the earliest year for which
values of all these parameters were available and has hence, been considered the starting year for
this purpose.

Current Account
Year CPI Real Interest Rate Government Debt Balance PPP
1988 8.79 7.638633 41.97 -1.5042 3.493
1989 5.42 7.435843 47.12 -0.5327 3.57
1990 13.71 5.269527 48.35 -1.0682 3.62
1991 13.07 3.624717 75.33 -1.3395 3.573
1992 8 9.132749 77.41 -2.6457 3.384
1993 8.64 5.814777 76.98 -5.0049 3.477
1994 9.47 4.33711 73.46 -3.4293 3.602
1995 9.69 5.864178 69.65 -3.2908 3.737
1996 10.41 7.792994 65.98 -1.9779 3.874
1997 6.29 6.909579 67.82 -2.6094 3.87
1998 15.32 5.121276 68.09 -0.6724 4.003
1999 0.47 9.191247 70.04 -1.0104 4.197
2000 3.48 8.342611 73.65 -1.2713 4.163
2001 5.16 8.591449 78.73 0.1115 4.266
2002 3.2 7.907177 82.85 1.4631 4.307
2003 3.72 7.307881 84.24 1.3895 4.467
2004 3.78 4.910135 83.29 0.2944 4.578
2005 5.57 6.248331 80.89 -0.9956 4.774
2006 6.53 4.477354 77.11 -0.7131 4.952
2007 5.51 6.869183 74.03 -1.6605 5.158
2008 9.7 4.277227 74.54 -0.7227 5.207
2009 14.97 5.773571 72.53 -1.5364 5.671
2010 9.47 1.085342 67.46 -1.565 5.941
2011 6.49 1.498947 69.64 -0.5191 6.085
2012 11.17 2.47352 69.07 -0.6807 6.221
2013 9.13 3.865993 67.96 -1.5773 6.402
2014 5.86 6.695176 68.33 -1.6104 6.645
2015 6.32 7.775343 69.07 -2.2216 6.954
2016 2.23 6.000743 69.6 -2.3324 7.221
2017 4 6.32125 68.7 -2.441 7.431

For the training series:-


The data set used has 8067 weekday values of currency from 1 January 1988 to 26 October
2018.
A few of those values are:-

Date Price
30-Oct-18 73.605
29-Oct-18 73.601
28-Oct-18 73.461
26-Oct-18 73.46
25-Oct-18 73.23
24-Oct-18 73.23
23-Oct-18 73.55
22-Oct-18 73.56
21-Oct-18 73.475
19-Oct-18 73.375
18-Oct-18 73.53
17-Oct-18 73.6
16-Oct-18 73.465
15-Oct-18 73.77
14-Oct-18 73.686
12-Oct-18 73.61
11-Oct-18 74.05
10-Oct-18 74.25
PREPROCESSING OF DATA
The input series data is preprocessed to increase the resolution. Two problems are faced:-
1) The NARX network takes only one input series but we have six parameters.
2) The values of the parameters chosen are available on a yearly basis while the prediction
needs to be made on a daily basis.
To form a single input series from 6 series, another feed forward neural network is used. This
feed forward network has 6 time series inputs which are the values of the six parameters used
over a period of thirty years. It is trained with the yearly average value of exchange rate over the
same period using “adapt command” for 1000 epochs using a learning rate of 0.00001 for the
gradient descent learning method. The output of this forms one weighted, consolidated series
with thirty yearly values.

Fig3: Feed Forward Neural Network Used To Generate One Series


Therefore, the MATLAB curve fitting tool is used for the same. This curve fitting gives us 8067
data points from just 30 data points. Also, using the function generated, this is used to calculate
the future values of the series.

Fig4: Curve Fitting to Enhance Resolution


THEORETICAL BACKGROUND
In time series modeling, a nonlinear autoregressive exogenous model (NARX) is
a nonlinear autoregressive model which has exogenous inputs. This means that the model relates
the current value of a time series to both:

 Past values of the same series; and


 Current and past values of the driving (exogenous) series — that is, of the externally
determined series that influences the series of interest.

y(t) = f(y(t – 1), ..., y(t – d), x(t – 1), ..., (t – d)

Training Function: Bayesian Regularization Backpropogation- It is based on the probabilistic


interpretation of network parameters, i.e. it involves a probability distribution of network
weights.

METHODOLOGY

For training, validation and testing, the method uses a Neural Network as shown below:-

Fig.4: Open Loop NARX Neural Network

 Number of Hidden Layers=10


 Number of Feedback Delays=3
 Number of Input Delays=3
 Performance: Mean Square Error
 Training values: Validation Values: Testing Values= 8000:30:37
Fig5: Training Window for the Network

For making predictions, the Neural Network used is as follows:-

Fig7: Closed Loop NARX Model

The network is closed, i.e. now the future values of the input series and predicted values of the
training series are used. A loop instruction is used to predict up to whichever date required. A
smoothing function is used to filter out unwanted values.

Validating the training: Figure 8 displays the error autocorrelation function. It describes how the
prediction errors are related in time. For a perfect prediction model, there should only be one
nonzero value of the autocorrelation function, and it should occur at zero lag. (This is the mean
square error.) This would mean that the prediction errors were completely uncorrelated with each
other (white noise). If even more accurate results were required, the network should be retrained.
This will change the initial weights and biases of the network, and may produce an improved
network after retraining.
Fig8: Error Autocorrelation Plot

CODING
MATLAB has been used for coding this network. This is because it is convenient to handle and
train NARX networks in MATLAB for time series prediction. Also, the results were appreciably
accurate and training process wasn’t too slow. The code uses simple ‘narxnet’ command to
create the neural network and ‘preparets’ command (prepare input and target time series data for
network simulation or training) to train it. The network loop is closed using ‘closeloop’
command. The predictions are made iteratively by updating the training series by adding the
newly predicted value. The training is not done using closed loop as using predicted instead of
actual values causes more error. The codes import the dataset values stored as a separate .mat
file. The codes used for preprocessing and predicting are appended at the end.

RESULTS
The result is displayed in the form of a currency exchange rate vs date for weekdays plot until
the date desired. The Mean square errors were found to be:-
Training-15.264
Validation-0.147
Testing-2.798
The data cursor can be used to check predicted values on any date in the prediction range. The
model has been trained for a period of thirty years, so it works best for predictions for not more
than ten years. A sample USD vs INRprediction result is as shown below:-
Fig9: Sample USD vs INR Prediction
CONCLUSION
The predictions made are smooth and more or less match predictions made by other methods.
However, there is still scope to enhance the productivity of this model. The model can be refined
to incorporate features such as Hourly prediction, Prediction Using Non-Quantifiable Parameters
as well, faster and more convenient importing of datasets. Removal of Interdependence of
Parameters. This model still works well considering no major impactful economic event happens
in the future and can be used with a high degree of reliability to predict currency exchange rates
for five days a week up until a period of almost 10 years from today.

REFERENCES

[1] Adewole Adetunji Philip Akinwale Adio Taofiki and Akintomide Ayo Bidemi,” Artificial
Neural Network Model for Forecasting
Foreign Exchange Rate”,World of Computer Science and Information Technology Journal
(WCSIT)”, Vol. 1, No. 3,pp.110-118, 2011.
[2] Athanasios Sfetsos and Costas Siriopoulos, “Time Series Forecasting of Averaged Data With
Efficient Use of Information”, IEEE
Ansactions on Systems, Man, and Cybernetics-Part A: Systems and Humans, vol. 35, NO. 5, pp.
738-745, September 2005.
[3] Carney, John G. and Cunningham Padraig ,“Neural Networks and Currency Exchange Rate
Prediction,” Trinity College Working
Paper Foresight Business Journal, http://www.maths.tcd.ie/pub/fbj/forex4.html.
[4] F. X. Diebold and J. A. Nason, “Nonparametric exchange rate pediction?,” J. Int. Econom.,
vol. 28, pp. 315–332, 1990.
[5] T. H. Hann and E. Steurer, “Much ado about nothing? Exchange rate forecasting: Neural
networks vs. Linear models using monthly
and weekly data,” Neurocomputing, vol. 10, pp. 323–339, 1996.
[6] Jingtao Yao and Chew Lim Tan ,“A Case Study on Using Neural Networks to Perform
Technical Forecasting of FOREX,”
Neurocomputing 34:pp.79-98,2000.
[7] Joarder Kamruzzaman and Ruhul A. Sarker,” ANN-Based Forecasting of Foreign Currency
Exchange Rates”, Neural Information
Processing - Letters and Reviews Vol. 3, No. 2,pp49-58, May 2004

[8] M. Kuan and T. Liu, “Forecasting exchange rates using feedforward and recurrent neural
networks,” J. Appl. Econometrics, vol. 10,
pp. 347–364, 1995.
[9] Lavanya, M. Parveentaj,” Foreign Currency Exchange Rate (FOREX) using Neural
Network”, International Journal of Science and
Research, Volume 2 Issue 10, pp.174-177,October 2013.
[10] PremChand Kumar and Ekta Walia,” Cash Forecasting: An Application of Artificial Neural
Networks in Finance”, International
Journal of Computer Science & Applications,Vol. III, No. I, pp. 61 – 77, 2006.
APPENDIX: CODES

Code for Preprocessing

%for this code to work, the setup.m code given in the drive link must first
be run
net=newlin([1 -1;-1 1;-1 1;-1 1;-1 1;-1 1],1,0,0.00000001);
net.IW{1,1}=[0.01 0.2 1 3 0.01 0.15 ];
b=[0.1 0.5 1 3 0.01 0.3 ];
net.b{1}=0;
%P={[1
% 2
% 3],[2;1;4],[2;3;5],[3;1;7],[4;4;9]};

P={a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21
a22 a23 a24 a25 a26 a27 a28 a29 a30};

%[t1,t2]=size(input);
%T={7 9 12 14 21};
T={13.92 16.23 17.5 22.74 25.92 30.49 31.37 32.43 35.43
36.31 41.26 43.06 44.94 47.19 48.61 46.58 45.32 44.1 45.31
41.35 43.51 48.41 45.73 46.67 53.44 56.57 62.33 62.97 66.46
67.79
};
%[t1,t2]=size(tar);
%Target=mat2cell(tar,t1,ones(1,t2));
%T=Target;
for i=1:1000
[net,a,e,pf,tr]=adapt(net,P,T);
end

Code for Prediction


%Converting matrix to cell
%price defined as matrix of dollar prices
import price
lp=length(price)
for i=1:lp
tar(i)=price(lp+1-i);
end
r=inputseries(1:8067)';
T=tar;
[t1,t2]=size(tar);
Target=mat2cell(tar,t1,ones(1,t2));
T=Target;
[t1,t2]=size(r);
Input=mat2cell(r,t1,ones(1,t2));
X=Input;
% Creating Open Loop Network
trainFcn='trainbr';
feedbackdelays=1:20;
hiddenLayerSize=10;
inputDelays =1:20;
net=narxnet(inputDelays,feedbackdelays,hiddenLayerSize,'open',trainFcn);
[x,xi,ai,t]=preparets(net,X,{},T);
net.divideFcn='divideind';
net.divideMode='time';
net.divideParam.trainInd=1:8000;
net.divideParam.valInd=8001:8030;
net.divideParam.testInd=8031:8067;
net.performFcn='mse';
[net,tr]=train(net,x,t,xi,ai);
y=net(x,xi,ai);
% Calculating Performance
trainTargets=gmultiply(t,tr.trainMask);
valTargets=gmultiply(t,tr.valMask);
testTargets=gmultiply(t,tr.testMask);
trainPerformance=perform(net,trainTargets,y)
valPerformance=perform(net,valTargets,y)
testPerformance=perform(net,testTargets,y)
%Closing the Network
view(net)
netc=closeloop(net);
netc.name=[net.name '-Closed Loop'];
view(netc)
[xc,xic,aic,tc]=preparets(netc,X,{},T);
yc=netc(xc,xic,aic);
closedLoopPerformance=perform(net,tc,yc)
y2_1=[];
%y22=zeros(1,7);
%Multi Step Prediction
for i=1:p
tar=[tar y2_1];
[t1,t2]=size(tar);
Target=mat2cell(tar,t1,ones(1,t2));
T=Target;
a=inputseries(1:8066+i)';
[t1,t2]=size(a);
Input=mat2cell(a,t1,ones(1,t2));
X=Input;
[x1,xio,aio,t]=preparets(net,X,{},T);
[y1,xfo,afo]=net(x1,xio,aio);
[netc,xic,aic]=closeloop(net,xfo,afo);
[y2,xfc,afc]=netc(cell(0,1),xic,aic);
y1_1=cell2mat(y1);
y2_1=cell2mat(y2);
y22(i)=y2_1;
end
plot(dates(1:8067+p),[tar y2_1],'-k')
hold on
plot(dates(1:8067),tar(1:8067),'-b');

To run the codes the datasets must be imported. The following link contains all these codes and
sample data set for USD vs INR prediction:-
https://drive.google.com/drive/folders/1FXKKnNx2D3ZxlByQChAJFaPN_xUchmo1?usp=shari
ng

You might also like