Introduction
Gold plays an essential role as a diversifier due to its low or negative correlation to other asset classes. We explore "The Fed Model," a theory that bonds can be used to judge whether the U.S. stock market is fairly valued and use this to determine entry and exit points for gold.
Method
Fed Model
Historically, the S&P 500 earning yield has a strong correlation with the 10-year Treasury note. There is the theory that if the forward earnings yield of the S&P 500 is higher than the 10-year government bond yield, stocks are undervalued and vice versa.
We import the custom fundamental data of government 10-year bond yield and S&P 500 earnings yield from Nasdaq Data Link.
# United States Government 10-Year Bond Yield
self.bond_yield = self.add_data(NasdaqDataLinkRate, "YC/USA10Y", Resolution.DAILY, TimeZones.UTC, True).symbol
# S&P 500 Earnings Yield. Earnings Yield = trailing 12 month earnings divided by index price
self.earnings_yield = self.add_data(NasdaqDataLink, "MULTPL/SP500_EARNINGS_YIELD_MONTH", Resolution.DAILY, TimeZones.UTC, True).symbol
# Gold Prices (Daily) - Currency USD (All values are national currency units per troy ounce)
self.gold = self.add_data(NasdaqDataLink, "WGC/GOLD_DAILY_USD", Resolution.DAILY, TimeZones.UTC, True).symbol
Gold Investment
With gold having a strong negative correlation to Equity valuations, then gold prices will rise along with earnings yield, bond yield, and inflation. Taking the above relationship a step further, this algorithm goes long gold when the Fed model shows the market undervalued otherwise liquidate the portfolio. The undervalued market is defined as the earning yield is higher than the bond yield and their ratio is at least 2. Rebalancing is done on a monthly basis.
def rebalance(self):
if self.securities[self.earnings_yield].price == 0 or self.securities[self.bond_yield].price == 0: return
# Buy gold if E/P is higher than the bond yield and their ratio is at least 2
if self.securities[self.earnings_yield].price > self.securities[self.bond_yield].price * Decimal(2):
self.set_holdings(self.gold, 0.9)
else:
self.liquidate()
Custom Charting
To demonstrate the relationship between government 10-year bond yield and S&P 500 earnings yield, we plot the two series in an custom chart.
def initialize(self):
yield_plot = Chart("Yield Plot")
yield_plot.add_series(Series("BondYield", SeriesType.LINE, 0))
yield_plot.add_series(Series("EarningsYield", SeriesType.LINE, 0))
self.add_chart(yield_plot)
def on_data(self, data):
if data.contains_key(self.bond_yield) and data.contains_key(self.earnings_yield):
self.plot("Yield Plot", "BondYield", data[self.bond_yield].price)
self.plot("Yield Plot", "EarningsYield", data[self.earnings_yield].price)
Derek Melchin
See the attached backtest for an updated version of the algorithm with the following changes:
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jing Wu
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!