The problem was about using the Big Mac index from The Economist to measure the purchasing power parity between two currencies. Basically, it can tell us how over or under valued a currency is relative to the dollar given the price of Big Macs in each country.
The percentage of over or under valuation of each currency is calculated by the formula percentage =
( (local price converted to USD- US price)/ (US price) ) * 100
I used numpy to read the txt files and convert each big mac price to USD given the exchange rate.
The hard part was really just converting the given columns of months and years into datetime format for matplotlib to plot.
Converting two columns to datetime format
Once I got a list of months and list of years in integer format, I converted them to tuples of (month, year) by using a while loop. I don't think this is the best way to do that since you had to know how many rows of data there are. There is probably an easier way to do that.
Once I had my list of tuples of (month, year), I used datetime to convert them to datetime. I was missing a "day" argument, so I made the day 1 for every tuple like so:
dt = []
for element in list_of_month_years:
dt_obj = datetime(*element, 1)
dt.append(dt_obj)
print(dt)
Now, I had my list of datetimes. I just had to plot it against the valuation percentages.
The Plots
Pretty neat graphs!
Final Thoughts
I learned more about the datetime module and creating line graphs with matplotlib. It would be interesting to know more about the economic history of the countries in the graphs to explain the overall trend or the the peaks or troughs of the graphs.
Github code - Big Mac Index
No comments:
Post a Comment