Currency Exchange Rate Prediction with Machine Learning

Currency exchange is one of the biggest financial markets. Currently, 1 United States dollar is equivalent to 73.02 Indian rupees. Many factors affect exchange rates such as economic, political and even psychological factors. The prediction of the currency exchange rate is a difficult problem, so in this article, I will walk you through the task of the currency exchange rate prediction with Machine Learning using Python.

Currency Exchange Rate Prediction

Predicting the currency exchange rates is the regression problem in machine learning. There are changes in exchange rates every day that affect the income of a person, a business and can even affect the economy of a country. Thus, predicting the currency exchange rates can help an individual as well as a country in many ways.

There are so many machine learning algorithms that we can use to predict future currency exchange rates. You can also use artificial neural networks for this task. In the section below, I will take you through the task of currency exchange rate prediction with machine learning using Python.

Currency Exchange Rate Prediction using Python

To predict the currency exchange rate with machine learning, we first need to get the most appropriate data for this task. To get a dataset for this task just follow the steps mentioned below:

  1. Visit Yahoo Finance
  2. Search for “USD/INR(INR=x)”
  3. Click on “Historical Data”
  4. Click on “Download”

By following the steps mentioned above, you will be able to download the historical data of currency exchange rates of Indian Rupees. After clicking on download you will receive a CSV file in your downloads folder.

Now let’s import the necessary Python libraries that we need for this task and read the dataset:

         Date       Open       High        Low      Close  Adj Close  Volume
0  2020-05-22  75.625000  76.209503  75.610001  75.625000  75.625000       0
1  2020-05-25  75.985001  76.129501  75.757500  75.985001  75.985001       0
2  2020-05-26  75.873596  76.110001  75.404999  76.110001  76.110001       0
3  2020-05-27  75.489502  76.000000  75.381302  75.820000  75.820000       0
4  2020-05-28  75.885696  76.129997  75.634499  76.129997  76.129997       0

In this dataset, the values in the “Close” column are the target values that we need to predict. So let’s take a closer look at these values:

Now let’s have a look at the correlation between the features before training the currency exchange rate prediction model:

               Open      High       Low     Close  Adj Close  Volume
Open       1.000000  0.984518  0.983143  0.994720   0.994720     NaN
High       0.984518  1.000000  0.981582  0.984599   0.984599     NaN
Low        0.983143  0.981582  1.000000  0.985281   0.985281     NaN
Close      0.994720  0.984599  0.985281  1.000000   1.000000     NaN
Adj Close  0.994720  0.984599  0.985281  1.000000   1.000000     NaN
Volume          NaN       NaN       NaN       NaN        NaN     NaN

Now the next step is to prepare the dataset by storing the most relevant features in the variable x and storing the target column in the variable y:

Now let’s split the dataset and train a currency exchange prediction model using the Decision Tree Regression model using Python:

Now let’s have a look at the predicted values of currency exchange rates of Indian Rupees for the next 5 days:

   Predicted Rate
0       74.820000
1       74.019997
2       73.089203
3       73.374802
4       73.133400

Summary

Predicting the currency exchange rates is the regression problem in machine learning. In this article, I used the Decision Tree Regression algorithm to predict the currency exchange rates. You can use other regression algorithms and even artificial neural networks for this task. I hope you liked this article on currency exchange rate prediction with machine learning using Python. Feel free to ask your valuable questions in the comments section below.

Default image
Aman Kharwal
Coder with the ♥️ of a Writer || Data Scientist | Solopreneur | Founder
Articles: 1102

Leave a Reply