-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (47 loc) · 2.19 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from riskpremia import *
if __name__ == '__main__':
from pandas_datareader import data as web
###################
########### ff5 factor #############
#################
port = pd.read_csv('D:/workspace/project/Risk premia Estimation/data/port.csv', index_col=[0],
parse_dates=[0]).dropna()
port /= 100
ff_factor = 'F-F_Research_Data_5_Factors_2x3'
ff_factor_data = web.DataReader(ff_factor, 'famafrench', start=port.index[0])[0]
ff_factor_data.index = ff_factor_data.index.to_timestamp()
ff_factor_data /= 100
start, end = max(port.index[0], ff_factor_data.index[0]), min(port.index[-1], ff_factor_data.index[-1])
ff_factor_data = ff_factor_data.loc[start:end]
port = port.loc[start:end]
port = port - ff_factor_data['RF'].values.reshape(-1, 1)
Est = Estimator(port, ff_factor_data[['Mkt-RF', 'SMB', 'HML', 'RMW', 'CMA']])
res_two = Est.two_pass(True, lag=1).T
res_three = Est.three_pass(max_k=300, lag=1).T
print(res_two)
print(res_three)
################
##### Macro Factor ####
#############
"""
The macro factors were constructed based on the methodology(=Mimicking Portfolios) of
Macro Factor-Mimicking Portfolios (2022).
"""
macro = pd.read_csv('D:/workspace/project/Risk premia Estimation/data/macro.csv',
index_col=[0], parse_dates=[0])[
['growth', 'inflation', 'real_rates', 'credit', 'currency', 'liquidity', 'tail_risk']]
port = pd.read_csv('D:/workspace/project/Risk premia Estimation/data/port.csv', index_col=[0],
parse_dates=[0]).dropna()
port /= 100
start, end = max(port.index[0], macro.index[0]), min(port.index[-1], macro.index[-1])
macro = macro.loc[start:end]
port = port.loc[start:end]
ff_factor = 'F-F_Research_Data_5_Factors_2x3'
ff_factor_data = web.DataReader(ff_factor, 'famafrench', start=port.index[0], end=port.index[-1])[0]
ff_factor_data /= 100
port = port - ff_factor_data['RF'].values.reshape(-1, 1)
Est = Estimator(port, macro)
res_two = Est.two_pass(True, lag=1).T
res_three = Est.three_pass(max_k=300, lag=1).T
print(res_two)
print(res_three)