{
"metadata": {
"name": "",
"signature": "sha256:16afd304a1d4f20d6fd49578a335f6b2048174808b4f38267a6f95b7ff5f302d"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Gold and 10-year Treasury TIPS, their daily relationship"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using monthly data we previously found that there is a strong correlation between gold and real rates, so we investigate this on a finer time scale. We then use this correlation to help make forecasts using the univariate Holt-Winters method."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Dependencies:*\n",
"\n",
" - Linux, bash [not crucial, cross-platform prefered]\n",
" - Python: matplotlib, pandas [recommend Anaconda distribution]\n",
" - Modules: yi_1tools, yi_timeseries, yi_fred\n",
" \n",
"*CHANGE LOG*\n",
"\n",
" 2015-03-10 Code review and revision.\n",
" 2014-08-01 Use modules derived from notebooks.\n",
" 2014-07-22 First satisfactory version."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# NOTEBOOK settings and system details: [00-tpl v14.09.28]\n",
"\n",
"# Assume that the backend is LINUX (our particular distro is Ubuntu, running bash shell):\n",
"print '\\n :: TIMESTAMP of last notebook execution:'\n",
"!date\n",
"print '\\n :: IPython version:'\n",
"!ipython --version\n",
"\n",
"# Automatically reload modified modules:\n",
"%load_ext autoreload\n",
"%autoreload 2 \n",
"# 0 will disable autoreload.\n",
"# Generate plots inside notebook:\n",
"%matplotlib inline\n",
"\n",
"# DISPLAY options\n",
"from IPython.display import Image \n",
"# e.g. Image(filename='holt-winters-equations.png', embed=True)\n",
"from IPython.display import YouTubeVideo\n",
"# e.g. YouTubeVideo('1j_HxD4iLn8')\n",
"from IPython.display import HTML # useful for snippets\n",
"# e.g. HTML('')\n",
"import pandas as pd\n",
"print '\\n :: pandas version:'\n",
"print pd.__version__\n",
"# pandas DataFrames are represented as text by default; enable HTML representation:\n",
"# [Deprecated: pd.core.format.set_printoptions( notebook_repr_html=True ) ]\n",
"pd.set_option( 'display.notebook_repr_html', False )\n",
"\n",
"# MATH display, use %%latex, rather than the following:\n",
"# from IPython.display import Math\n",
"# from IPython.display import Latex\n",
"\n",
"print '\\n :: Working directory (set as $workd):'\n",
"workd, = !pwd\n",
"print workd + '\\n'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
" :: TIMESTAMP of last notebook execution:\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Thu Mar 12 14:20:08 PDT 2015\r\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
" :: IPython version:\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"2.3.0\r\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
" :: pandas version:\n",
"0.15.0\n",
"\n",
" :: Working directory (set as $workd):\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"/home/yaya/Dropbox/ipy/fecon235/nb\n",
"\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from yi_1tools import *\n",
"from yi_timeseries import *\n",
"from yi_fred import *"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Get gold and 10-y TIPS rates, both as daily frequency:\n",
"gold = getfred( d4xau )\n",
"tips = getfred( d4tips10 )"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# The joint sample size is constrained by the more \n",
"# recent instrument TIPS issued by the US Treasury:\n",
"head( tips, 1 )"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"text": [
" Y\n",
"T \n",
"2003-01-02 2.43"
]
}
],
"prompt_number": 4
},
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Strong inverse correlation between XAU and 10-year TIPS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since 2003, there has been a strong inverse correlation between gold and TIPS: -87%. Gold becomes more attractive as an asset as real rates decline. When real rates are negative, then gold (which has no income stream) will preserve wealth. \n",
"\n",
"**Linear regression shows that since 2003 a decrease of 100 basis points in the TIPS yield implies an increase of $413 in gold price.**"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Focus on Great Recession to present"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"start = '2003-01-02'\n",
"\n",
"start = '2007-01-02'\n",
"# Comment out this line to get earlier regression results.\n",
"\n",
"# Do linear regression:\n",
"stat2( gold['Y'][start:], tips['Y'][start:] )"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" :: FIRST variable:\n",
"count 2138.000000\n",
"mean 1210.443662\n",
"std 330.007724\n",
"min 608.400000\n",
"25% 921.187500\n",
"50% 1234.625000\n",
"75% 1456.812500\n",
"max 1895.000000\n",
"Name: Y, dtype: float64\n",
"\n",
" :: SECOND variable:\n",
"count 2137.000000\n",
"mean 0.916425\n",
"std 0.952471\n",
"min -0.870000\n",
"25% 0.250000\n",
"50% 0.850000\n",
"75% 1.640000\n",
"max 3.150000\n",
"Name: Y, dtype: float64"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"\n",
" :: CORRELATION\n",
"-0.913379014814\n",
"\n",
"-------------------------Summary of Regression Analysis-------------------------\n",
"\n",
"Formula: Y ~ + \n",
"\n",
"Number of Observations: 2137\n",
"Number of Degrees of Freedom: 2\n",
"\n",
"R-squared: 0.8343\n",
"Adj R-squared: 0.8342\n",
"\n",
"Rmse: 134.4115\n",
"\n",
"F-stat (1, 2135): 10746.7170, p-value: 0.0000\n",
"\n",
"Degrees of Freedom: model 1, resid 2135\n",
"\n",
"-----------------------Summary of Estimated Coefficients------------------------\n",
" Variable Coef Std Err t-stat p-value CI 2.5% CI 97.5%\n",
"--------------------------------------------------------------------------------\n",
" x -316.5351 3.0534 -103.67 0.0000 -322.5198 -310.5505\n",
" intercept 1500.5516 4.0354 371.85 0.0000 1492.6423 1508.4609\n",
"---------------------------------End of Summary---------------------------------\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2015-03-10: **The inverse relationship has become stronger since the Great Recession crisis (-91% correlation): TIPS +100 bp move implies a -$317 decrease in gold price.** "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"tail( gold )"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": [
" Y\n",
"T \n",
"2015-03-04 1199.50\n",
"2015-03-05 1202.00\n",
"2015-03-06 1175.75\n",
"2015-03-09 1168.50\n",
"2015-03-10 1162.00\n",
"2015-03-11 1150.00\n",
"2015-03-12 1152.25"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"tail( tips )"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"text": [
" Y\n",
"T \n",
"2015-03-03 0.26\n",
"2015-03-04 0.25\n",
"2015-03-05 0.27\n",
"2015-03-06 0.41\n",
"2015-03-09 0.44\n",
"2015-03-10 0.41\n",
"2015-03-11 0.39"
]
}
],
"prompt_number": 7
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Interim conclusions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Regression summary*: Depending on the timeframe specified by the *start* variable, the **regression coefficient tells us that the price of gold decreases by about \\$365 (midpoint) for every 100 basis point rise in 10-year real rates** (*so roughly \\$90 decrease per quarter point rise*)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*August 2014 summary:* From current levels where gold is at \\$1290 and TIPS yield 0.25%, we can **expect gold to fall below \\$1000 if 10-year TIPS reach 1.25%.** Note that \\$1000 gold is only $0.61 \\sigma$ away from the 7-year mean of \\$1208. The long-term *support point* going back to 2005 is currently around $1260. It's not unreasonable for gold to breach long-term support if the Fed starts hiking rates up. The mean TIPS rate is 1.30% since its inception."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*March 2015 summary:* From current levels where gold is at \\$1162 and TIPS yield 0.25%, we can **expect gold to fall below \\$1000 if the 10-year TIPS rate reach 0.75%.** The Fed has ceased its QE quantitative easing program, and looks to raise rates soon, especially given that unemployment has decreased to the top of the Fed's NAIRU range (\"non-accelerating inflation rate of unemployment\"). USD has become extremely strong against all major currencies -- which further diminishes the appeal of gold."
]
},
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Univariate forecasts using Holt-Winters method"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# We resample gold monthly, and project out 12 months from now:\n",
"holtfred( monthly(gold), 12 )"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": [
" Forecast\n",
"0 1175.750000\n",
"1 1195.296751\n",
"2 1189.081183\n",
"3 1182.865616\n",
"4 1176.650048\n",
"5 1170.434481\n",
"6 1164.218913\n",
"7 1158.003346\n",
"8 1151.787778\n",
"9 1145.572211\n",
"10 1139.356643\n",
"11 1133.141076\n",
"12 1126.925508"
]
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2015-03-10: Possible dramatic change in Fed policy (rate hikes) does not seem reflected in the projected decline in gold price. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# We resample TIPS monthly, and project out 12 months from now:\n",
"holtfred( monthly(tips), 12 )"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": [
" Forecast\n",
"0 0.330000\n",
"1 0.288096\n",
"2 0.261604\n",
"3 0.235112\n",
"4 0.208620\n",
"5 0.182127\n",
"6 0.155635\n",
"7 0.129143\n",
"8 0.102651\n",
"9 0.076158\n",
"10 0.049666\n",
"11 0.023174\n",
"12 -0.003318"
]
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2015-03-10: Possible dramatic change in Fed policy (rate hikes) does not seem reflected in the projected decline into negative territory for TIPS rate. This 12-month projection to -0.06% (from 0.26% currently) would indicate a \\$95 increase in gold price to $1295. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notes:\n",
"\n",
"- The directions of univariate forecasts may at times contradict the directions expected from the sign of correlation. In such cases, we suggest taking the average of point forecasts.\n",
"\n",
"- TIPS bond also reflects the current forward expectation of inflation in the next ten years.\n",
"\n",
"- Gold has soft lower boundaries, for example, the cost of production to produce new stock."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# 2005-03-12: average of between 12-m gold H-W forecast \n",
"# and 12-m gold extrapolated from H-W forecasted change in TIPS \n",
"# using regression coefficient [delta analysis]:\n",
"coef = -317\n",
"delta = coef * (-0.00-0.33)\n",
"(1127 + (tailvalue(gold) + delta)) / 2"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 17,
"text": [
"1191.9299999999998"
]
}
],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 10
}
],
"metadata": {}
}
]
}