-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminAvTurn.asv
More file actions
34 lines (24 loc) · 817 Bytes
/
Copy pathminAvTurn.asv
File metadata and controls
34 lines (24 loc) · 817 Bytes
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
function x = minAvTurn(mu, Q, x0)
% Minimizing average turnover
% Find the total number of assets
n = size(Q,1);
% Disallow short sales
lb = zeros(n,1);
% constrain weights to sum to 1
Aeq = ones(1,n);
beq = 1;
% Set the target as the average expected return of all assets
targetRet = mean(mu);
% Set inequality constraint on target return
A = -mu.';
b = -targetRet;
% Get max asset return and index from mu
[m, i] = max(mu);
% Set fmincon options
options = optimoptions('fmincon','Algorithm','sqp');
% Optimal asset weights using fmincon
ip = zeros(n,1);
ip(i) = 1;
obj = @(x) (norm(x-x0,2));
x = fmincon(obj, ip, A, b, Aeq, beq, lb, [], [], options);
end