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 pandas_datareader.data 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
      6 
      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]:
Start='19940131'
Start_Recession_Values='19940101'
End='20140131' #20140630 latest St Louis Recession data date
window_range= 60  #months

FmmaFrench49_from1926=pd.read_pickle('FF49_1926').resample('M').sum().loc[Start:End]
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]:
Input=FmmaFrench49_from1926
Inputs=Input[window_range:]
In [12]:
MD_input=Inputs         #Change this value for data required
        #Run
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]:
Inputs=Inputs.drop('MD',1)
MD_input= MD_input.drop('MD',1)
/home/randlow/github/blog/content/articles/Econometrics/systemicRiskMeasures1.py:69: 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: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  returns['MD']=MD_returns
In [ ]:
Corr_Input= Inputs
        #Run
SRM_Correlation_Surprise=srm.Correlation_Surprise(Returns=Corr_Input)  #need to reshift by 41 months
        #Graph
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
    #Graphs
srm.plot_AR(AR=SRM_absorptionratio, figsize=(10,2.5),yaxis=[0.84,0.92])

Comments

Comments powered by Disqus