Estimating systemic risk on the equities market

This post is about replicating the Turbulence Index, Correlation Surprise, and Absorption Ratio that was publisehd in Journal of Portfolio Management by Mark Kritzman of Wyndham Capital. Stay tuned!

In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
import systemicRiskMeasures1 as srm   

import os
from pprint import pprint

pd.core.common.is_list_like = pd.api.types.is_list_like # Quick-fix for version compatibility correct version compatability.
import as web  # module for reading datasets directly from the web
from pandas_datareader.famafrench import get_available_datasets
ModuleNotFoundError       Traceback (most recent call last)
<ipython-input-1-91eb8522a543> in <module>
      3 import matplotlib.pyplot as plt
      4 import scipy as sp
----> 5 import systemicRiskMeasures1 as srm
      7 import os

ModuleNotFoundError: No module named 'systemicRiskMeasures1'
In [7]:
datasets = get_available_datasets()
print('No. of datasets:{0}'.format(len(datasets)))
#datasets #comment out if you want to see all the datasets
No. of datasets:286
In [9]:
End='20140131' #20140630 latest St Louis Recession data date
window_range= 60  #months

Recession_Values= pd.read_pickle('USARECM')
VIX_returns= pd.read_pickle('^VIX').resample('M').mean().loc[Start:End]

Balanced_port= srm.logreturns(Returns=pd.read_pickle('Probit_portfolio')).resample('M').sum().loc[Start:End]
Recession_Values= Recession_Values[Start_Recession_Values:] 

t1 = pd.read_pickle('Probit_portfolio')
SP500_TB= pd.read_pickle('Probit_portfolio').resample('M').mean().loc[Start:End]
In [10]:
In [12]:
MD_input=Inputs         #Change this value for data required
SRM_mahalanobis= srm.MahalanobisDist(Returns=MD_input)[17:]   
In [13]:
SRM_mahalanobis_turbulent_nonturbulent_days= srm.MahalanobisDist_Turbulent_Returns(MD_returns= SRM_mahalanobis, Returns=MD_input)
                    #drop inputs
In [11]:
MD_input= MD_input.drop('MD',1)
/home/randlow/github/blog/content/articles/Econometrics/ SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation:
In [ ]:
Corr_Input= Inputs
SRM_Correlation_Surprise=srm.Correlation_Surprise(Returns=Corr_Input)  #need to reshift by 41 months
srm.Corr_plot(Corr_sur=SRM_Correlation_Surprise[0][17:], Mag_sur=SRM_Correlation_Surprise[1][17:],  width=25, figsize=(10,4.5), datesize='M')
In [ ]:
AR_input= Inputs
SRM_absorptionratio= srm.Absorption_Ratio(Returns= AR_input, halflife=int(8.5))                        #define Absorption Ratio
srm.plot_AR(AR=SRM_absorptionratio, figsize=(10,2.5),yaxis=[0.84,0.92])


Comments powered by Disqus