-
Notifications
You must be signed in to change notification settings - Fork 10
/
hierarchial.m
38 lines (37 loc) · 1.24 KB
/
hierarchial.m
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
function simObj = hierarchial(simObj, lambda, warmup, freq)
if nargin < 2
lambda = 0.5;
warmup = 30;
freq = 30;
end
if nargin < 3
warmup = 30;
freq = 30;
end
if nargin <4
freq = 30;
end
% Cluster stocks together by return?
% assign weight to each cluster
% assign weight to each asset in cluster
% https://uk.mathworks.com/help/stats/cluster-analysis.html
% https://colab.research.google.com/drive/1IpYLBmVwAnL1g_99o5BIhcZ9V6_Ij0j7
% https://uk.mathworks.com/help/stats/hierarchical-clustering-12.htm
% https://uk.mathworks.com/matlabcentral/fileexchange/70186-asset-allocation-hierarchical-risk-parity
simObj = simObj.reset(); % reset simulation environment
% equal weighted portfolio vector
for i=1:simObj.T
if i < warmup
w_const = ones(simObj.d,1)/simObj.d;
else
if mod(i, freq) == 0
rets = diff(log(simObj.s_hist(:,1:i)),1,2);
assetCovar = cov(rets');
wgtHRP = allocByBisectHRP(assetCovar);
w_const = wgtHRP;
w_const = w_const ./ sum(w_const);
end
end
simObj = simObj.step(w_const) ;
end
end