MITB Banner

Applying Time Series Analysis On Forex Historical Dataset

the time series analysis trends over the Forex historical dataset pair EUR/USD for visualising market scenario over the past 30 years depending on various attributes such as opening price, closing price, lowest price, highest price and volume.
Share

Forex or the foreign exchange market is a decentralised system for foreign currency trading and exchange. Foreign exchange is the process of changing one country’s currency into another country’s currency for trading, commerce, or tourism. The rise to the foreign exchange services and trading was due to the varying values of individual currencies. In the world trade market Forex is regarded as the largest and most liquid asset market. National currencies have an exchange rate fixed in pairs, e.g. USD/JPY. Commercial and investment banks carry out most of the trading process on behalf of their clients. 

Currency trading is completely conducted electronically over computer networks between institutions, banks, brokers, and individual traders (mostly trading through brokers or banks) around the globe, that is known as over-the-counter (OTC). The market is open 24 hours a day and five trading days a week. Currencies are traded in the major financial centres of London(U.K), New York(U.S), Tokyo(Japan), Zurich(Switzerland), Frankfurt(Germany), Hong Kong(China), Singapore, Paris(France) and Sydney(Australia)—across almost every time zone. This means that when the trading day ends in the U.S., it begins in Singapore and Hong Kong. The forex market is almost active the entire day, with price quotes rapidly changing.

Time Series Analysis 

AI now rules the world with use cases in almost all business sectors. Finance is one such widespread area where time series is used for analytics and prediction. Exchange Rate is one of the daily economic topics that is observed by everyone. We will be analyzing the exchange rate pattern over a time span to be able to forecast it in the future.

The dataset used for demonstration is the Forex pair EUR/USD dataset which holds the record from 1971 to 2019. Dataset link.

# importing libraries

 import pandas as pd
 import numpy as np
 import seaborn as sns
 import matplotlib.pyplot as plt 

# dataset exploration setting date as index

 df = pd.read_csv('../input/eurusd-daily/eu.csv', index_col=0, parse_dates=True, skipinitialspace=True)
 df.drop('date', axis='columns', inplace=True)
 df.head() 

df.tail()

df.shape, df.info()

 <class 'pandas.core.frame.DataFrame'>
 DatetimeIndex: 12115 entries, 1971-01-04 to 2019-05-09
 Data columns (total five columns):
  #   Column  Non-Null Count  Dtype  
 ---  ------  --------------  -----  
  0   open    12115 non-null  float64
  1   high    12115 non-null  float64
  2   low     12115 non-null  float64
  3   close   12115 non-null  float64
  4   volume  12115 non-null  int64  
 dtypes: float64(4), int64(1)
 memory usage: 567.9 KB
 ((12115,5), None) 

# checking null values 

df.isna().sum()

 open      0
 high      0
 low       0
 close     0
 volume    0
 dtype: int64 

# statistical analysis

df.describe()

Market Trends

# data visualisation

# visualizing trend for closing price 

 plt.figure(figsize=(15,6))
 plt.plot(df.close)
 plt.title('Euro vs USD')
 plt.legend()
 plt.show() 

# visualizing trend for volume

 plt.figure(figsize=(15,6))
 plt.plot(df.volume)
 plt.title('Euro vs USD')
 plt.legend()
 plt.show() 

#boxplot

df.drop('volume', axis=1).boxplot()

#generating heatmap

sns.heatmap(df.corr())

# Resampling yearly analysis on volume

df.resample('Y').mean().plot.bar(y=['volume'], figsize=[25,10])

# Resampling yearly analysis on closing price

df.resample('Y').mean().plot.bar(y=['close'], figsize=[25,10])

# lag plot comparing before and after values on volume

 from pandas.plotting import lag_plot
 lag_plot(df['volume'].tail(500)) 

# lag plot comparing before and after values on closing price

 from pandas.plotting import lag_plot
 lag_plot(df['close'].tail(500)) 

Complete notebook link is here.

Conclusion

In this article, we have successfully implemented the time series analysis trends over the Forex historical dataset pair EUR/USD for visualising market scenario over the past 30 years depending on various attributes such as opening price, closing price, lowest price, highest price and volume.

PS: The story was written using a keyboard.
Share
Picture of Jayita Bhattacharyya

Jayita Bhattacharyya

Machine learning and data science enthusiast. Eager to learn new technology advances. A self-taught techie who loves to do cool stuff using technology for fun and worthwhile.
Related Posts

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Generative AI Skilling for Enterprises

Our customized corporate training program on Generative AI provides a unique opportunity to empower, retain, and advance your talent.

Upcoming Large format Conference

May 30 and 31, 2024 | 📍 Bangalore, India

Download the easiest way to
stay informed

Subscribe to The Belamy: Our Weekly Newsletter

Biggest AI stories, delivered to your inbox every week.

AI Courses & Careers

Become a Certified Generative AI Engineer

AI Forum for India

Our Discord Community for AI Ecosystem, In collaboration with NVIDIA. 

Flagship Events

Rising 2024 | DE&I in Tech Summit

April 4 and 5, 2024 | 📍 Hilton Convention Center, Manyata Tech Park, Bangalore

MachineCon GCC Summit 2024

June 28 2024 | 📍Bangalore, India

MachineCon USA 2024

26 July 2024 | 583 Park Avenue, New York

Cypher India 2024

September 25-27, 2024 | 📍Bangalore, India

Cypher USA 2024

Nov 21-22 2024 | 📍Santa Clara Convention Center, California, USA

Data Engineering Summit 2024

May 30 and 31, 2024 | 📍 Bangalore, India