-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmodifyUMultiple.m
61 lines (53 loc) · 1023 Bytes
/
modifyUMultiple.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function [uBuy,uSell] = modifyUMultiple(portfolio,numStocks,minOpt,maxOpt,currentSD)
Inv = portfolio';
portfolio = sqrt(portfolio'*currentSD*portfolio); %risk adjusted portfolio
min = minOpt;
max = maxOpt;
uBuy = 1;
uSell = 1;
step = 0.5;
indices = 1:step:5;
if mod(5,step) ~= 0 %to make sure 5 is actually in the vector
indices = [indices 5];
end
l=length(indices);
diff = max - min;
inc = diff/(l-2);
threshold = min:inc:max;
k=0;
for i=(l-1):(-1):1
if abs(portfolio)>threshold(i)
k=i;
break
end
end
if (k~=0 & portfolio>0)
if k==l
uBuy = 0;
end
uSell = indices(k);
end
if (k~=0 & portfolio<0)
if k==l
uSell = 0;
end
uBuy = indices(k);
end
ub = uBuy;
us = uSell;
uBuy = ones(1,numStocks);
uSell = ones(1,numStocks);
for i = 1:numStocks
if(isnan(Inv(i)) == 0 && Inv(i) ~=0)
if(Inv(i) < 0)
uBuy(i) = us;
uSell(i) = 1;
else
uBuy(i) = 1;
uSell(i) = us;
end
else
uBuy(i) = 1;
uSell(i) = 1;
end
end