PMI Correlated to the 10-Year Yields? Yes, A PMI Proxy Any Time, Any Day!
Introduction
A PMI Proxy Any Time, Any Day! If this is true, this could come in handy when you need a quick estimate mid-month. Let's roll up our sleeves and find out.
Code
from IPython.display import Image
Image(filename='viralml-book.png')
Fundamental and Technical Indicators - Hands-On Market Analysis¶
Companion book: "The Little Book of Fundamental Market Indicators":
More at:
The US ISM manufacturing headline series is closely correlated with yields ( CS is using ISM as a macro momentum proxy here)¶
Data¶
Purchasing Managers' Index - PMI Composite Index https://www.quandl.com/data/ISM/MAN_PMI-PMI-Composite-Index
Treasury Yield Curve Rates https://www.quandl.com/data/USTREASURY/YIELD-Treasury-Yield-Curve-Rates
%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-07-20/'
# create an MACD indicators
def MACD(df, feature, fast=9, medium=12, long=26):
# WARNING - Feed data in ascending order only (i.e. first row should be your oldest print)
tmp_df = df.copy()
tmp_df['EXP1'] = tmp_df[feature].ewm(span=medium, adjust=False).mean()
tmp_df['EXP2'] = tmp_df[feature].ewm(span=long, adjust=False).mean()
tmp_df['MACD'] = tmp_df['EXP1']-tmp_df['EXP2']
tmp_df['EXP3'] = tmp_df['MACD'].ewm(span=fast, adjust=False).mean()
tmp_df['MACD_Hist'] = tmp_df['MACD'] - tmp_df['EXP3']
return tmp_df
Data¶
# Purchasing Managers' Index - PMI
pmi_df = pd.read_csv(path_to_market_data + 'ISM-MAN_PMI.csv')
pmi_df['Date'] = pd.to_datetime(pmi_df['Date'])
print(np.min(pmi_df['Date'] ),np.max(pmi_df['Date'] ))
pmi_df = pmi_df.sort_values('Date', ascending=True) # sort in ascending date order
pmi_df['PMI_pct_change'] = pmi_df['PMI'].pct_change()
pmi_df.tail()
# Treasury Yield Curve Rates
rates_df = pd.read_csv(path_to_market_data + 'USTREASURY-YIELD.csv')
rates_df['Date'] = pd.to_datetime(rates_df['Date'])
print(np.min(rates_df['Date'] ),np.max(rates_df['Date'] ))
rates_df = rates_df.sort_values('Date', ascending=True) # sort in ascending date order
rates_df['10_YR_pct_change'] = rates_df['10 YR'].pct_change()
rates_df.tail()
Let's Plot it All¶
cut_off_date = '1995-01-02'
pmi_df_tmp = pmi_df.copy()
rates_df_tmp = rates_df.copy()
pmi_df_tmp = pmi_df_tmp[pmi_df_tmp['Date'] >= cut_off_date]
rates_df_tmp = rates_df_tmp[rates_df_tmp['Date'] >= cut_off_date]
# join both datasets together
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(pmi_df_tmp['Date'], pmi_df_tmp['PMI'] , color='blue', label='PMI')
plt.title('PMI & 10 Year Yield')
plt.legend(loc='lower right')
plt.grid()
# Get new axis
ax2 = ax.twinx()
plt.plot(rates_df_tmp['Date'], rates_df_tmp['10 YR'] , color='black', label='10 YR')
plt.legend(loc='lower left')
plt.show()
Join both datasets together¶
# merge data sets together
# join both datasets together
print('pmi_df.shape():',pmi_df.shape)
print('rates_df.shape():',rates_df.shape)
together = pd.merge(rates_df, pmi_df, on= ['Date'], how='left')
# last valid observation forward
together = together.fillna(method='ffill')
together.tail(20)
As Percentage Change¶
# join both datasets together
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(together['Date'], together['PMI_pct_change'] , color='blue', label='PMI_pct_change')
plt.title('DOW_pct_change, DJTA_pct_change')
plt.plot(together['Date'], together['10_YR_pct_change'], color='green', label='10_YR_pct_change')
plt.axhline(0, color='gray', linewidth=3, linestyle='-.' )
plt.legend()
plt.grid()
plt.show()
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(together['Date'], together['PMI_pct_change'].rolling(window=1, min_periods=1).mean(), color='blue', label='PMI_pct_change')
plt.title('DOW_pct_change, DJTA_pct_change')
plt.plot(together['Date'], together['10_YR_pct_change'].rolling(window=25, min_periods=1).mean()*10, color='green', label='10_YR_pct_change')
plt.axhline(0, color='gray', linewidth=3, linestyle='-.' )
plt.legend()
plt.grid()
plt.show()
cut_off_date = '2015-01-02'
together_tmp = together.copy()
together_tmp = together_tmp[together_tmp['Date'] >= cut_off_date]
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(together_tmp['Date'], together_tmp['PMI_pct_change'].rolling(window=1, min_periods=1).mean(), color='blue', label='PMI_pct_change')
plt.title('DOW_pct_change, DJTA_pct_change')
plt.plot(together_tmp['Date'], together_tmp['10_YR_pct_change'].rolling(window=30, min_periods=1).mean()*10, color='green', label='10_YR_pct_change')
plt.axhline(0, color='gray', linewidth=3, linestyle='-.' )
plt.legend()
plt.grid()
plt.show()
Show Notes
(pardon typos and formatting -these are the notes I use to make the videos)
A PMI Proxy Any Time, Any Day! If this is true, this could come in handy when you need a quick estimate mid-month. Let's roll up our sleeves and find out.