Get the "Applied Data Science Edge"!

The ViralML School

Fundamental Market Analysis with Python - Find Your Own Answers On What Is Going on in the Financial Markets

Web Work

Python Web Work - Prototyping Guide for Maker

Use HTML5 Templates, Serve Dynamic Content, Build Machine Learning Web Apps, Grow Audiences & Conquer the World!

Hot off the Press!

The Little Book of Fundamental Market Indicators

My New Book: "The Little Book of Fundamental Analysis: Hands-On Market Analysis with Python" is Out!

US Bankruptcies and the S&P 500 - Market Analysis Hands-On with Python

Introduction

Lets look at US non-business bankruptcies and its relationship to the S&P 500. Welcome to another market analysis hands-on with Python video. MORE: Blog or code: http://www.viralml.com/video-content.html?fm=yt&v=f0Krmmo2mAw Signup for my newsletter and more: http://www.viralml.com Connect on Twitter: https://twitter.com/amunategui Check out my book on Amazon The Little Book of Fundamental Market Indicators https://amzn.to/2DERG3d Transcript Hello YouTube Friends This is another market analysis hands-on with Python video. In this episode, we are going to look at US non-business bankruptcies - it isnt a super fun data set, like cancer or crime but there is an interesting relationship with the market that I think is interesting to note. This is the final product, the final chart I will show you how to create. Welcome to the ViralML Show, my name is Manuel Amunategui. I am the author of a few books including a new one that will be out at the end of the month The Little Book of Fundamental Indicators where I share my favorite hands-on market analysis fundamental indicators and data sets. Things like the S&P500, unemployment, real estate, CPI, VIX, etc. Please signup for my newsletter to get early access to my material. Subscribe to the channel - and give it a big thumbs up, pretty please! As usual, the link to the Jupiter notebook is included in the description of this video. There is some manual labor involved in gathering all the needed data. I already did all that work for you up to 2018 and included it in the corresponding Jupyter notebook for this chapter. Navigate to the “Caseload Statistics Data Tables” page on the United States. Courts website1. Follow the same selections as per the screenshots below.1 https://www.uscourts.gov/statistics-reports/caseload-statistics-data-tables CATEGORY:Finance HASCODE:ViralML-Hands-On-Market-Analysis-Bankruptcy-Filings.html



If you liked it, please share it:

Code

Bankruptcy Filings vs S&P500
In [12]:
from IPython.display import Image
Image(filename='viralml-book.png')
Out[12]:
In [6]:
%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
from random import randint
In [8]:
# get the SP500 (^GSPC) from Yahoo Finace
gspc_df = pd.read_csv('^GSPC.csv')
gspc_df['Date'] = pd.to_datetime(gspc_df['Date'])
gspc_df = gspc_df[['Date', 'Adj Close']]
gspc_df.columns = ['Date', 'SP500_Value']
gspc_df['SP500_pct_change'] = gspc_df['SP500_Value'].pct_change()
gspc_df.head()
Out[8]:
Date SP500_Value SP500_pct_change
0 1950-01-03 16.66 NaN
1 1950-01-04 16.85 0.011405
2 1950-01-05 16.93 0.004748
3 1950-01-06 16.98 0.002953
4 1950-01-09 17.08 0.005889

Create Bankruptcy Filings data set and assign actual date

In [9]:
year_ls = [str(y) + '-12-31'  for y in range(2001, 2019)]
total_noncom_filings = [1452030,1539111,1625208,1563145,2039214,597965,822590,
                        1074225,1412838,1536799,1362847,1181016,1038720,909812,
                        819760,770846,765863,751186]
bankruptcy_filings = pd.DataFrame({'Date':year_ls, 'Filings': total_noncom_filings})
bankruptcy_filings['Date'] = pd.to_datetime(bankruptcy_filings['Date'])
cut_off_date = '2001-01-01'

gspc_df = gspc_df[gspc_df['Date'] >= cut_off_date]
bankruptcy_filings.head()
Out[9]:
Date Filings
0 2001-12-31 1452030
1 2002-12-31 1539111
2 2003-12-31 1625208
3 2004-12-31 1563145
4 2005-12-31 2039214
In [10]:
# join both datasets together
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(gspc_df['Date'], gspc_df['SP500_Value'], '-b', label='S&P500')

plt.legend()
plt.grid()
ax.tick_params('vals', colors='r')

# Get second axis
ax2 = ax.twinx()
plt.plot(bankruptcy_filings['Date'], bankruptcy_filings['Filings'], linewidth=2, color='black', label='Filings')
plt.legend()
plt.title('Bankruptcy Filings vs S&P 500')
ax2.tick_params('vals', colors='b')

Show Notes

(pardon typos and formatting -
these are the notes I use to make the videos)

Lets look at US non-business bankruptcies and its relationship to the S&P 500. Welcome to another market analysis hands-on with Python video. MORE: Blog or code: http://www.viralml.com/video-content.html?fm=yt&v=f0Krmmo2mAw Signup for my newsletter and more: http://www.viralml.com Connect on Twitter: https://twitter.com/amunategui Check out my book on Amazon The Little Book of Fundamental Market Indicators https://amzn.to/2DERG3d Transcript Hello YouTube Friends This is another market analysis hands-on with Python video. In this episode, we are going to look at US non-business bankruptcies - it isnt a super fun data set, like cancer or crime but there is an interesting relationship with the market that I think is interesting to note. This is the final product, the final chart I will show you how to create. Welcome to the ViralML Show, my name is Manuel Amunategui. I am the author of a few books including a new one that will be out at the end of the month The Little Book of Fundamental Indicators where I share my favorite hands-on market analysis fundamental indicators and data sets. Things like the S&P500, unemployment, real estate, CPI, VIX, etc. Please signup for my newsletter to get early access to my material. Subscribe to the channel - and give it a big thumbs up, pretty please! As usual, the link to the Jupiter notebook is included in the description of this video. There is some manual labor involved in gathering all the needed data. I already did all that work for you up to 2018 and included it in the corresponding Jupyter notebook for this chapter. Navigate to the “Caseload Statistics Data Tables” page on the United States. Courts website1. Follow the same selections as per the screenshots below.1 https://www.uscourts.gov/statistics-reports/caseload-statistics-data-tables CATEGORY:Finance HASCODE:ViralML-Hands-On-Market-Analysis-Bankruptcy-Filings.html