Highest & Lowest Ever 30-Year Interest Rates in our Lifetime: Hands-On Market Analysis with Python
Introduction
If you are alive today, you have just experienced the lowest 30-year interest rates ever. If you were born before 1981, you also experienced the highest 30-year interest rates ever. Let's explore this weird phenomenon with Python and market data.
Code
from IPython.display import Image
Image(filename='viralml-book.png')
Fundamental and Technical Indicators - Hands-On Market Analysis¶
Get the book "The Little Book of Fundamental Market Indicators":
More at:
Data from the Federal Reserve Bank of St. Louis¶
Treasury 30-Year Treasury Constant Maturity Rate (DGS30)¶
https://fred.stlouisfed.org/series/DGS30
3-Month Treasury Constant Maturity Rate (DGS3MO)¶
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import io, base64, os, json, re
import pandas as pd
import numpy as np
import datetime
import warnings
warnings.filterwarnings('ignore')
path_to_market_data = '/Users/manuel/Documents/financial-research/market-data/2019-08-30/'
Load 30-Year Treasury Constant Maturity Rate (DGS30)¶
In a recession, short-term interest rates can rise above long-term ones, which is the opposite of the more conventional pattern of longer-term interest rates being higher than shorter-term interest rates in normal economic times.
# Get the rates 30 year
# Treasury Yield Curve Rates
rates_30_df = pd.read_csv(path_to_market_data + 'DGS30.csv')
rates_30_df.columns = ['Date', '30yearT']
rates_30_df['Date'] = pd.to_datetime(rates_30_df['Date'])
print(np.min(rates_30_df['Date'] ),np.max(rates_30_df['Date'] ))
rates_30_df = rates_30_df.sort_values('Date', ascending=True)
rates_30_df.tail()
rates_30_df.describe()
# remove NaN and text characters
rates_30_df = rates_30_df[rates_30_df['30yearT'] != '.']
rates_30_df['30yearT'] = rates_30_df['30yearT'].astype(float)
rates_30_df.head()
cut_off_date = '1977-01-01'
rates_30_df_tmp = rates_30_df.copy()
fig, ax = plt.subplots(figsize=(16, 10))
plt.plot(rates_30_df_tmp['Date'], rates_30_df_tmp['30yearT'], color='black', label='Rates')
plt.grid()
plt.title("30 Year Rates")
plt.legend(loc='upper left')
plt.axhline(2)
# Get the 3 months rates
# Treasury Yield Curve Rates
rates_3MO_df = pd.read_csv(path_to_market_data + 'DGS3MO.csv')
rates_3MO_df.columns = ['Date', '3MOT']
rates_3MO_df['Date'] = pd.to_datetime(rates_3MO_df['Date'])
print(np.min(rates_3MO_df['Date'] ),np.max(rates_3MO_df['Date'] ))
rates_3MO_df = rates_3MO_df.sort_values('Date', ascending=True)
rates_3MO_df = rates_3MO_df[rates_3MO_df['3MOT'] != '.']
rates_3MO_df['3MOT'] = rates_3MO_df['3MOT'].astype(float)
rates_3MO_df.tail()
cut_off_date = '2008-01-01 00:00:00'
rates_30_df_tmp = rates_30_df.copy()
rates_30_df_tmp = rates_30_df_tmp[rates_30_df_tmp['Date'] >= cut_off_date]
rates_3MO_df_tmp = rates_3MO_df.copy()
rates_3MO_df_tmp = rates_3MO_df_tmp[rates_3MO_df_tmp['Date'] >= cut_off_date]
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(rates_30_df_tmp['Date'], rates_30_df_tmp['30yearT'], color='black', label='30 Year Rates')
plt.plot(rates_3MO_df_tmp['Date'], rates_3MO_df_tmp['3MOT'], color='blue', label='3MO Rates')
plt.grid()
plt.title("30 Year Rates")
plt.legend(loc='upper left')
plt.axhline(2)
Show Notes
(pardon typos and formatting -these are the notes I use to make the videos)
If you are alive today, you have just experienced the lowest 30-year interest rates ever. If you were born before 1981, you also experienced the highest 30-year interest rates ever. Let's explore this weird phenomenon with Python and market data.