The currency exchange market has been around since coins were first used. At the end of the 1800s the development of the gold standard fixed currency values to a certain amount of gold, allowing for an internationally stable monetary system (1). Eventually the amount of gold was not enough to keep up with the demand for currency. After World War II the Bretton Woods Accord set the US Dollar as the global fixed currency. This was an adjustable rate, but still determined by central banks and state actors (2). The US dollar was pegged to gold at the time, but during the 1970s the same problem (i.e. amount of gold vs currency in circulation) occurred with the dollar. In August of 1971 President Richard Nixon unilaterally canceled direct international convertibility of the US dollar to gold, inadvertently beginning a regime of free-floating currencies (3).
The modern foreign exchange market (Forex, FX, or currency market) is a direct broker to dealer global marketplace that determines the market value and exchange rate of currencies all over the world. It is open 24 hours a day, 5 days a week. Currencies are always traded in pairs, and the value expressed is of one currency relative to another. For example, at the end of the day on 11/19/21 the Euro to US dollar rate was 1.13, or $1.13 equals €1. All of the twenty most traded currencies are free-floating, their value is determined by political conditions, economic factors and market psychology.
Forex is by far the largest financial market in the world, in 2019 having a daily volume of over $6.6 trillion (4). The Euro to US dollar (EURUSD) is the most traded currency pair, taking about 30% of the multi-billion dollar Forex turnover (5).
This study examines the volatility of the value of the Euro to eight other currencies. It uses the 2019 Triennial Central Bank Survey by the Bank for International Settlements to determine four currencies that represent large portions of the market and four currencies that represent small portions of the market. The highly traded currencies are the US dollar, Japanese yen, UK pound, and Australian dollar. The Israeli shekel, Phillipine peso, Malaysian ringgit, and Romanian leu comprise the group of least traded currencies.
The data set used is based on daily closing values provided by the European Central Bank and compiled by Daria Chemkaeva. It is updated weekly, the version used for this study was downloaded from Kaggle in November 2021.
Text with conclusion.
The first steps are to import the basic libraries, open the file, and take an initial look at the dataset.
# import libraries and set display options
import pandas as pd
import pprint
pd.options.display.float_format = '{:20,.4f}'.format
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 3000)
pd.set_option('display.colheader_justify', 'center')
pd.set_option('display.precision', 3)
# import json
# s = json.load( open("bmh_matplotlibrc.json") ) #edit path to json file
# matplotlib.rcParams.update(s)
# open file
x_rates = pd.read_csv("euro-daily-hist_1999_2020.csv")
# head, tail, and basic info
display(x_rates.head())
display(x_rates.tail())
display(x_rates.info())
Period\Unit: | [Australian dollar ] | [Bulgarian lev ] | [Brazilian real ] | [Canadian dollar ] | [Swiss franc ] | [Chinese yuan renminbi ] | [Cypriot pound ] | [Czech koruna ] | [Danish krone ] | [Estonian kroon ] | [UK pound sterling ] | [Greek drachma ] | [Hong Kong dollar ] | [Croatian kuna ] | [Hungarian forint ] | [Indonesian rupiah ] | [Israeli shekel ] | [Indian rupee ] | [Iceland krona ] | [Japanese yen ] | [Korean won ] | [Lithuanian litas ] | [Latvian lats ] | [Maltese lira ] | [Mexican peso ] | [Malaysian ringgit ] | [Norwegian krone ] | [New Zealand dollar ] | [Philippine peso ] | [Polish zloty ] | [Romanian leu ] | [Russian rouble ] | [Swedish krona ] | [Singapore dollar ] | [Slovenian tolar ] | [Slovak koruna ] | [Thai baht ] | [Turkish lira ] | [US dollar ] | [South African rand ] | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2021-01-08 | 1.5758 | 1.9558 | 6.5748 | 1.5543 | 1.0827 | 7.9184 | NaN | 26.163 | 7.4369 | NaN | 0.90128 | NaN | 9.4982 | 7.5690 | 359.62 | 17247.33 | 3.8981 | 89.7975 | 155.5000 | 127.26 | 1337.90 | NaN | NaN | NaN | 24.4718 | 4.9359 | 10.2863 | 1.6883 | 58.947 | 4.5113 | 4.8708 | 90.8000 | 10.0510 | 1.6228 | NaN | NaN | 36.8480 | 9.0146 | 1.2250 | 18.7212 |
1 | 2021-01-07 | 1.5836 | 1.9558 | 6.5172 | 1.5601 | 1.0833 | 7.9392 | NaN | 26.147 | 7.4392 | NaN | 0.90190 | NaN | 9.5176 | 7.5660 | 357.79 | 17259.99 | 3.9027 | 90.0455 | 155.3000 | 127.13 | 1342.29 | NaN | NaN | NaN | 24.2552 | 4.9570 | 10.3435 | 1.6907 | 59.043 | 4.4998 | 4.8712 | 91.2000 | 10.0575 | 1.6253 | NaN | NaN | 36.8590 | 8.9987 | 1.2276 | 18.7919 |
2 | 2021-01-06 | 1.5824 | 1.9558 | 6.5119 | 1.5640 | 1.0821 | 7.9653 | NaN | 26.145 | 7.4393 | NaN | 0.90635 | NaN | 9.5659 | 7.5595 | 357.86 | 17168.20 | 3.9289 | 90.2040 | 156.3000 | 127.03 | 1339.30 | NaN | NaN | NaN | 24.3543 | 4.9482 | 10.3810 | 1.6916 | 59.296 | 4.5160 | 4.8720 | 90.8175 | 10.0653 | 1.6246 | NaN | NaN | 36.9210 | 9.0554 | 1.2338 | 18.5123 |
3 | 2021-01-05 | 1.5927 | 1.9558 | 6.5517 | 1.5651 | 1.0803 | 7.9315 | NaN | 26.227 | 7.4387 | NaN | 0.90333 | NaN | 9.5136 | 7.5588 | 360.27 | 17075.10 | 3.9277 | 89.8670 | 156.1000 | 126.25 | 1335.85 | NaN | NaN | NaN | 24.5860 | 4.9293 | 10.4713 | 1.7036 | 59.020 | 4.5473 | 4.8721 | 91.6715 | 10.0570 | 1.6180 | NaN | NaN | 36.7760 | 9.0694 | 1.2271 | 18.4194 |
4 | 2021-01-04 | 1.5928 | 1.9558 | 6.3241 | 1.5621 | 1.0811 | 7.9484 | NaN | 26.141 | 7.4379 | NaN | 0.90160 | NaN | 9.5330 | 7.5565 | 361.32 | 17062.67 | 3.9430 | 89.7890 | 156.1000 | 126.62 | 1332.03 | NaN | NaN | NaN | 24.3031 | 4.9264 | 10.4440 | 1.7065 | 59.058 | 4.5475 | 4.8713 | 90.3420 | 10.0895 | 1.6198 | NaN | NaN | 36.7280 | 9.0579 | 1.2296 | 17.9214 |
Period\Unit: | [Australian dollar ] | [Bulgarian lev ] | [Brazilian real ] | [Canadian dollar ] | [Swiss franc ] | [Chinese yuan renminbi ] | [Cypriot pound ] | [Czech koruna ] | [Danish krone ] | [Estonian kroon ] | [UK pound sterling ] | [Greek drachma ] | [Hong Kong dollar ] | [Croatian kuna ] | [Hungarian forint ] | [Indonesian rupiah ] | [Israeli shekel ] | [Indian rupee ] | [Iceland krona ] | [Japanese yen ] | [Korean won ] | [Lithuanian litas ] | [Latvian lats ] | [Maltese lira ] | [Mexican peso ] | [Malaysian ringgit ] | [Norwegian krone ] | [New Zealand dollar ] | [Philippine peso ] | [Polish zloty ] | [Romanian leu ] | [Russian rouble ] | [Swedish krona ] | [Singapore dollar ] | [Slovenian tolar ] | [Slovak koruna ] | [Thai baht ] | [Turkish lira ] | [US dollar ] | [South African rand ] | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5694 | 1999-01-08 | 1.8406 | NaN | NaN | 1.7643 | 1.6138 | NaN | 0.58187 | 34.938 | 7.4433 | 15.6466 | 0.70940 | 324.00 | 9.0302 | NaN | 250.15 | 9321.63 | NaN | NaN | 80.9900 | 130.09 | 1366.73 | 4.66430 | 0.6654 | 0.4419 | 11.4414 | 4.4295 | 8.5900 | 2.1557 | 44.295 | 4.0363 | 1.3143 | 27.2075 | 9.1650 | 1.9537 | 188.8400 | 42.560 | 42.5590 | 0.3718 | 1.1659 | 6.7855 |
5695 | 1999-01-07 | 1.8474 | NaN | NaN | 1.7602 | 1.6165 | NaN | 0.58187 | 34.886 | 7.4431 | 15.6466 | 0.70585 | 324.40 | 9.0131 | NaN | 250.09 | 9218.77 | NaN | NaN | 81.0600 | 129.43 | 1337.16 | 4.65480 | 0.6627 | 0.4413 | 11.5511 | 4.4203 | 8.6295 | 2.1531 | 44.436 | 4.0165 | 1.3092 | 26.9876 | 9.1800 | 1.9436 | 188.8000 | 42.765 | 42.1678 | 0.3701 | 1.1632 | 6.8283 |
5696 | 1999-01-06 | 1.8820 | NaN | NaN | 1.7711 | 1.6116 | NaN | 0.58200 | 34.850 | 7.4452 | 15.6466 | 0.70760 | 324.72 | 9.1010 | NaN | 250.67 | 9337.68 | NaN | NaN | 81.5400 | 131.42 | 1359.54 | 4.69940 | 0.6649 | 0.4420 | 11.4705 | 4.4637 | 8.7335 | 2.1890 | 44.872 | 4.0065 | 1.3168 | 27.4315 | 9.3050 | 1.9699 | 188.7000 | 42.778 | 42.6949 | 0.3722 | 1.1743 | 6.7307 |
5697 | 1999-01-05 | 1.8944 | NaN | NaN | 1.7965 | 1.6123 | NaN | 0.58230 | 34.917 | 7.4495 | 15.6466 | 0.71220 | 324.70 | 9.1341 | NaN | 250.80 | 9314.51 | NaN | NaN | 81.5300 | 130.96 | 1373.01 | 4.71740 | 0.6657 | 0.4432 | 11.5960 | 4.4805 | 8.7745 | 2.2011 | 44.745 | 4.0245 | 1.3168 | 26.5876 | 9.4025 | 1.9655 | 188.7750 | 42.848 | 42.5048 | 0.3728 | 1.1790 | 6.7975 |
5698 | 1999-01-04 | 1.9100 | NaN | NaN | 1.8004 | 1.6168 | NaN | 0.58231 | 35.107 | 7.4501 | 15.6466 | 0.71110 | 327.15 | 9.1332 | NaN | 251.48 | 9433.61 | NaN | NaN | 81.4800 | 133.73 | 1398.59 | 4.71700 | 0.6668 | 0.4432 | 11.6446 | 4.4798 | 8.8550 | 2.2229 | 45.510 | 4.0712 | 1.3111 | 25.2875 | 9.4696 | 1.9554 | 189.0450 | 42.991 | 42.6799 | 0.3723 | 1.1789 | 6.9358 |
<class 'pandas.core.frame.DataFrame'> RangeIndex: 5699 entries, 0 to 5698 Data columns (total 41 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Period\Unit: 5699 non-null object 1 [Australian dollar ] 5699 non-null object 2 [Bulgarian lev ] 5297 non-null object 3 [Brazilian real ] 5431 non-null object 4 [Canadian dollar ] 5699 non-null object 5 [Swiss franc ] 5699 non-null object 6 [Chinese yuan renminbi ] 5431 non-null object 7 [Cypriot pound ] 2346 non-null object 8 [Czech koruna ] 5699 non-null object 9 [Danish krone ] 5699 non-null object 10 [Estonian kroon ] 3130 non-null object 11 [UK pound sterling ] 5699 non-null object 12 [Greek drachma ] 520 non-null object 13 [Hong Kong dollar ] 5699 non-null object 14 [Croatian kuna ] 5431 non-null object 15 [Hungarian forint ] 5699 non-null object 16 [Indonesian rupiah ] 5699 non-null object 17 [Israeli shekel ] 5431 non-null object 18 [Indian rupee ] 5431 non-null object 19 [Iceland krona ] 3292 non-null float64 20 [Japanese yen ] 5699 non-null object 21 [Korean won ] 5699 non-null object 22 [Lithuanian litas ] 4159 non-null object 23 [Latvian lats ] 3904 non-null object 24 [Maltese lira ] 2346 non-null object 25 [Mexican peso ] 5699 non-null object 26 [Malaysian ringgit ] 5699 non-null object 27 [Norwegian krone ] 5699 non-null object 28 [New Zealand dollar ] 5699 non-null object 29 [Philippine peso ] 5699 non-null object 30 [Polish zloty ] 5699 non-null object 31 [Romanian leu ] 5637 non-null float64 32 [Russian rouble ] 5699 non-null object 33 [Swedish krona ] 5699 non-null object 34 [Singapore dollar ] 5699 non-null object 35 [Slovenian tolar ] 2085 non-null object 36 [Slovak koruna ] 2608 non-null object 37 [Thai baht ] 5699 non-null object 38 [Turkish lira ] 5637 non-null float64 39 [US dollar ] 5699 non-null object 40 [South African rand ] 5699 non-null object dtypes: float64(3), object(38) memory usage: 1.8+ MB
None
The dataset covers the time period from January 1999 to January 2021. It has 5699 rows and 41 columns. Some of these columns have less than half the number of entries as other columns. In the original data set, cells with missing entries have a hyphen (-). This causes problems with a lot of the functions that will be used. For the time being the hyphens will be converted to the value NaN
, which preserves the row of information.
The first steps will be:
datetime
data type# strip brackets and trailing space from country names
# replace remaining space with underscore
# lower case all column names
x_rates.columns = x_rates.columns.str.replace("[","").str.replace("]","")
x_rates.columns = x_rates.columns.str.rstrip()
x_rates.columns = x_rates.columns.str.replace(" ","_")
x_rates.columns = x_rates.columns.str.lower()
# rename columns
x_rates.rename(columns={"period\\unit:":"date",
"chinese_yuan_renminbi":"chinese_yuan",
"uk_pound_sterling":"uk_pound"}, inplace=True)
# convert datetime
x_rates["date"] = pd.to_datetime(x_rates["date"])
# resort and reindex
x_rates.sort_values("date", inplace=True)
x_rates.reset_index(drop=True, inplace=True)
# convert hyphens in currency columns to NaN
import numpy as np
x_rates = x_rates.replace("-", np.nan)
# convert exchange rate values to float
x_rates.iloc[:,1:] = x_rates.iloc[:,1:].astype(float)
# set style for cells with centered output
from IPython.core.display import HTML
HTML("""
<style>
.output_png {
display: table-cell; text-align: center; vertical-align: middle}
</style>
""")
display(x_rates.head())
/var/folders/bz/5cj1tzbj5xn319rpqrw6gpmh0000gn/T/ipykernel_12511/2256657528.py:4: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will *not* be treated as literal strings when regex=True. x_rates.columns = x_rates.columns.str.replace("[","").str.replace("]","")
date | australian_dollar | bulgarian_lev | brazilian_real | canadian_dollar | swiss_franc | chinese_yuan | cypriot_pound | czech_koruna | danish_krone | estonian_kroon | uk_pound | greek_drachma | hong_kong_dollar | croatian_kuna | hungarian_forint | indonesian_rupiah | israeli_shekel | indian_rupee | iceland_krona | japanese_yen | korean_won | lithuanian_litas | latvian_lats | maltese_lira | mexican_peso | malaysian_ringgit | norwegian_krone | new_zealand_dollar | philippine_peso | polish_zloty | romanian_leu | russian_rouble | swedish_krona | singapore_dollar | slovenian_tolar | slovak_koruna | thai_baht | turkish_lira | us_dollar | south_african_rand | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1999-01-04 | 1.9100 | NaN | NaN | 1.8004 | 1.6168 | NaN | 0.5823 | 35.1070 | 7.4501 | 15.6466 | 0.7111 | 327.1500 | 9.1332 | NaN | 251.4800 | 9,433.6100 | NaN | NaN | 81.4800 | 133.7300 | 1,398.5900 | 4.7170 | 0.6668 | 0.4432 | 11.6446 | 4.4798 | 8.8550 | 2.2229 | 45.5100 | 4.0712 | 1.3111 | 25.2875 | 9.4696 | 1.9554 | 189.0450 | 42.9910 | 42.6799 | 0.3723 | 1.1789 | 6.9358 |
1 | 1999-01-05 | 1.8944 | NaN | NaN | 1.7965 | 1.6123 | NaN | 0.5823 | 34.9170 | 7.4495 | 15.6466 | 0.7122 | 324.7000 | 9.1341 | NaN | 250.8000 | 9,314.5100 | NaN | NaN | 81.5300 | 130.9600 | 1,373.0100 | 4.7174 | 0.6657 | 0.4432 | 11.5960 | 4.4805 | 8.7745 | 2.2011 | 44.7450 | 4.0245 | 1.3168 | 26.5876 | 9.4025 | 1.9655 | 188.7750 | 42.8480 | 42.5048 | 0.3728 | 1.1790 | 6.7975 |
2 | 1999-01-06 | 1.8820 | NaN | NaN | 1.7711 | 1.6116 | NaN | 0.5820 | 34.8500 | 7.4452 | 15.6466 | 0.7076 | 324.7200 | 9.1010 | NaN | 250.6700 | 9,337.6800 | NaN | NaN | 81.5400 | 131.4200 | 1,359.5400 | 4.6994 | 0.6649 | 0.4420 | 11.4705 | 4.4637 | 8.7335 | 2.1890 | 44.8720 | 4.0065 | 1.3168 | 27.4315 | 9.3050 | 1.9699 | 188.7000 | 42.7780 | 42.6949 | 0.3722 | 1.1743 | 6.7307 |
3 | 1999-01-07 | 1.8474 | NaN | NaN | 1.7602 | 1.6165 | NaN | 0.5819 | 34.8860 | 7.4431 | 15.6466 | 0.7058 | 324.4000 | 9.0131 | NaN | 250.0900 | 9,218.7700 | NaN | NaN | 81.0600 | 129.4300 | 1,337.1600 | 4.6548 | 0.6627 | 0.4413 | 11.5511 | 4.4203 | 8.6295 | 2.1531 | 44.4360 | 4.0165 | 1.3092 | 26.9876 | 9.1800 | 1.9436 | 188.8000 | 42.7650 | 42.1678 | 0.3701 | 1.1632 | 6.8283 |
4 | 1999-01-08 | 1.8406 | NaN | NaN | 1.7643 | 1.6138 | NaN | 0.5819 | 34.9380 | 7.4433 | 15.6466 | 0.7094 | 324.0000 | 9.0302 | NaN | 250.1500 | 9,321.6300 | NaN | NaN | 80.9900 | 130.0900 | 1,366.7300 | 4.6643 | 0.6654 | 0.4419 | 11.4414 | 4.4295 | 8.5900 | 2.1557 | 44.2950 | 4.0363 | 1.3143 | 27.2075 | 9.1650 | 1.9537 | 188.8400 | 42.5600 | 42.5590 | 0.3718 | 1.1659 | 6.7855 |
The change over time in Euro exchange rate can be visualized in a line graph. It and the US dollar are the first currency pair to be examined.
# create a us dollar to euro dataframe and add 30 day rolling mean column
us_dollar = x_rates[["date","us_dollar"]].copy()
us_dollar["rolling_mean_30"] = us_dollar["us_dollar"].rolling(30).mean()
# line graph for dollar to euro exchange rate
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
%matplotlib inline
fig, ax = plt.subplots(figsize=(10,3.75))
ax.plot(us_dollar["date"], us_dollar["rolling_mean_30"])
ax.set(xlabel="Year",
ylabel="US dollar",
title="US Dollar to Euro Exhcange Rates")
ax.set_xticks(["2000-01-04 00:00:00", "2005-01-04 00:00:00", "2010-01-04 00:00:00",
"2015-01-04 00:00:00", "2020-01-04 00:00:00"])
ax.set_xticklabels([2000,2005,2010,2015,2020])
plt.show()
The line graph shows that the exchange rate between the Euro and US dollar is pretty variable. There are also a lot of gaps in the graph. These represent points in the data frame where information for a particular day is missing. This is the most accurate representation of the data, but it's not very easy to look at. A quick visual check can illustrate this overlap and then compare the original data frame with one where the missing dates are removed.
# create nan group and get dates
nan_dollar_group = us_dollar[us_dollar["us_dollar"].isnull()]
nan_days = nan_dollar_group["date"]
# line graph showing dollar to euro showing NaN values with and without highlight
fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(10,7.5))
ax1.plot(us_dollar["date"], us_dollar["rolling_mean_30"])
ax1.set(title="dataset w/ NaN values")
ax2.plot(us_dollar["date"], us_dollar["rolling_mean_30"])
ax2.set(title="dataset w/ corresponding dates in light blue")
for ax in ax1, ax2:
ax.set_xticks(["2000-01-04 00:00:00", "2005-01-04 00:00:00", "2010-01-04 00:00:00",
"2015-01-04 00:00:00", "2020-01-04 00:00:00"])
ax.set_xticklabels([2000,2005,2010,2015,2020])
for xc in nan_days:
plt.axvline(x=xc, color="lightcyan")
fig.suptitle("US dollar to Euro exchange rates", fontsize=20)
fig.tight_layout(pad=3.0)
plt.show()
# create a dollar to euro dataframe with NaN dates removed
US_dollar_nonull = x_rates[x_rates["us_dollar"].notna()].copy()
US_dollar_nonull["rolling_mean_30"] = US_dollar_nonull["us_dollar"].rolling(30).mean()
# line graph showing 30 day rolling mean with and without NaN rows
fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(10,7.5))
ax1.plot(us_dollar["date"], us_dollar["rolling_mean_30"])
ax1.set(title="NaN rows included")
ax2.plot(US_dollar_nonull["date"], US_dollar_nonull["rolling_mean_30"])
ax2.set(title="NaN rows removed")
for ax in ax1, ax2:
ax.set_xticks(["2000-01-04 00:00:00", "2005-01-04 00:00:00", "2010-01-04 00:00:00",
"2015-01-04 00:00:00", "2020-01-04 00:00:00"])
ax.set_xticklabels([2000,2005,2010,2015,2020])
fig.suptitle("US dollar to Euro exchange rates", fontsize=20)
fig.tight_layout(pad=3.0)
plt.show()
The third graph shows vertical blue stripes for all dates with missing information. These correspond perfectly with the gaps in the original chart. The final chart, with these rows removed, appears to be good match and is easier to look at. This also demonstrates how the rolling mean handles NaN values within a data frame. In either case the shape of the line is identical where the information exists, therefor both are similarly accurate representations of the available data. All further currency data frames will be handled the same.
The line graphs represent the exchange rates for the Euro to the US dollar, Japanese yen, UK pound, and Australian dollar. These four currencies, in addition to the Euro, are the top five currencies in the Forex market. All five together comprise over 75% of daily trades (4).
The line graphs represent the exchange rates for the Euro to the Israeli shekel, Philippine peso, Malaysian ringgit, and Romanian leu. These four currencies have low trade volumes, they comprise less than 0.4% of daily trades (4).
# create a list of data frame names
# not sure this is neccessary but trying df = df_list.index(currency) in the framer function doesn't seem to work
# create a list of data frames for each currency with log rate of the exchange rate, 30 day rolling mean, and year
col_names = []
df_dict = {}
for currency in x_rates.columns[1:]:
df_name = currency
col_names.append(df_name)
df = x_rates[["date", currency]].copy()
df = df[df[currency].notna()]
df["log_rate"] = np.log(df.iloc[:,1]/df.iloc[:,1].shift()) # getting the log of the exchange rate # double check this is the correct way to get log
df["rolling_mean_30"] = df[currency].rolling(30).mean()
df["year"] = df["date"].dt.year
df_dict[currency] = df
# list of countries for comparisson
c_list = ["us_dollar", "japanese_yen", "uk_pound", "australian_dollar",
"israeli_shekel", "philippine_peso", "malaysian_ringgit", "romanian_leu"]
# line graph showing Euro to each high frequency trading pairs
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize=(12,8))
fig.tight_layout(pad=3)
for ax, currency in zip((ax1, ax2, ax3, ax4), (df_dict["us_dollar"], df_dict["japanese_yen"], df_dict["uk_pound"], df_dict["australian_dollar"])):
ax.plot(currency["date"], currency["rolling_mean_30"])
for ax in ax1, ax2, ax3, ax4:
ax.set_xticks(["2000-01-04 00:00:00", "2005-01-04 00:00:00", "2010-01-04 00:00:00",
"2015-01-04 00:00:00", "2020-01-04 00:00:00"])
ax.set_xticklabels([2000,2005,2010,2015,2020])
ax.set(yticks=[],
xlabel="Year")
# ax.set_ylabel(str(currency)) # why not, i can get it to change to a string "currency", but not a variable
ax1.set(ylabel="US dollar")
ax2.set(ylabel="Japanese yen")
ax3.set(ylabel="UK pound")
ax4.set(ylabel="Australian dollar")
fig.suptitle("Euro to High Frequency Pairs", fontsize=20)
plt.show()
# line graph showing Euro to each low frequency trading pairs
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize=(12,8))
fig.tight_layout(pad=3)
for ax, currency in zip((ax1, ax2, ax3, ax4), (df_dict["israeli_shekel"], df_dict["philippine_peso"], df_dict["malaysian_ringgit"], df_dict["romanian_leu"])):
ax.plot(currency["date"], currency["rolling_mean_30"])
for ax in ax1, ax2, ax3, ax4:
ax.set_xticks(["2000-01-04 00:00:00", "2005-01-04 00:00:00", "2010-01-04 00:00:00",
"2015-01-04 00:00:00", "2020-01-04 00:00:00"])
ax.set_xticklabels([2000,2005,2010,2015,2020])
ax.set(yticks=[],
xlabel="Year")
# ax.set_ylabel(str(currency)) # why not, i can get it to change to a string "currency", but not a variable
ax1.set(ylabel="Israeli shekel")
ax2.set(ylabel="Philippine peso")
ax3.set(ylabel="Malaysian ringgit")
ax4.set(ylabel="Romanian leu")
fig.suptitle("Euro to Low Frequency Pairs", fontsize=20)
plt.show()
An overlay of all currencies focused on the first decade of the Euro shows it's initial struggle and eventual success.
x_values1 = df_dict["us_dollar"]["date"]
y_values1 = df_dict["us_dollar"]["rolling_mean_30"]
x_values2 = df_dict["japanese_yen"]["date"]
y_values2 = df_dict["japanese_yen"]["rolling_mean_30"]
x_values3 = df_dict["uk_pound"]["date"]
y_values3 = df_dict["uk_pound"]["rolling_mean_30"]
x_values4 = df_dict["australian_dollar"]["date"]
y_values4 = df_dict["australian_dollar"]["rolling_mean_30"]
fig = plt.figure(figsize=(12,8))
ax = fig.add_subplot(111, label = "1")
ax2 = fig.add_subplot(111, label = "2", frame_on = False)
ax3 = fig.add_subplot(111, label = "3", frame_on = False)
ax4 = fig.add_subplot(111, label = "4", frame_on = False)
# for ax in ax, ax2, ax3, ax4:
# ax.xaxis.set_major_locator(years) # format the x ticks
# ax.xaxis.set_major_formatter(years_fmt)
# fmt_three_years = mdates.MonthLocator(interval = 36) # Major ticks every 3 years
# ax.xaxis.set_major_locator(fmt_three_years)
# ax.set(yticks=[],
# xlabel="Year")
ax.plot(x_values1, y_values1, color = "blue")
ax.set_yticks([])
# ax.set_xlabel("x label 1", color = "C0")
# ax.set_ylabel("y label 1", color = "C0")
# ax.tick_params(axis = 'x', colors = "C0")
# ax.tick_params(axis = 'y', colors = "C0")
ax2.plot(x_values2, y_values2, color = "green")
ax2.set_yticks([])
# ax2.xaxis.tick_top()
# ax2.yaxis.tick_right()
# ax2.set_xlabel('x label 2', color = "C1")
# ax2.set_ylabel('y label 2', color = "C1")
# ax2.xaxis.set_label_position('top')
# ax2.yaxis.set_label_position('right')
# ax2.tick_params(axis = 'x', colors = "C1")
# ax2.tick_params(axis = 'y', colors = "C1")
ax3.plot(x_values3, y_values3, color = "yellow")
ax3.set_yticks([])
ax4.plot(x_values4, y_values4, color = "purple")
ax4.set_yticks([])
plt.show()
x_values1 = df_dict["israeli_shekel"]["date"]
y_values1 = df_dict["israeli_shekel"]["rolling_mean_30"]
x_values2 = df_dict["philippine_peso"]["date"]
y_values2 = df_dict["philippine_peso"]["rolling_mean_30"]
x_values3 = df_dict["malaysian_ringgit"]["date"]
y_values3 = df_dict["malaysian_ringgit"]["rolling_mean_30"]
x_values4 = df_dict["romanian_leu"]["date"]
y_values4 = df_dict["romanian_leu"]["rolling_mean_30"]
fig = plt.figure(figsize=(12,8))
ax = fig.add_subplot(111, label = "1")
ax2 = fig.add_subplot(111, label = "2", frame_on = False)
ax3 = fig.add_subplot(111, label = "3", frame_on = False)
ax4 = fig.add_subplot(111, label = "4", frame_on = False)
# for ax in ax, ax2, ax3, ax4:
# ax.xaxis.set_major_locator(years) # format the x ticks
# ax.xaxis.set_major_formatter(years_fmt)
# fmt_three_years = mdates.MonthLocator(interval = 36) # Major ticks every 3 years
# ax.xaxis.set_major_locator(fmt_three_years)
# ax.set(yticks=[],
# xlabel="Year")
ax.plot(x_values1, y_values1, color = "blue")
ax.set_yticks([])
# ax.set_xlabel("x label 1", color = "C0")
# ax.set_ylabel("y label 1", color = "C0")
# ax.tick_params(axis = 'x', colors = "C0")
# ax.tick_params(axis = 'y', colors = "C0")
ax2.plot(x_values2, y_values2, color = "green")
ax2.set_yticks([])
# ax2.xaxis.tick_top()
# ax2.yaxis.tick_right()
# ax2.set_xlabel('x label 2', color = "C1")
# ax2.set_ylabel('y label 2', color = "C1")
# ax2.xaxis.set_label_position('top')
# ax2.yaxis.set_label_position('right')
# ax2.tick_params(axis = 'x', colors = "C1")
# ax2.tick_params(axis = 'y', colors = "C1")
ax3.plot(x_values3, y_values3, color = "yellow")
ax3.set_yticks([])
ax4.plot(x_values4, y_values4, color = "purple")
ax4.set_yticks([])
plt.show()
# function to create df with year and annual volatility for every row
volatility_df_list = []
def volatizer(currency):
annual_df_list = [currency[currency['year'] == y] for y in currency['year'].unique()] # list of annual dfs
c_name = currency.columns[1]
row_dict = {} # dictionary with year:annual_volatility as key:value
for frame in annual_df_list:
year_name = frame.iat[0,4] # first cell of the "year" column, becomes the "year" key for row_dict
annual_volatility = frame["log_rate"].std()*253**.5 # volatility measured by standard deviation * 253 trading days per year raised to the 0.5 power
row_dict[year_name] = annual_volatility # dictionary with year:annual_volatility as key:value
df = pd.DataFrame.from_dict(row_dict, orient="index", columns=[c_name+"_annual_vol"]) # new df from dictionary indexing on year
volatility_df_list.append(df)
# apply volatizer to each currency df
for key in df_dict:
df_dict[key] = volatizer(df_dict[key])
# create an annual volatility data frame with all 40 currencies
annual_volatility = pd.concat(volatility_df_list, axis=1)
display(annual_volatility.head())
annual_volatility["year"] = annual_volatility.index
display(annual_volatility.head())
australian_dollar_annual_vol | bulgarian_lev_annual_vol | brazilian_real_annual_vol | canadian_dollar_annual_vol | swiss_franc_annual_vol | chinese_yuan_annual_vol | cypriot_pound_annual_vol | czech_koruna_annual_vol | danish_krone_annual_vol | estonian_kroon_annual_vol | uk_pound_annual_vol | greek_drachma_annual_vol | hong_kong_dollar_annual_vol | croatian_kuna_annual_vol | hungarian_forint_annual_vol | indonesian_rupiah_annual_vol | israeli_shekel_annual_vol | indian_rupee_annual_vol | iceland_krona_annual_vol | japanese_yen_annual_vol | korean_won_annual_vol | lithuanian_litas_annual_vol | latvian_lats_annual_vol | maltese_lira_annual_vol | mexican_peso_annual_vol | malaysian_ringgit_annual_vol | norwegian_krone_annual_vol | new_zealand_dollar_annual_vol | philippine_peso_annual_vol | polish_zloty_annual_vol | romanian_leu_annual_vol | russian_rouble_annual_vol | swedish_krona_annual_vol | singapore_dollar_annual_vol | slovenian_tolar_annual_vol | slovak_koruna_annual_vol | thai_baht_annual_vol | turkish_lira_annual_vol | us_dollar_annual_vol | south_african_rand_annual_vol | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1999 | 0.1287 | NaN | NaN | 0.1184 | 0.0256 | NaN | 0.0096 | 0.0694 | 0.0020 | 0.0000 | 0.0718 | 0.0245 | 0.0913 | NaN | 0.0513 | 0.3246 | NaN | NaN | 0.0489 | 0.1445 | 0.1130 | 0.0914 | 0.0669 | 0.0784 | 0.2085 | 0.0914 | 0.0569 | 0.1293 | 0.1208 | 0.1142 | 0.2024 | 0.1963 | 0.0556 | 0.0966 | 0.0456 | 0.0569 | 0.1250 | 0.0614 | 0.0924 | 0.1311 |
2000 | 0.1270 | 0.0098 | 0.2621 | 0.1507 | 0.0441 | 0.1376 | 0.0116 | 0.0452 | 0.0032 | 0.0000 | 0.1112 | 0.0066 | 0.1374 | 0.0169 | 0.0159 | 0.2169 | 0.1479 | 0.1448 | 0.0811 | 0.1650 | 0.1640 | 0.1376 | 0.1035 | 0.0640 | 0.1662 | 0.1373 | 0.0533 | 0.1461 | 0.1688 | 0.1251 | 0.1414 | 0.1533 | 0.0618 | 0.1391 | 0.0207 | 0.0471 | 0.1597 | 0.0832 | 0.1376 | 0.1273 |
2001 | 0.1273 | 0.0058 | 0.2217 | 0.1149 | 0.0456 | 0.1115 | 0.0170 | 0.0468 | 0.0030 | 0.0000 | 0.0755 | NaN | 0.1116 | 0.0498 | 0.0784 | 0.2555 | 0.1212 | 0.1124 | 0.1161 | 0.1371 | 0.1467 | 0.1115 | 0.0818 | 0.0426 | 0.1575 | 0.1122 | 0.0522 | 0.1206 | 0.2043 | 0.1275 | 0.1119 | 0.1129 | 0.0752 | 0.1132 | 0.0129 | 0.0347 | 0.1201 | 0.6486 | 0.1115 | 0.2148 |
2002 | 0.0990 | 0.0075 | 0.3007 | 0.1037 | 0.0297 | 0.0962 | 0.0081 | 0.0760 | 0.0023 | 0.0000 | 0.0592 | NaN | 0.0962 | 0.0278 | 0.0508 | 0.1363 | 0.1299 | 0.0961 | 0.0831 | 0.0897 | 0.0982 | 0.0363 | 0.0600 | 0.0335 | 0.1533 | 0.0957 | 0.0499 | 0.1091 | 0.0980 | 0.1016 | 0.0993 | 0.0975 | 0.0677 | 0.0810 | 0.0321 | 0.0504 | 0.0851 | 0.1908 | 0.0962 | 0.1996 |
2003 | 0.0843 | 0.0047 | 0.2003 | 0.0947 | 0.0387 | 0.1031 | 0.0084 | 0.0530 | 0.0024 | 0.0000 | 0.0709 | NaN | 0.1030 | 0.0344 | 0.1017 | 0.1114 | 0.1256 | 0.1010 | 0.0798 | 0.0941 | 0.1110 | 0.0014 | 0.0599 | 0.0316 | 0.1627 | 0.1024 | 0.0680 | 0.0903 | 0.1068 | 0.0934 | 0.0597 | 0.1011 | 0.0509 | 0.0869 | 0.0082 | 0.0412 | 0.0946 | 0.1606 | 0.1031 | 0.1846 |
australian_dollar_annual_vol | bulgarian_lev_annual_vol | brazilian_real_annual_vol | canadian_dollar_annual_vol | swiss_franc_annual_vol | chinese_yuan_annual_vol | cypriot_pound_annual_vol | czech_koruna_annual_vol | danish_krone_annual_vol | estonian_kroon_annual_vol | uk_pound_annual_vol | greek_drachma_annual_vol | hong_kong_dollar_annual_vol | croatian_kuna_annual_vol | hungarian_forint_annual_vol | indonesian_rupiah_annual_vol | israeli_shekel_annual_vol | indian_rupee_annual_vol | iceland_krona_annual_vol | japanese_yen_annual_vol | korean_won_annual_vol | lithuanian_litas_annual_vol | latvian_lats_annual_vol | maltese_lira_annual_vol | mexican_peso_annual_vol | malaysian_ringgit_annual_vol | norwegian_krone_annual_vol | new_zealand_dollar_annual_vol | philippine_peso_annual_vol | polish_zloty_annual_vol | romanian_leu_annual_vol | russian_rouble_annual_vol | swedish_krona_annual_vol | singapore_dollar_annual_vol | slovenian_tolar_annual_vol | slovak_koruna_annual_vol | thai_baht_annual_vol | turkish_lira_annual_vol | us_dollar_annual_vol | south_african_rand_annual_vol | year | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1999 | 0.1287 | NaN | NaN | 0.1184 | 0.0256 | NaN | 0.0096 | 0.0694 | 0.0020 | 0.0000 | 0.0718 | 0.0245 | 0.0913 | NaN | 0.0513 | 0.3246 | NaN | NaN | 0.0489 | 0.1445 | 0.1130 | 0.0914 | 0.0669 | 0.0784 | 0.2085 | 0.0914 | 0.0569 | 0.1293 | 0.1208 | 0.1142 | 0.2024 | 0.1963 | 0.0556 | 0.0966 | 0.0456 | 0.0569 | 0.1250 | 0.0614 | 0.0924 | 0.1311 | 1999 |
2000 | 0.1270 | 0.0098 | 0.2621 | 0.1507 | 0.0441 | 0.1376 | 0.0116 | 0.0452 | 0.0032 | 0.0000 | 0.1112 | 0.0066 | 0.1374 | 0.0169 | 0.0159 | 0.2169 | 0.1479 | 0.1448 | 0.0811 | 0.1650 | 0.1640 | 0.1376 | 0.1035 | 0.0640 | 0.1662 | 0.1373 | 0.0533 | 0.1461 | 0.1688 | 0.1251 | 0.1414 | 0.1533 | 0.0618 | 0.1391 | 0.0207 | 0.0471 | 0.1597 | 0.0832 | 0.1376 | 0.1273 | 2000 |
2001 | 0.1273 | 0.0058 | 0.2217 | 0.1149 | 0.0456 | 0.1115 | 0.0170 | 0.0468 | 0.0030 | 0.0000 | 0.0755 | NaN | 0.1116 | 0.0498 | 0.0784 | 0.2555 | 0.1212 | 0.1124 | 0.1161 | 0.1371 | 0.1467 | 0.1115 | 0.0818 | 0.0426 | 0.1575 | 0.1122 | 0.0522 | 0.1206 | 0.2043 | 0.1275 | 0.1119 | 0.1129 | 0.0752 | 0.1132 | 0.0129 | 0.0347 | 0.1201 | 0.6486 | 0.1115 | 0.2148 | 2001 |
2002 | 0.0990 | 0.0075 | 0.3007 | 0.1037 | 0.0297 | 0.0962 | 0.0081 | 0.0760 | 0.0023 | 0.0000 | 0.0592 | NaN | 0.0962 | 0.0278 | 0.0508 | 0.1363 | 0.1299 | 0.0961 | 0.0831 | 0.0897 | 0.0982 | 0.0363 | 0.0600 | 0.0335 | 0.1533 | 0.0957 | 0.0499 | 0.1091 | 0.0980 | 0.1016 | 0.0993 | 0.0975 | 0.0677 | 0.0810 | 0.0321 | 0.0504 | 0.0851 | 0.1908 | 0.0962 | 0.1996 | 2002 |
2003 | 0.0843 | 0.0047 | 0.2003 | 0.0947 | 0.0387 | 0.1031 | 0.0084 | 0.0530 | 0.0024 | 0.0000 | 0.0709 | NaN | 0.1030 | 0.0344 | 0.1017 | 0.1114 | 0.1256 | 0.1010 | 0.0798 | 0.0941 | 0.1110 | 0.0014 | 0.0599 | 0.0316 | 0.1627 | 0.1024 | 0.0680 | 0.0903 | 0.1068 | 0.0934 | 0.0597 | 0.1011 | 0.0509 | 0.0869 | 0.0082 | 0.0412 | 0.0946 | 0.1606 | 0.1031 | 0.1846 | 2003 |
# horizontal bar chart showing volatility
plt.barh(y=annual_volatility.iloc[:,40], width=annual_volatility.iloc[:,2])
plt.show()
# build and animate the map
# # need this to correctly get year ticks in DQ server
# years = mdates.YearLocator() # every year
# years_fmt = mdates.DateFormatter('%Y')
# for ax in ax1, ax2, ax3, ax4:
# ax.xaxis.set_major_locator(years) # format the x ticks
# ax.xaxis.set_major_formatter(years_fmt)
# fmt_three_years = mdates.MonthLocator(interval = 36) # Major ticks every 3 years
# ax.xaxis.set_major_locator(fmt_three_years)
# ax.set(yticks=[],
# xlabel="Year")
from IPython.core.display import HTML
# def css_styling():
# styles = open("custom.css", "r").read() #or edit path to custom.css
# return HTML(styles)
# css_styling()
display(HTML("<style>.container { width:70% !important; }</style>"))