# importing the libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import matplotlib.style as style
import seaborn as sns
# importing the dataset
exchange_rates = pd.read_csv('euro-daily-hist_1999_2022.csv')
# Knowing the dataset
exchange_rates.head()
exchange_rates.info()
# Changing columns names
exchange_rates.rename(columns = {'[US dollar ]': 'US_dollar', 'Period\\Unit:': 'Time', '[Australian dollar ]': 'AUS_dollar', '[Swiss franc ]': 'Swiss_franc', '[UK pound sterling ]': 'UK_pound'},
inplace = True)
# Changing Time column
exchange_rates['Time'] = pd.to_datetime(exchange_rates['Time'])
exchange_rates.sort_values('Time', inplace = True)
exchange_rates.reset_index(drop = True, inplace = True)
exchange_rates.info()
# Selecting the currencies
euro_to_USdollar=exchange_rates.copy()[["Time", "US_dollar"]]
euro_to_UKpound=exchange_rates.copy()[["Time", "UK_pound"]]
euro_to_AUSdollar=exchange_rates.copy()[["Time", "AUS_dollar"]]
euro_to_SwissF=exchange_rates.copy()[["Time", "Swiss_franc"]]
# Inspecting value_counts
euro_to_USdollar["US_dollar"].value_counts()
# Excluding "-"
euro_to_USdollar=euro_to_USdollar[euro_to_USdollar["US_dollar"]!="-"]
# Transforming into float type
euro_to_USdollar.loc[:,"US_dollar"]=euro_to_USdollar.loc[:,"US_dollar"].astype(float)
euro_to_USdollar.info()
# Inspecting value_counts
euro_to_UKpound["UK_pound"].value_counts()
# Excluding "-"
euro_to_UKpound=euro_to_UKpound[euro_to_UKpound["UK_pound"]!="-"]
# Transforming into float type
euro_to_UKpound.loc[:,"UK_pound"]=euro_to_UKpound.loc[:,"UK_pound"].astype(float)
euro_to_UKpound.info()
# Inspecting value_counts
euro_to_AUSdollar["AUS_dollar"].value_counts()
# Excluding "-"
euro_to_AUSdollar=euro_to_AUSdollar[euro_to_AUSdollar["AUS_dollar"]!="-"]
# Transforming into float type
euro_to_AUSdollar.loc[:,"AUS_dollar"]=euro_to_AUSdollar.loc[:,"AUS_dollar"].astype(float)
euro_to_AUSdollar.info()
# Inspecting value_counts
euro_to_SwissF["Swiss_franc"].value_counts()
# Excluding "-"
euro_to_SwissF=euro_to_SwissF[euro_to_SwissF["Swiss_franc"]!="-"]
# Transforming into float type
euro_to_SwissF.loc[:,"Swiss_franc"]=euro_to_SwissF.loc[:,"Swiss_franc"].astype(float)
euro_to_SwissF.info()
# Minimum value
euro_to_USdollar[euro_to_USdollar['US_dollar'] == euro_to_USdollar['US_dollar'].min()]
# Maximum value
euro_to_USdollar[euro_to_USdollar['US_dollar'] == euro_to_USdollar['US_dollar'].max()]
# Mean
euro_to_USdollar['US_dollar'].mean()
# Using rolling mean (moving average) to smooth the graph line
euro_to_USdollar['rolling_mean'] = euro_to_USdollar['US_dollar'].rolling(30).mean()
# Graph of the whole period
plt.plot(euro_to_USdollar['Time'], euro_to_USdollar['rolling_mean'])
plt.axhline(y=euro_to_USdollar['US_dollar'].mean(), color='red')
plt.show()
# Slicing the 2019-2022 period
euro_to_USdollar_19=euro_to_USdollar.copy()[euro_to_USdollar['Time'].dt.year >= 2019]
# Minimum value
euro_to_USdollar_19[euro_to_USdollar_19['US_dollar'] == euro_to_USdollar_19['US_dollar'].min()]
# Maximum value
euro_to_USdollar_19[euro_to_USdollar_19['US_dollar'] == euro_to_USdollar_19['US_dollar'].max()]
# Graph of the 2019-2022 period
plt.plot(euro_to_USdollar_19['Time'], euro_to_USdollar_19['US_dollar'])
plt.xticks(rotation=30)
plt.show()
# Minimum value
euro_to_UKpound[euro_to_UKpound['UK_pound'] == euro_to_UKpound['UK_pound'].min()]
# Maximum value
euro_to_UKpound[euro_to_UKpound['UK_pound'] == euro_to_UKpound['UK_pound'].max()]
# Mean
euro_to_UKpound['UK_pound'].mean()
# Using rolling mean (moving average) to smooth the graph line
euro_to_UKpound['rolling_mean'] = euro_to_UKpound['UK_pound'].rolling(30).mean()
# Graph of the whole period
plt.plot(euro_to_UKpound['Time'], euro_to_UKpound['rolling_mean'])
plt.axhline(y=euro_to_UKpound['UK_pound'].mean(), color='red')
plt.show()
# Slicing the 2019-2022 period
euro_to_UKpound_19=euro_to_UKpound.copy()[euro_to_UKpound['Time'].dt.year >= 2019]
# Minimum value
euro_to_UKpound_19[euro_to_UKpound_19['UK_pound'] == euro_to_UKpound_19['UK_pound'].min()]
# Maximum value
euro_to_UKpound_19[euro_to_UKpound_19['UK_pound'] == euro_to_UKpound_19['UK_pound'].max()]
# Graph of the 2019-2022 period
plt.plot(euro_to_UKpound_19['Time'], euro_to_UKpound_19['UK_pound'])
plt.xticks(rotation=30)
plt.show()
# Minimum value
euro_to_AUSdollar[euro_to_AUSdollar['AUS_dollar'] == euro_to_AUSdollar['AUS_dollar'].min()]
# Maximum value
euro_to_AUSdollar[euro_to_AUSdollar['AUS_dollar'] == euro_to_AUSdollar['AUS_dollar'].max()]
# Mean
euro_to_AUSdollar['AUS_dollar'].mean()
# Using rolling mean (moving average) to smooth the graph line
euro_to_AUSdollar['rolling_mean'] = euro_to_AUSdollar['AUS_dollar'].rolling(30).mean()
# Graph of the whole period
plt.plot(euro_to_AUSdollar['Time'], euro_to_AUSdollar['rolling_mean'])
plt.axhline(y=euro_to_AUSdollar['AUS_dollar'].mean(), color='red')
plt.show()
# Slicing the 2019-2022 period
euro_to_AUSdollar_19=euro_to_AUSdollar.copy()[euro_to_AUSdollar['Time'].dt.year >= 2019]
# Minimum value
euro_to_AUSdollar_19[euro_to_AUSdollar_19['AUS_dollar'] == euro_to_AUSdollar_19['AUS_dollar'].min()]
# Maximum value
euro_to_AUSdollar_19[euro_to_AUSdollar_19['AUS_dollar'] == euro_to_AUSdollar_19['AUS_dollar'].max()]
# Graph of the 2019-2022 period
plt.plot(euro_to_AUSdollar_19['Time'], euro_to_AUSdollar_19['AUS_dollar'])
plt.xticks(rotation=30)
plt.show()
# Minimum value
euro_to_SwissF[euro_to_SwissF['Swiss_franc'] == euro_to_SwissF['Swiss_franc'].min()]
# Maximum value
euro_to_SwissF[euro_to_SwissF['Swiss_franc'] == euro_to_SwissF['Swiss_franc'].max()]
# Mean
euro_to_SwissF['Swiss_franc'].mean()
# Using rolling mean (moving average) to smooth the graph line
euro_to_SwissF['rolling_mean'] = euro_to_SwissF['Swiss_franc'].rolling(30).mean()
# Graph of the whole period
plt.plot(euro_to_SwissF['Time'], euro_to_SwissF['rolling_mean'])
plt.axhline(y=euro_to_SwissF['Swiss_franc'].mean(), color='red')
plt.show()
# Slicing the 2019-2022 period
euro_to_SwissF_19=euro_to_SwissF.copy()[euro_to_SwissF['Time'].dt.year >= 2019]
# Minimum value
euro_to_SwissF_19[euro_to_SwissF_19['Swiss_franc'] == euro_to_SwissF_19['Swiss_franc'].min()]
# Maximum value
euro_to_SwissF_19[euro_to_SwissF_19['Swiss_franc'] == euro_to_SwissF_19['Swiss_franc'].max()]
# Graph of the 2019-2022 period
plt.plot(euro_to_SwissF_19['Time'], euro_to_SwissF_19['Swiss_franc'])
plt.xticks(rotation=30)
plt.show()
style.use("fivethirtyeight")
#2016-2019:
euro_to_USdollar_16 = euro_to_USdollar.copy()[(euro_to_USdollar['Time'].dt.year >= 2016) & (euro_to_USdollar['Time'].dt.year <= 2019)]
euro_to_UKpound_16 = euro_to_UKpound.copy()[(euro_to_UKpound['Time'].dt.year >= 2016) & (euro_to_UKpound['Time'].dt.year <= 2019)]
euro_to_AUSdollar_16 = euro_to_AUSdollar.copy()[(euro_to_AUSdollar['Time'].dt.year >= 2016) & (euro_to_AUSdollar['Time'].dt.year <= 2019)]
euro_to_SwissF_16 = euro_to_SwissF.copy()[(euro_to_SwissF['Time'].dt.year >= 2016) & (euro_to_SwissF['Time'].dt.year <= 2019)]
#2020-2022:
euro_to_USdollar_20 =euro_to_USdollar.copy()[(euro_to_USdollar['Time'].dt.year >= 2020) & (euro_to_USdollar['Time'].dt.year <= 2022)]
euro_to_UKpound_20 =euro_to_UKpound.copy()[(euro_to_UKpound['Time'].dt.year >= 2020) & (euro_to_UKpound['Time'].dt.year <= 2022)]
euro_to_AUSdollar_20 =euro_to_AUSdollar.copy()[(euro_to_AUSdollar['Time'].dt.year >= 2020) & (euro_to_AUSdollar['Time'].dt.year <= 2022)]
euro_to_SwissF_20 =euro_to_SwissF.copy()[(euro_to_SwissF['Time'].dt.year >= 2020) & (euro_to_SwissF['Time'].dt.year <= 2022)]
#Create the plot area and structure
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(
ncols=2,
nrows=2,
figsize=(18, 9))
ax1.plot(euro_to_USdollar_16['Time'], euro_to_USdollar_16['rolling_mean'],color='lightblue')
ax1.plot(euro_to_USdollar_20['Time'], euro_to_USdollar_20['rolling_mean'],color='green' )
ax1.set_ylim(1, 1.3)
ax1.set_yticks([1.0,1.1, 1.2,1.3])
ax1.set_yticklabels([1.0,1.1, 1.2,1.3])
ax1.tick_params(colors='#948484', which='both', labelsize=12)
ax1.set_xticklabels([])
ax1.yaxis.grid(False)
#ax1.set_yticklabels([])
ax1.axhline(1.1436,c="black", linewidth=2.5, alpha=0.8)
ax1.text(x=16530,y=1.155, s="m*=1.14", size=11)
ax1.annotate('Mar-2020', xy=(18400, 1.08), xytext=(18500, 1),
arrowprops=dict(facecolor='black', shrink=0.05),
)
ax1.title.set_text('Euro/US Dollar')
ax2.plot(euro_to_UKpound_16['Time'], euro_to_UKpound_16['rolling_mean'],color='lightblue')
ax2.plot(euro_to_UKpound_20['Time'], euro_to_UKpound_20['rolling_mean'],color='green' )
ax2.set_ylim(0.7, 1)
ax2.set_yticks([0.7,0.8, 0.9, 1])
ax2.set_yticklabels([0.7,0.8, 0.9, 1])
ax2.tick_params(colors='#948484', which='both', labelsize=12)
ax2.set_xticklabels([])
ax2.yaxis.grid(False)
#ax2.set_yticklabels([])
ax2.axhline(0.8678,c="black", linewidth=2.5, alpha=0.8)
ax2.text(x=16530,y=0.875, s="m*=0.86", size=11)
ax2.annotate('Mar-2020', xy=(18400, 0.91), xytext=(18500, 1),
arrowprops=dict(facecolor='black', shrink=0.05),
)
ax2.title.set_text('Euro/UK Pound')
ax3.plot(euro_to_AUSdollar_16['Time'], euro_to_AUSdollar_16['rolling_mean'],color='lightblue')
ax3.plot(euro_to_AUSdollar_20['Time'], euro_to_AUSdollar_20['rolling_mean'],color='green' )
ax3.set_ylim(1.3, 1.9)
ax3.set_yticks([1.3, 1.5, 1.7, 1.9])
ax3.set_yticklabels([1.3, 1.5, 1.7, 1.9])
ax3.tick_params(colors='#948484', which='both', labelsize=12)
ax3.yaxis.grid(False)
#ax3.set_yticklabels([])
ax3.axhline(1.5637,c="black", linewidth=2.5, alpha=0.8)
ax3.text(x=16530,y=1.58, s="m*=1.56", size=11)
ax3.annotate('Mar-2020', xy=(18360, 1.77), xytext=(18500, 1.86),
arrowprops=dict(facecolor='black', shrink=0.05),
)
ax3.title.set_text('Euro/AUS Dollar')
ax4.plot(euro_to_SwissF_16['Time'], euro_to_SwissF_16['rolling_mean'],color='lightblue')
ax4.plot(euro_to_SwissF_20['Time'], euro_to_SwissF_20['rolling_mean'],color='green' )
ax4.set_ylim(1, 1.2)
ax4.set_yticks([1, 1.1, 1.15, 1.2])
ax4.set_yticklabels([1, 1.1, 1.15, 1.2])
ax4.tick_params(colors='#948484', which='both', labelsize=12)
ax4.yaxis.grid(False)
#ax4.set_yticklabels([])
ax4.axhline(1.1,c="black", linewidth=2.5, alpha=0.8)
ax4.text(x=16530,y=1.11, s="m*=1.1", size=11)
ax4.annotate('Mar-2020', xy=(18400, 1.05), xytext=(18500, 1),
arrowprops=dict(facecolor='black', shrink=0.05),
)
ax4.title.set_text('Euro/Swiss Franc')
#Title and subtitle:
fig.text(x=0.18,y=1.08,s="Despite COVID-19 pandemic, euro remains broadly stable",size=25, weight="bold")
fig.text(x=0.15,y=1.03,s="Comparing the exchange rates of four strong currencies, there wasn't big variations",size=21)
fig.text(x=0.28,y=0.98, s="(less than 0.3) since the first cases (March, 2020)",size=21)
#r description
fig.text(x=0.05,y=0, s="*m means the mean for the period (2016-2022)", size=13)
#Foot signature/source of graph:
fig.text(x=0.05, y=-0.03,s='©Ana Luiza Miranda' +' '*78 +"Source: European Central Bank", backgroundcolor="#4d4d4d", size=13,color="#f0f0f0")
euro_to_USdollar_g = euro_to_USdollar.copy()[(euro_to_USdollar['Time'].dt.year >= 2016) & (euro_to_USdollar['Time'].dt.year <= 2022)]
euro_to_USdollar_g['US_dollar'].mean()
euro_to_UKpound_g = euro_to_UKpound.copy()[(euro_to_UKpound['Time'].dt.year >= 2016) & (euro_to_UKpound['Time'].dt.year <= 2022)]
euro_to_UKpound_g['UK_pound'].mean()
euro_to_AUSdollar_g = euro_to_AUSdollar.copy()[(euro_to_AUSdollar['Time'].dt.year >= 2016) & (euro_to_AUSdollar['Time'].dt.year <= 2022)]
euro_to_AUSdollar_g['AUS_dollar'].mean()
euro_to_SwissF_g = euro_to_SwissF.copy()[(euro_to_SwissF['Time'].dt.year >= 2016) & (euro_to_SwissF['Time'].dt.year <= 2022)]
euro_to_SwissF_g['Swiss_franc'].mean()