Visualising international and European government bond market returns in R
Every now and then, I need to get a quick overview of international government bond markets to assess changes over time or compare countries. Usually, places like the Financial Times provide the necessary information, but when you need to dig a little deeper, manual work is required. In the past, I would simply get the data from whatever database was available to me (like the IMF's database), but starting over every time becomes cumbersome, so I decided to automate a few things in R.
The St. Louis Fed's FRED database covers a lot of the stuff I need regularly. Their data is available publicly and can be conveniently loaded into R using the pdfetch package by running
pdfetch_FRED(c("List of indicators")). The indicator codes can be found right on FRED's homepage, e.g. IRLTLT01USM156N is the code for 10-year US Treasuries and IRLTLT01JPM156N is the code for 10-year Japanese Government Bonds. Notice how these codes generally look very similar for the same economic concept, only the two-letter ISO country code changes (IRLTLT01JPM156N, where JP stands for Japan).
I first fetch data for the four main government bond markets, i.e. the US, the UK, Germany, and Japan, from FRED. The graph nicely illustrates how interest rates on long-term government bonds declined since the 1980s-1990s, with Japanese and German 10-year government bonds even briefly dipping below zero in recent months.
Another chart I frequently need is one showing European government bond yields. Again, FRED has all the necessary data. The graph nicely shows how government bond yields initially converged across Europe as the euro was introduced, and then diverged again from 2009 onward. Have a look at this script to see how all of this works in detail.