コード例 #1
0
ファイル: main.py プロジェクト: rand-RI/DM
    #Modified Mean-Variance Optimization:
equilibrium_Weights=[0.4,0.6]
#Equilbrium_returns= returns[['EFA','TIP','VNQ']]
#S_P500= pd.load('S&P_500')
#S_P500_returns= srm.logreturns(Returns=S_P500)
Equilbrium_returns= pd.load('Equilibrium_returns')
Equilbrium_returns= srm.logreturns(Returns=Equilbrium_returns) *equilibrium_Weights


#Latex Figures
EM_Asia_xIndia= pd.load('EM_Asia_xIndia')
EM_Asia_xIndia_returns= srm.logreturns(Returns=EM_Asia_xIndia)
"""
US_sectors= pd.load('USsectors')
US_sectors_returns= srm.logreturns(Returns=US_sectors)

UK_sectors= pd.load('UKsectors')
UK_sectors_returns= srm.logreturns(Returns=UK_sectors)

JPN_sectors= pd.load('JPNsectors')
JPN_sectors_returns= srm.logreturns(Returns=JPN_sectors)

CAN_sectors= pd.load('CANsectors')
CAN_sectors_returns= srm.logreturns(Returns=CAN_sectors)
#-------------------------



"""Correlation Surprise"""
    #Import US_Equities, Euro_Equities and Currency data
コード例 #2
0
ファイル: Data.py プロジェクト: rand-RI/DM
Global_Assets=pd.read_csv('Global_Assets.csv', index_col=0)
Global_Assets_timeseries_dataframe=srm.CreateDataFrameWithTimeStampIndex(DataFrame=Global_Assets)
Global_Assets_timeseries_dataframe.save('Table1_Global_Assets')

US_Assets=pd.read_csv('US_Assets.csv', index_col=0)
US_Assets_timeseries_dataframe=srm.CreateDataFrameWithTimeStampIndex(DataFrame=US_Assets)
US_Assets_timeseries_dataframe.save('Table1_US_Assets')

Currency=pd.read_csv('Currency.csv', index_col=0)
Currency_timeseries_dataframe=srm.CreateDataFrameWithTimeStampIndex(DataFrame=Currency)
Currency_timeseries_dataframe.save('Table1_Currency')

#Table 2
Table_2_Asset_Classes=pd.read_csv('MahDis_Table_2.csv', index_col=0)
Asset_Classes_timeseries_dataframe=srm.CreateDataFrameWithTimeStampIndex(DataFrame=Table_2_Asset_Classes)
Asset_Classes_timeseries_dataframe_log_returns=srm.logreturns(Returns=Asset_Classes_timeseries_dataframe) 
Asset_Classes_timeseries_dataframe_log_returns.save('Table2_Asset_Classes')

#Mean-variance optimisation
symbols = ['^GSPC']                                                             #An example of the type of data that would be required for Figure 5 inputs 
Start_Date='1/1/1980'                                    #Date Range for required returns. In the format of MM/DD/YY 
Historical_Pricess = pdio.get_data_yahoo(symbols,start= Start_Date)#Download Historical Prices using symbols as a list of yahoo tickers over the defined start date-end date
Historical_Pricess_closed=Historical_Pricess['Adj Close'].dropna()  
Historical_Pricess_closed.save('S&P_500')  
  
symbols = ['^VIX']                                                             #An example of the type of data that would be required for Figure 5 inputs 
Start_Date,End_Date='2/01/1977','31/12/2014'                                     #Date Range for required returns. In the format of MM/DD/YY 
Historical_Pricess = pdio.get_data_yahoo(symbols,start= Start_Date,end= End_Date)#Download Historical Prices using symbols as a list of yahoo tickers over the defined start date-end date
Historical_Pricess_closed=Historical_Pricess['Adj Close'].dropna()  
Historical_Pricess_closed.save('^VIX')    
  
コード例 #3
0
ファイル: untitled39.py プロジェクト: rand-RI/DM
import numpy as np
import systemicRiskMeasures as srm
import pandas as pd   

US_sectors= pd.load('USsectors')
US_sectors_returns= srm.logreturns(Returns=US_sectors)
      

#(1) absolute weights (MVO_abs_wtgs) 

x_t= [0.2,0.3,0.4]
N= int(np.shape(x_t)[0])
one_n= np.ones((1,N))
MVO_abs_wtgs= x_t/(np.absolute(np.transpose(one_n)*x_t))


## calcalcuate x_T
y=0.2
sigma= US_sectors_returns.cov()
sigma_inv=np.linalg.inv(sigma)
u=np.reshape(np.array(US_sectors_returns.mean()), (1,US_sectors_returns.shape[1]))

x_t=(1/y)*sigma_inv*u




#(2) relative weights (MVO_rel_wtgs)u= returns.mean()
u_t=np.reshape(np.array(US_sectors_returns.mean()), (US_sectors_returns.shape[1],1))
sigma= US_sectors_returns.cov()
one_n= np.ones((1,US_sectors_returns.shape[1]))
コード例 #4
0
ファイル: 02-create-pickles.py プロジェクト: randlow/IC
"""STAGE 1: 
IMPORT LIBRARY"""
import pandas as pd
import systemicRiskMeasures as srm   

"""STAGE 2: 
IMPORT DATA"""
src= pd.read_pickle('sourcedata.pickle')
src_returns= srm.logreturns(Returns=src)

"""STAGE 3: 
IMPORT SYSTEMIC RISK MEASURES AND RUN SIGNALS"""
Input= src_returns.resample('M') #input monthly returns

"""Mahalanobis Distance"""
        #Input
MD_input=Input           #Change this value for data required
        #Run
SRM_mahalanobis= srm.MahalanobisDist(Returns=MD_input)   
SRM_mahalanobis_turbulent_nonturbulent_days= srm.MahalanobisDist_Turbulent_Returns(MD_returns= SRM_mahalanobis, Returns=MD_input)
                    #drop inputs

Input=Input.drop('MD',1)

MD_input= MD_input.drop('MD',1)
       #Graph
SRM_HistoricalTurbulenceIndexGraph= srm.HistoricalTurbulenceIndexGraph_bokeh( Mah_Days=SRM_mahalanobis,  width=30, figsize=(10,2.5), datesize='M')

#-------------------------

Corr_Input= Input
コード例 #5
0
ファイル: main_2.py プロジェクト: rand-RI/DM
    imported from systemicRiskMeasures as srm  in or each Systemic Risk Paper
                                                                                """


                #STAGE 1: IMPORT LIBRARY
import systemicRiskMeasures as srm                                             #Import Systemic Risk Measures library
import pandas as pd
import Mahalanobis_Distance as md
import Correlation_Surprise as cs


                #STAGE 2: IMPORT DATA
    #Mahalanobis Distance
Historical_Prices= pd.load('returns')                                          #Import Historical Prices for six asset-class indices: US stocks, non-US Stocks, US Bonds, non-US bonds, commodities, and US real estate
Adjusted_Close_Prices= Historical_Prices['Adj Close'].dropna()                 #Extract Adjusted Close prices from Historial Prices of the six assets 
returns= srm.logreturns(Returns=Adjusted_Close_Prices)                         #Convert Adjusted Close Prices from daily returns to Logarithmic returns

returns_Figure5= pd.load('returnsMD_Figure5')                                  #Import Daily returns of World Equities, US small-capitalisation premium(Small-Large), growth Premium(Growth-Value) and HFRI Fund of Funds composite Index

Table_1_returns= pd.load('Table_1')                                            #Import Table 1 returns for Global Assets, US assets, US sectors, Currencies, US fixed income, US Treasury notes and US credit

    #Correlation Surprise
Exhibit5_USEquities= pd.load('Exhibit5_US_Equities')        #Import Correlation Surprise Exhibit5 US Equities
Exhibit5_Euro_Equities=pd.load('Exhibit5_Euro_Equities')#Import Correlation Surprise Exhibit5 European Equities
Exhibit5_Currency=pd.load('Exhibit5_Currency')             #Import Correlation Surprise Exhibit5 Currency

    
    #Absorption Ratio
FamaFrench49= pd.load('FenFrench49')                                           #51 sectors
MSCIUS_PRICES= pd.load('MSCIUSA')                                              #MSCI US Index daily prices