DEV Community

loading...

Comparing currency devaluation with Python

Harvey
・2 min read

As the old saying goes, "money makes the world go around". Sure enough, money is the easiest way to measure a country's economic health, or at least its purchasing power.

Data about purchasing power is publicly available at statista. We can use matplotlib to plot a line chart and compare the devaluation process of currencies.

For the euro the purchasing power data from 2000 to 2020 is:

y = [ 1.39, 1.36, 1.33, 1.3, 1.28, 1.25, 1.22, 1.2, 1.16, 1.15, 1.13, 1.1, 1.08, 1.06, 1.06, 1.06, 1.06, 1.04, 1.02, 1.01, 1]
Enter fullscreen mode Exit fullscreen mode

The code below plots the devaluation of the euro:

import matplotlib.pyplot as plt
import numpy as np

y = [ 1.39, 1.36, 1.33, 1.3, 1.28, 1.25, 1.22, 1.2, 1.16, 1.15, 1.13, 1.1, 1.08, 1.06, 1.06, 1.06, 1.06, 1.04, 1.02, 1.01, 1]
x = range(0,len(y)) 

plt.figure()
plt.plot(x,y)

plt.show()
Enter fullscreen mode Exit fullscreen mode

For the dollar the devaluation is:

y = [ 1.51, 1.47, 1.45, 1.41, 1.38, 1.33, 1.29, 1.26, 1.21, 1.19, 1.16, 1.13, 1.12, 1.1, 1.1, 1.08, 1.06, 1.04, 1.02 ]
Enter fullscreen mode Exit fullscreen mode

The numbers are not in the same range, so you need to normalize them. I will normalize against the maximum, not normalize against the sum. To normalize against the maximum you can use

norm = [float(i)/max(raw) for i in raw]
Enter fullscreen mode Exit fullscreen mode

Ofcourse I add a legend to the plot to show the currency.
That gives us this plot:

import matplotlib.pyplot as plt
import numpy as np

eur = [ 1.39, 1.36, 1.33, 1.3, 1.28, 1.25, 1.22, 1.2, 1.16, 1.15, 1.13, 1.1, 1.08, 1.06, 1.06, 1.06, 1.06, 1.04, 1.02]

usd = [ 1.51, 1.47, 1.45, 1.41, 1.38, 1.33, 1.29, 1.26, 1.21, 1.19, 1.16, 1.13, 1.12, 1.1, 1.1, 1.08, 1.06, 1.04, 1.02 ]

x = range(0,len(eur))

y_eur = [float(i)/max(eur) for i in eur]
y_usd = [float(i)/max(usd) for i in usd]

plt.figure()
plt.plot(x,y_eur)
plt.plot(x,y_usd)

plt.ylabel("Purchasing power")
plt.xlabel("Year")
plt.legend(['eur','usd'])
plt.show()
Enter fullscreen mode Exit fullscreen mode

purchasing power

The trend is similar in both currencies. This program should work with any currency

Discussion (0)