-
Notifications
You must be signed in to change notification settings - Fork 10
/
macd.m
23 lines (23 loc) · 844 Bytes
/
macd.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function simObj = macd(simObj, lambda)
% Define MACD based
simObj = simObj.reset(); % reset simulation environment
w_const = ones(simObj.d,1)/simObj.d; % equal weighted portfolio vector
warmup = 50;
short = 10;
long = 50;
std_period = 50;
freq = 1;
for i=1:simObj.T
if mod(i, freq) == 0 && i > warmup
short_ma= mean(simObj.s_hist(:,(i - short + 1):i), 2);
long_ma = mean(simObj.s_hist(:,(i - long + 1):i), 2);
std_stat = std(simObj.s_hist(:,(i - std_period + 1):i), 0, 2);
w_const = exp((short_ma - long_ma) / std_stat) .^ (1/lambda);
% w_const = w_const ./ sum(w_const);
w_const = w_const / sum(w_const);
simObj = simObj.step(w_const);
else
simObj = simObj.step(w_const);
end
end
end