Business Sentiment Indicators - Hands-On With Market Analysis with Python
Introduction
Let's get a handle on business sentiment by looking at the PMI, BCI, CPPI and, of course, the SPY, DOW, and Russel 2000. I'll show you where to get the data and run some simple charts to get a feel of what is going on.
Code
from IPython.display import Image
Image(filename='viralml-book.png')
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.dates as mdates
from mpl_finance import candlestick_ohlc
mpl.style.use('default')
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-09-16/'
Data Required¶
S&P 500 (^GSPC)
https://finance.yahoo.com/quote/%5EGSPC/history?p=%5EGSPC
Russell 2000 (^RUT)
https://finance.yahoo.com/quote/%5ERUT/history?p=^RUT
Dow Jones Industrial Average (^DJI)
https://finance.yahoo.com/quote/%5EDJI
BCI - Business confidence index
This business confidence indicator provides information on future developments, based upon opinion surveys on developments in production, orders and stocks of finished goods in the industry sector. It can be used to monitor output growth and to anticipate turning points in economic activity. Numbers above 100 suggest an increased confidence in near future business performance, and numbers below 100 indicate pessimism towards future performance.
https://data.oecd.org/leadind/business-confidence-index-bci.htm
PMI Composite Index
Purchasing Managers' Indexes (PMI) are economic indicators derived from monthly surveys of private sector companies.
https://www.quandl.com/data/ISM/MAN_PMI-PMI-Composite-Index
Green Street Commercial Property Price Index
https://www.greenstreetadvisors.com/insights/CPPI
S&P 500 (^GSPC)¶
sp500_df = pd.read_csv(path_to_market_data + '^GSPC.csv')
sp500_df['Date'] = pd.to_datetime(sp500_df['Date'])
sp500_df = sp500_df[['Date','Adj Close']]
sp500_df.columns = ['Date', 'SP500_Close']
print(np.min(sp500_df['Date'] ),np.max(sp500_df['Date'] ))
sp500_df = sp500_df.sort_values('Date', ascending=True) # sort in ascending date order
sp500_df.tail()
Russell 2000 (^RUT)¶
ru2000_df = pd.read_csv(path_to_market_data + '^RUT.csv')
ru2000_df['Date'] = pd.to_datetime(ru2000_df['Date'])
ru2000_df = ru2000_df[['Date','Adj Close']]
ru2000_df.columns = ['Date', 'RUS_Close']
print(np.min(ru2000_df['Date'] ),np.max(ru2000_df['Date'] ))
ru2000_df = ru2000_df.sort_values('Date', ascending=True) # sort in ascending date order
ru2000_df.tail()
Dow Jones Industrial Average (^DJI)¶
dji_df = pd.read_csv(path_to_market_data + '^DJI.csv')
dji_df['Date'] = pd.to_datetime(dji_df['Date'])
dji_df = dji_df[['Date','Adj Close']]
dji_df.columns = ['Date', 'DOW_Close']
print(np.min(dji_df['Date'] ),np.max(dji_df['Date'] ))
dji_df = dji_df.sort_values('Date', ascending=True) # sort in ascending date order
dji_df.tail()
ru2000_df_tmp = ru2000_df.copy()
sp500_df_tmp = sp500_df.copy()
dji_df_tmp = dji_df.copy()
cut_off_date = '2015-01-01'
ru2000_df_tmp = ru2000_df_tmp[ru2000_df_tmp['Date'] >= cut_off_date]
sp500_df_tmp = sp500_df_tmp[sp500_df_tmp['Date'] >= cut_off_date]
dji_df_tmp = dji_df_tmp[dji_df_tmp['Date'] >= cut_off_date]
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(ru2000_df_tmp['Date'], ru2000_df_tmp['RUS_Close'], label='RUS_Close', color='blue')
plt.legend(loc='lower right')
plt.title('RUS_Close & SP500 - ' + str(np.max(ru2000_df_tmp['Date']))[0:10])
plt.grid()
# Get second axis
ax2 = ax.twinx()
plt.plot(sp500_df_tmp['Date'], sp500_df_tmp['SP500_Close'], label='SP500_Close',color='green')
plt.legend(loc='upper left')
ax3 = ax.twinx()
plt.plot(dji_df_tmp['Date'], dji_df_tmp['DOW_Close'], label='DOW_Close',color='red')
plt.legend(loc='lower left')
plt.show()
BCI - Business confidence index¶
https://data.oecd.org/leadind/business-confidence-index-bci.htm
bci_df = pd.read_csv(path_to_market_data + 'DP_LIVE_17092019082247898.csv')
bci_df = bci_df[bci_df['LOCATION'] == 'USA']
bci_df['Date'] = bci_df['TIME'] + '-01'
bci_df['Date'] = pd.to_datetime(bci_df['Date'])
bci_df = bci_df.sort_values('Date', ascending=True) # sort in ascending date order
bci_df = bci_df[['Date','Value']]
bci_df.columns = ['Date', 'BCI']
print(np.min(bci_df['Date'] ),np.max(bci_df['Date'] ))
bci_df.tail()
bci_df_tmp = bci_df.copy()
sp500_df_tmp = sp500_df.copy()
cut_off_date = '2007-01-01'
bci_df_tmp = bci_df_tmp[bci_df_tmp['Date'] >= cut_off_date]
sp500_df_tmp = sp500_df_tmp[sp500_df_tmp['Date'] >= cut_off_date]
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(bci_df_tmp['Date'], bci_df_tmp['BCI'], label='BCI', color='blue')
plt.legend(loc='lower right')
plt.title('BCI & SP500 - ' + str(np.max(bci_df_tmp['Date']))[0:10])
plt.grid()
plt.axhline(100, color='gray', linewidth=3, linestyle='-.' )
# Get second axis
ax2 = ax.twinx()
plt.plot(sp500_df_tmp['Date'], sp500_df_tmp['SP500_Close'], label='SP500_Close',color='black')
plt.legend(loc='upper left')
plt.show()
Purchasing Managers' Index - PMI Composite Index¶
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.tail()
pmi_df_tmp = pmi_df.copy()
sp500_df_tmp = sp500_df.copy()
cut_off_date = '2007-01-01'
pmi_df_tmp = pmi_df_tmp[pmi_df_tmp['Date'] >= cut_off_date]
sp500_df_tmp = sp500_df_tmp[sp500_df_tmp['Date'] >= cut_off_date]
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(pmi_df_tmp['Date'], pmi_df_tmp['PMI'], label='PMI', color='blue')
plt.legend(loc='lower right')
plt.title('PMI & SP500 - ' + str(np.max(pmi_df_tmp['Date']))[0:10])
plt.grid()
plt.axhline(50, color='gray', linewidth=3, linestyle='-.' )
# Get second axis
ax2 = ax.twinx()
plt.plot(sp500_df_tmp['Date'], sp500_df_tmp['SP500_Close'], label='SP500_Close',color='black')
plt.legend(loc='upper left')
plt.show()
Real Estate¶
Green Street Commercial Property Price Index¶
cppi_df = pd.read_csv(path_to_market_data + 'CPPI.csv') #, sep='\t')
cppi_df['Date'] = pd.to_datetime(cppi_df['Date'])
cppi_df.columns = ['Date', 'CPPI_All_Property' , 'CPPI_Core_Sector']
print('cppi_df:', np.min(cppi_df['Date']), np.max(cppi_df['Date']))
cppi_df.tail()
cppi_df_tmp = cppi_df.copy()
sp500_df_tmp = sp500_df.copy()
cut_off_date = '2007-01-01'
cppi_df_tmp = cppi_df_tmp[cppi_df_tmp['Date'] >= cut_off_date]
sp500_df_tmp = sp500_df_tmp[sp500_df_tmp['Date'] >= cut_off_date]
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(cppi_df_tmp['Date'], cppi_df_tmp['CPPI_All_Property'], label='CPPI_All_Property', color='blue')
plt.legend(loc='lower right')
plt.title('CPPI_All_Property & SP500 - ' + str(np.max(cppi_df_tmp['Date']))[0:10])
plt.grid()
# Get second axis
ax2 = ax.twinx()
plt.plot(sp500_df_tmp['Date'], sp500_df_tmp['SP500_Close'], label='SP500_Close',color='black')
plt.legend(loc='upper left')
plt.show()
Show Notes
(pardon typos and formatting -these are the notes I use to make the videos)
Let's get a handle on business sentiment by looking at the PMI, BCI, CPPI and, of course, the SPY, DOW, and Russel 2000. I'll show you where to get the data and run some simple charts to get a feel of what is going on.