-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulate_hrp_riskfolio_agent.py
149 lines (139 loc) · 4.69 KB
/
simulate_hrp_riskfolio_agent.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from datetime import datetime
import pickle
from simulate_agent import parallel_simulate_agent, simulate_agent
if __name__ == "__main__":
from trading_gym.agents.hrp_riskfoliolib import HRPAgent
from trading_gym.utils.screener import Screener
assets_data = pickle.load(open("./assets_data_testing.pickle", "rb"))
# windows = [260, 180, 60, 30]
# screeners = [
# Screener("returns", 10, 15),
# Screener("returns", 5, 15),
# Screener("returns", 10, 5),
# Screener("returns", 5, 5),
# ]
# model = "HRP"
# codependences = [
# "pearson",
# "spearman",
# "abs_pearson",
# "abs_spearman",
# "distance",
# "mutual_info",
# "tail",
# ]
# covariances = ["hist", "ewma1", "ewma2", "ledoit", "oas", "shrunk"]
# objectives = ["MinRisk", "Sharpe"]
# risk_measures = [
# "MV",
# "MSV",
# "FLPM",
# "SLPM",
# "VaR",
# "CVaR",
# "WR",
# "MDD",
# ]
# leaf_orders = [True, False]
# params_grid = []
# for w in windows:
# for screener in screeners:
# for codependence in codependences:
# for covariance in covariances:
# for objective in objectives:
# for risk_measure in risk_measures:
# for leaf_order in leaf_orders:
# params_grid.append(
# {
# "window": w,
# "screener": screener,
# "model": model,
# "rebalance_each_n_obs": 7,
# "codependence": codependence,
# "covariance": covariance,
# "objective": objective,
# "risk_measure": risk_measure,
# "leaf_order": leaf_order,
# }
# )
params_grid = [
{
"window": 180,
"screener": [
Screener("volume", 200, 15),
Screener("volatility", 50, 15),
Screener("returns", 10, 15),
],
"model": "HRP",
"rebalance_each_n_obs": 7,
"codependence": "pearson",
"covariance": "hist",
"objective": "Sharpe",
"risk_measure": "MV",
"leaf_order": True,
"w_min": 0.05,
"w_max": 0.35,
}
]
start = datetime(2019, 5, 1)
end = datetime(2022, 1, 17)
start_eval_date = datetime(2021, 1, 1)
# n_obs_volatility = [5, 15, 30]
# n_obs_returns = [5, 15, 30]
# n_assets_volatility = [30, 60, 90]
# n_assets_returns = [5, 10, 15, 20]
# windows = [180, 60, 30]
# params_grid = []
# for n_obs_vol in n_obs_volatility:
# for n_obs_ret in n_obs_returns:
# for n_assets_vol in n_assets_volatility:
# for n_assets_ret in n_assets_returns:
# for window in windows:
# params_grid.append(
# {
# "window": window,
# "screener": [
# Screener("volume", 200, 15),
# Screener("volatility", n_assets_vol, n_obs_vol),
# Screener("returns", n_assets_ret, n_obs_ret),
# ],
# "model": "HRP",
# "rebalance_each_n_obs": 7,
# "codependence": "pearson",
# "covariance": "hist",
# "objective": "Sharpe",
# "risk_measure": "MDD",
# "leaf_order": True,
# "w_min": 0.05,
# "w_max": 0.35,
# }
# )
# start = datetime(2018, 5, 1)
# end = datetime(2021, 1, 1)
# start_eval_date = datetime(2019, 1, 1)
# TESTING
# params_grid = [{"window": 180, "screener": Screener("returns", 10, 15)}]
# start = datetime(2020, 5, 1)
# end = datetime(2022, 1, 12)
# TESTING WEEKLY REB
# params_grid = [
# {
# "window": 180,
# "screener": Screener("returns", 10, 15),
# "codependence": "pearson",
# "objective": "Sharpe",
# "rebalance_each_n_obs": 7,
# },
# ]
# start = datetime(2020, 5, 1)
# end = datetime(2022, 1, 12)
simulate_agent(
assets_data=assets_data,
start=start,
end=end,
fee=0.01,
agent_class=HRPAgent,
cash=True,
agent_params_grid=params_grid,
file_suffix="testing_today",
)