#!/usr/bin/env python
# coding: utf-8
#
Table of Contents
#
# In[2]:
from pandas_datareader import data, wb
import pandas_datareader as pdr
import matplotlib.pyplot as plt
import datetime as dt
import pandas as pd
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters() # Allow matplotlib have access to timestamp
import matplotlib.ticker as mplticker
# In[29]:
# Retrieve data from FRED, check my notebook for pandareader's user guide
start = dt.datetime(1950, 1, 1)
end = dt.datetime.today()
GovBond10Y = pdr.data.DataReader('IRLTLT01USM156N', 'fred', start, end)
GoldFixP = pdr.data.DataReader('GOLDAMGBD228NLBM', 'fred', start, end)
# In[30]:
fig, ax = plt.subplots(figsize = (13, 8))
ax.plot(GovBond10Y, color = 'CornflowerBlue', alpha = 1, label = '10Y US Treasury Bond')
ax.set_ylabel('Long Term US Gov Bond Yield', size = 14)
ax_RHS = ax.twinx() # share the same x-axis
ax_RHS.plot(GoldFixP, color = 'DarkGoldenRod', alpha = .7, label = 'Gold Fixing Price')
ax_RHS.set_ylabel('Gold Fixing Price London', size = 14)
ax.legend(fontsize = 16)
ax_RHS.legend(fontsize = 16, loc = 'lower right')
ax.grid()
plt.show()
# In[31]:
fig, ax = plt.subplots(figsize = (13, 8))
ax.plot(GovBond10Y, color = 'CornflowerBlue', alpha = 1, label = '10Y US Treasury Bond')
ax.set_ylabel('Long Term US Gov Bond Yield', size = 14)
ax = plt.gca()
ax.set_ylim(ax.get_ylim()[::-1])
ax_RHS = ax.twinx() # share the same x-axis
ax_RHS.plot(GoldFixP, color = 'DarkGoldenRod', alpha = .7, label = 'Gold Fixing Price')
ax_RHS.set_ylabel('Gold Fixing Price London', size = 14)
ax.legend(fontsize = 16)
ax_RHS.legend(fontsize = 16, loc = 'lower right')
ax.grid()
plt.show()
# TIPS is constanly used as a proxy for real interest rate.
# In[44]:
# Retrieve data from FRED, check my notebook for pandareader's user guide
start = dt.datetime(2003, 1, 1)
end = dt.datetime.today()
TIPS10Y = pdr.data.DataReader('DFII10', 'fred', start, end)
GoldFixP = pdr.data.DataReader('GOLDAMGBD228NLBM', 'fred', start, end)
fig, ax = plt.subplots(figsize = (13, 8))
ax.plot(TIPS10Y, color = 'CornflowerBlue', alpha = 1, label = 'TIPS 10Y')
ax.set_ylabel('TIPS 10Y', size = 14)
ax.axhline(0, color = 'k', zorder = -1, lw = 1.5)
ax_RHS = ax.twinx() # share the same x-axis
ax_RHS.plot(GoldFixP, color = 'DarkGoldenRod', alpha = .7, label = 'Gold Fixing Price')
ax_RHS.set_ylabel('Gold Fixing Price London', size = 14)
ax.legend(fontsize = 16)
ax_RHS.legend(fontsize = 16, loc = 'lower right')
ax.grid()
# In the period of negative real interest rate, the gold price surges, because other assets are negative return, gold resume its role of store of value.
# In[ ]: