Forecasting Currency Pairs With the PPP Method in Python
How to Use the PPP Method to Forecast Currencies
The Purchasing Power Parity is a fundamental forecasting tool that relies on inflation between two countries to forecast the intrinsic value of the currency pair between them. This article presents the PPP method and shows how to use Python to forecast currency pairs using it.
For a detailed and thorough collection of contrarian trading strategies, you can check out my book. The book features a huge number of classic and modern techniques as it dwelves into the realm of technical analysis with different trading strategies. The book comes with its own GitHub.
Contrarian Trading Strategies in Python
Amazon.com: Contrarian Trading Strategies in Python: 9798434008075: Kaabar, Sofien: Booksamzn.to
The Purchasing Power Parity Forecasting Method
The Purchasing Power Parity (PPP) method is a widely used approach for forecasting exchange rates between two currencies. It is based on the idea that over time, the exchange rate between two currencies will adjust such that the purchasing power of each currency is equal in both countries thus making it part of fundamental analysis.
To use the PPP method for forecasting exchange rates, you need to gather data on the prices of a basket of goods and services in both countries. This data can typically be obtained from various sources such as the Saint-Louis Federal Reserve.
The PPP rate can then be used to forecast future exchange rates by assuming that the PPP rate will continue to hold in the future. However, it is important to note that the PPP method is not an accurate forecasting tool, as it makes several assumptions about market conditions and the functioning of international markets that may not always hold true. In fact, some market professionals even call it the Pretty Poor Predictor.
Also, I have found that the data does not always match since the base years are not the same (typically, one would consider the end of Bretton Woods to be the base but again it was accompanied by very high inflation). In the US, the consumer price index which is the best proxy of the basket of goods and services has a base since 1982 unlike other countries. These challenges hinder the accuracy and utility of PPP but for the sake of explaining it, we’ll go past them. We will download data for the US and the UK CPI’s and analyze them while keeping in mind the limitations (and the likely differences you may find with other sources due to other methods of calculations)
A Simple Example
We’ll use Python to automatically download the US CPI, UK CPI, and GBPUSD from the FRED (Federal Reserve of Saint-Louis). Then we will try to apply the formula and see where we stand.
import pandas_datareader.data as pdr
import matplotlib.pyplot as plt
import datetime
start_date = datetime.datetime(1982, 1, 1)
end_date = datetime.datetime(2022, 11, 30)
us_cpi = pdr.DataReader('CPILFESL', 'fred', start_date, end_date)
uk_cpi = pdr.DataReader('GBRCPICORMINMEI', 'fred', start_date, end_date)
gbpusd = pdr.DataReader('DEXUSUK', 'fred', start_date, end_date)
gbpusd = gbpusd.resample("M").last()
us_cpi_yoy = us_cpi.pct_change(periods = 12) * 100
us_cpi_yoy = us_cpi_yoy.dropna()
uk_cpi_yoy = uk_cpi.pct_change(periods = 12) * 100
uk_cpi_yoy = uk_cpi_yoy.dropna()
ppp = us_cpi_yoy['CPILFESL'] / uk_cpi_yoy['GBRCPICORMINMEI']
plt.plot(ppp[-250:,], label = 'Real Exchange Rate - PPP')
plt.plot(gbpusd[-250:], label = 'GBPUSD Market Rate')
plt.legend()
plt.grid()
The code first imports the pandas_datareader library and the datetime module. The start and end dates for the data are set using the datetime module, and the YoY data is retrieved using the DataReader function from the pandas_datareader library.
The data is then resampled to get the last value of each year, and the YoY change is calculated using the pct_change function from pandas. The head function is used to display the first 5 rows of the YoY data.
Now, what is wrong with the above graph? Naturally, we would use directly the CPI’s in the formula and not their Year-on-Year changes. Doing so will give a distorted image that is actually pretty useless (values will remain above 2.5 for most of the time giving an undervalued GBPUSD for the past 30–40 years). Is this because of the base year effect? Different calculation methods? Different weightings? Yes, the PPP method while having a simple formula, remains very subjective and professionals actually never use it directly but with a few tweaks and additions so that it becomes useful.
It’s important to note that the PPP model is not always an accurate way of predicting exchange rates, as it makes several assumptions about market conditions and the functioning of international markets that may not always hold true. Additionally, the accuracy of the real exchange rate calculation will depend on the quality and representativeness of the basket of goods and services used in the calculation.
We will start discovering more fundamental valuation models in Python in the coming articles and why not combine them with technical indicators. Do not forget to subscribe to get the best of the articles.
If you want to see how to create all sorts of algorithms yourself, feel free to check out Lumiwealth. From algorithmic trading to blockchain and machine learning, they have hands-on detailed courses that I highly recommend.
Learn Algorithmic Trading with Python Lumiwealth
Learn how to create your own trading algorithms for stocks, options, crypto and more from the experts at Lumiwealth. Click to learn more
Summary
To sum up, what I am trying to do is to simply contribute to the world of objective technical analysis which is promoting more transparent techniques and strategies that need to be back-tested before being implemented. This way, technical analysis will get rid of the bad reputation of being subjective and scientifically unfounded.
I recommend you always follow the the below steps whenever you come across a trading technique or strategy:
Have a critical mindset and get rid of any emotions.
Back-test it using real life simulation and conditions.
If you find potential, try optimizing it and running a forward test.
Always include transaction costs and any slippage simulation in your tests.
Always include risk management and position sizing in your tests.
Finally, even after making sure of the above, stay careful and monitor the strategy because market dynamics may shift and make the strategy unprofitable.