Long-term comparison of two asset classes: we boxplot their return distribution and also compute geometric mean returns. Correlation between the two is shown to be nil. We then look at the history of projected returns using Holt-Winters method, which also gives the latest forecasts.
To conclude, we closely examine the relative value of the two assets in terms of gold troy ounces per equity share. Analytically short equities vs. long gold is favorable for an investor with log utility, but hardly profitable over the long haul.
Dependencies:
- Linux, bash [not crucial, cross-platform prefered]
- Python: matplotlib, pandas [recommend Anaconda distribution]
- Modules: yi_1tools, yi_plot, yi_timeseries, yi_fred
CHANGE LOG
2015-02-23 Code review and revision.
2014-08-05 Uses new boxplot routine with paste of dataframes.
# NOTEBOOK settings and system details: [00-tpl v14.09.28]
# Assume that the backend is LINUX (our particular distro is Ubuntu, running bash shell):
print '\n :: TIMESTAMP of last notebook execution:'
!date
print '\n :: IPython version:'
!ipython --version
# Automatically reload modified modules:
%load_ext autoreload
%autoreload 2
# 0 will disable autoreload.
# Generate plots inside notebook:
%matplotlib inline
# DISPLAY options
from IPython.display import Image
# e.g. Image(filename='holt-winters-equations.png', embed=True)
from IPython.display import YouTubeVideo
# e.g. YouTubeVideo('1j_HxD4iLn8')
from IPython.display import HTML # useful for snippets
# e.g. HTML('<iframe src=http://en.mobile.wikipedia.org/?useformat=mobile width=700 height=350></iframe>')
import pandas as pd
print '\n :: pandas version:'
print pd.__version__
# pandas DataFrames are represented as text by default; enable HTML representation:
# [Deprecated: pd.core.format.set_printoptions( notebook_repr_html=True ) ]
pd.set_option( 'display.notebook_repr_html', False )
# MATH display, use %%latex, rather than the following:
# from IPython.display import Math
# from IPython.display import Latex
print '\n :: Working directory (set as $workd):'
workd, = !pwd
print workd + '\n'
:: TIMESTAMP of last notebook execution: Fri Mar 6 08:29:39 PST 2015 :: IPython version: 2.3.0 :: pandas version: 0.15.0 :: Working directory (set as $workd): /home/yaya/Dropbox/ipy/fecon235/nb
from yi_1tools import *
from yi_fred import *
from yi_plot import *
from yi_timeseries import *
# Get SPX daily:
sp = getfred( d4spx )
:: S&P 500 prepend successfully goes back to 1957.
# Get Gold daily:
au = getfred( d4xau )
# Create their dataframe:
assets = paste( [au, sp])
assets.columns = ['Au', 'SP']
# Compute returns as YoY percentage, assuming 256 days/year:
returns = pcent( assets, 256 )
We can explore returns as far back as 1968-04-01, or any sub-section in time. The gold bubble crashes to its low point around 1982-03-19.
start = '1969-07-01'
# Show subret distribution:
boxplot( returns[start:] )
:: Finished: boxplot-tmp.png
The red line within the box shows the median, while the red dot plots the most recent data point.
Gold shows a wider range of returns to the upside. To best summarize performance, we compute geometric mean returns.
# Geometric mean return for gold in chosen period:
georet( au[start:] )
[7.2, 9.2, 20.02, 256]
# Geometric mean return for US equities in chosen period:
georet( sp[start:] )
[6.59, 8.0, 16.78, 256]
For start since 1970, gold's geometric return exceeds that of US equities by 65 bp. Note that dividends are not included in the SPX index, so we are not comparing total investment return. (Geometric mean returns implicitly penalizes volatility, and is compatible for an investor with logrithmic utility.)
stats( returns[start:] )
Au SP count 11918.000000 11918.000000 mean 10.613677 7.976448 std 28.282301 16.759750 min -41.473587 -48.779458 25% -6.891652 -2.075755 50% 5.086154 9.821511 75% 22.170530 19.348908 max 261.010830 65.300874 :: Index on min: Au 1982-03-19 SP 2008-11-20 dtype: datetime64[ns] :: Index on max: Au 1980-01-21 SP 2010-03-02 dtype: datetime64[ns] :: Head: Au SP T 1969-07-01 0.734394 -3.786541 1969-07-02 3.580402 -3.218233 1969-07-03 3.615960 -2.562848 1969-07-04 6.393862 -2.715109 1969-07-07 6.488550 -3.234317 1969-07-08 7.397959 -4.527675 1969-07-09 8.636364 -4.739430 :: Tail: Au SP T 2015-02-25 -9.739652 12.804777 2015-02-26 -9.629768 12.644292 2015-02-27 -9.756551 12.118613 2015-03-02 -9.193035 12.744670 2015-03-03 -9.765625 12.284982 2015-03-04 -10.900650 12.363263 2015-03-05 -12.005857 12.463334 :: Correlation matrix: Au SP Au 1.000000 -0.103213 SP -0.103213 1.000000
Without the effects of volatility, the arithmetic mean of gold is 260 bp greater than US equities -- which might compensate for its lack of dividends cash flow.
# This also runs a linear regression: Au = f(SP)
stat2( returns[start:]['Au'], returns[start:]['SP'] )
:: FIRST variable: count 11918.000000 mean 10.613677 std 28.282301 min -41.473587 25% -6.891652 50% 5.086154 75% 22.170530 max 261.010830 Name: Au, dtype: float64 :: SECOND variable: count 11918.000000 mean 7.976448 std 16.759750 min -48.779458 25% -2.075755 50% 9.821511 75% 19.348908 max 65.300874 Name: SP, dtype: float64 :: CORRELATION -0.103213213575 -------------------------Summary of Regression Analysis------------------------- Formula: Y ~ <x> + <intercept> Number of Observations: 11918 Number of Degrees of Freedom: 2 R-squared: 0.0107 Adj R-squared: 0.0106 Rmse: 28.1324 F-stat (1, 11916): 128.3076, p-value: 0.0000 Degrees of Freedom: model 1, resid 11916 -----------------------Summary of Estimated Coefficients------------------------ Variable Coef Std Err t-stat p-value CI 2.5% CI 97.5% -------------------------------------------------------------------------------- x -0.1742 0.0154 -11.33 0.0000 -0.2043 -0.1440 intercept 12.0030 0.2854 42.06 0.0000 11.4436 12.5623 ---------------------------------End of Summary---------------------------------
We use the Holt-Winters technique to plot projected annual returns. Resampled monthly data, rather than raw daily data, is used to see the broader trends.
The projected annual returns gives the best linear slope forecasts, thus it is a compact representation of many point predictions using the Holt-Winters technique. It may not be accurate at major turning points, but its path very far away from the (seemingly stationary) mean could indicate overbought or oversold conditions in the market.
# Gold: projected annual returns using monthly data:
aupro = holtpc( monthly(au), 12 )
# Gold projections for the last 40 years:
plotfred( aupro[-480:] )
# Long-term arithmetic mean return is 10.6%.
# Latest forecast of gold return for the coming year:
tailvalue( aupro )
-4.884878533176684
# SPX: projected annual returns using monthly data:
sppro = holtpc( monthly(sp), 12 )
# US equities projections for the last 40 years:
plotfred( sppro[-480:] )
# Long-term arithmetic mean return is 8.0%.
# Latest forecast of SPX return for the coming year:
tailvalue( sppro )
10.944655163915927
# SPX priced in USD per share:
plotfred( sp['1968-04-01':] )
# XAU priced in USD per troy ounce:
plotfred( au['1968-04-01':] )
The previous section on forecasting looked the assets separately. Now we shall look at SPX priced in terms of XAU, which can be interpretated as troy ounces of gold required to buy an equity share in the US.
spau = todf( sp / au )
# Units are thus expressed in troy ounces per share.
# USD as common denominator drops out, and
# Y plots the US equity in terms of troy ounces of gold:
plotfred( spau )
That spike to 5.6 ounces is very noteworthy indicating overvalued equities, and a signal to buy gold. In fact, it is the all-time high since 1880.
# Longer view using monthly Schiller "data," back to 1880, but in terms of grams:
Image(url='http://pricedingold.com/charts/SP500-1880.png', embed=False)
# 1 troy ounce = 31.1 grams
stats( spau )
Y count 12244.000000 mean 1.565869 std 1.217546 min 0.131882 25% 0.644588 50% 1.163509 75% 2.306488 max 5.565022 :: Index on min: Y 1980-01-21 dtype: datetime64[ns] :: Index on max: Y 1999-07-15 dtype: datetime64[ns] :: Head: Y T 1968-04-01 2.453050 1968-04-02 2.483646 1968-04-03 2.485904 1968-04-04 2.539648 1968-04-05 2.521351 1968-04-08 2.562753 1968-04-09 2.532000 :: Tail: Y T 2015-02-25 1.754605 2015-02-26 1.746940 2015-02-27 1.733526 2015-03-02 1.746301 2015-03-03 1.738017 2015-03-04 1.749504 2015-03-05 1.747953 :: Correlation matrix: Y Y 1
Over the long haul, it took an average of 1.57 troy ounces of gold to purchase one US equity share.
# What is the long-term trend?
plotfred( trend(spau) )
:: regresstime slope = 9.67148719065e-05
Simplistically, US equites has arithmetically doubled in value in terms of gold (from 1 oz. in the 70's to over 2 oz. recently). That trend looks good, going as far back as 1932.
# Compute the geometric mean return:
georet( spau )
[-0.7, 2.71, 26.12, 256]
The arithmetic mean return for spau is approximately 2.7% per annum (which is the trend shown graphically above), however, due to high volatility the geometric mean return is sub-zero. This analytically implies short equities vs. long gold is favorable for an investor with log utility, but at high risk with hardly any profit over the long haul.
Including dividends in our analysis would reverse this conclusion as to positions, but would still leave us indifferent as to a definitive choice between the two assets. A complete treatment should also account for the taxation on dividends and capital gains (financial vs. commodity assets).
Notice that the spau volatility is greater than that of SPX, and also that of XAU. Opposing the two assets in a portfolio does not diminish risk, but rather increases risk.
It is worth noting that dividends are reduced generally when industries are not doing well. Interest rates may decrease in order to induce economic activity (cf. Great Recession), which would decrease real interest rates. Since gold has no income stream, it thus becomes more preferable over equities in such situations.
Real interest rates also become negative when monetary policy allows inflation to rise above nominal interest rates. This is the classic scenario where gold is preferable because financial instruments will have difficulty merely preserving wealth.