The recession.
The news talks about it.
Investors cry over it.
And in the end, weβre the ones that lose money.
But you can prepare.
Hereβs how:
Analyze the yield curve.
The yield curve plots the yield of US treasuries against their maturity.
βInvertedβ yield curves have been shown to reliably predict recessions.
Itβs key to understanding investorsβ predictions about the economy.
But whatβs an inverted yield curve?
The yield curve plots the yield of US treasuries against their maturity.
βInvertedβ yield curves have been shown to reliably predict recessions.
Itβs key to understanding investorsβ predictions about the economy.
But whatβs an inverted yield curve?
The inverted yield curve:
β’ Normally, longer-dated treasuries yield more than shorter-dated ones
β’ The market expects the Fed to lower rates to fight recessions
β’ Longer-dated maturities yield less than shorter-dated ones
Letβs check it out in Python.
β’ Normally, longer-dated treasuries yield more than shorter-dated ones
β’ The market expects the Fed to lower rates to fight recessions
β’ Longer-dated maturities yield less than shorter-dated ones
Letβs check it out in Python.
Start with importing NumPy, Matplotlib, and the OpenBB SDK.
You can use the OpenBB SDK to get yield curve data for the St. Louis Fedβs data portal (FRED).
You can use the OpenBB SDK to get yield curve data for the St. Louis Fedβs data portal (FRED).

Then set up the bond maturities you want to use to build the yield curve.
There are conventions about which maturities to use, but there is no βrightβ answer.
The point is to get a good representation across the maturities.
There are conventions about which maturities to use, but there is no βrightβ answer.
The point is to get a good representation across the maturities.

With Matplotlib, you can animate a chart.
Animated charts offer a great way to visualize how data changes through time.
First, set up the plots.
Animated charts offer a great way to visualize how data changes through time.
First, set up the plots.

Next, build the animation functions.
The `animate` function grabs the data to plot, then changes the curve color to red when the yield curve is inverted and sets the data.
The `FuncAnimation` function then loops through each row of data, creates the plot, and displays it.
The `animate` function grabs the data to plot, then changes the curve color to red when the yield curve is inverted and sets the data.
The `FuncAnimation` function then loops through each row of data, creates the plot, and displays it.

Animating the chart makes it easy to visualize the evolution of the yield curve through time.
You can change which maturities to use for the yield curve, adjust the time frame, and experiment with different maturities to use to define inverted.
You can change which maturities to use for the yield curve, adjust the time frame, and experiment with different maturities to use to define inverted.
VIDEO
By reading this thread:
β’ You have a reliable predictor of recessions
β’ Can get the data from the OpenBB SDK
β’ Animate a plot of the yield curve
All without an expensive research department or spending a dollar.
β’ You have a reliable predictor of recessions
β’ Can get the data from the OpenBB SDK
β’ Animate a plot of the yield curve
All without an expensive research department or spending a dollar.
To come back to this step-by-step guide later:
β’ Click the link below
β’ Retweet the top tweet
That's it!
β’ Click the link below
β’ Retweet the top tweet
That's it!
View Tweet
Generated by Thread Navigator
Press β + S to quick-export
