[ Beginner 3 ] Best Algo Trading Tutorial – US-German Yield Spread

Yaonology Algorithmic Trading
Share on facebook
Share on twitter
Share on linkedin
Share on email
Share on reddit

Best algo economic indicator tutorial for the beginner (3): US-German Yield Spread

Algo trading is not as difficult as you think. In this tutorial article, there are three simple steps to lead the beginner to understand how to code your own best algorithm trading strategy for yield spread economic indicator. All the coding is using pine script and based on the Tradingview platform.

Background Introduction

US-German Yield Spread is a widely used economic indicator to study economic trends in US and Europe. At here, we refer to the difference between US 10-year Treasury yield and German 10-year government bond yield.

Long-term Treasury bonds are more able to reflect changes in the general environment than short-term Treasury bonds, including central bank policy trends, inflation expectations, and overall condition of the economy. In general, the relationship between the economy and government bonds is as follows:

  1. Prosperity >> Capital flows from the bond market into the stock market, inflation is expected to rise; Central bank‘s policy is expected to be tightened >> bond prices are decreasing >> yields are rising.
  2. Recession>> Funds flow from the stock market into the bond market, inflation is expected to slow down; Central bank’s policy is expected to be easing >> bond prices are rising >> yields are decreasing

The reverse of Yield Spread between the US and German normally happened 1 to 2 years before the same situation happens in the U.S. stocks market. (in 2000, 2008, and 2011)

The United States is always in a leading position with a strong growth rate. When Yield Spread between US and German increases, the US economy is expanding strongly, and the price of US stocks will rise. When the Euro area’s economy is improving, the Euro area central bank will take relatively austerity actions, and the Yield Spread of the US and Germany will reverse from a high-end reversal. When this happens, global stock markets will be in a thriving phase. Over the past 20 years, this period often also represented the signal of the end of the boom, and it usually happened 1 to 2 years ahead of the trend of S & P 500.

Below is the full version of code:


study("US & GERMANY 10 Year Government Bond Yield Difference",overlay = true)

ger = security("DE10Y","D",close)

us = security("US10Y","D",close)

diff = us-ger

plot(diff,color = color.red)

Step One: Initialization

study(“Yaonology US & GERMANY 10 Year Government Bond Yield Difference“,overlay = true)

“study” is different from “strategy”. It contains calculations and may plot information on charts, but cannot be used in backtesting. 

Yaonology  defines the name as “Yaonology US & GERMANY 10 Year Government Bond Yield Difference” 

overlay: Yes – True

Step Two: Calculate the Index

ger = security(“DE10Y”,”D”,close)

us = security(“US10Y”,”D”,close)

diff = us-ger

security- the function that enables to extract data from the symbol

“D”-we set the interval as each day 

“close”- we use the closing price

Here, ger is German 10-year government bond yield, and us is US 10-year Treasury yield. The last variable diff is the difference between ger and diff.

Step Three: Plot

plot(diff,color = color.red)

We plot the difference between US and Germany yield, and set the curve’s color to red

Final Version

[ Beginner 3 ] Best Algo Trading Tutorial – US-German Yield Spread
Source: Yaonology

Surprisingly, the difference curve lies above the US Treasury yield curve! This is because the German government bond yield remains negative in recent years, causing the difference to be higher than the US Treasury yield itself.


SP500 Algo Trading Strategy

Bitcoin Algo Trading Strategy

#algorithmictrading #algotrading #trading #tradingstrategy #bitcoin #sp500 #stock #traderslife #algo #tradingplan #tradingview #pinescript #yieldspread #yield #yieldcurve

This website uses cookies to ensure you get the best experience on our website.

Read Privacy Policy