Minimising the variance of a portfolio using weights of assets and covariance matrix
1 回表示 (過去 30 日間)
古いコメントを表示
Shaun King
2020 年 4 月 5 日
コメント済み: Shaun King
2020 年 4 月 5 日
I have the formula for the variance of a portfolio
variance = transpose(weight)* covariance * weights
where the covariance(covR) is a 10*10 matrix and the weights(w) are a 10*1 matrix
I am trying to minimize the weights while having the constraints that the weights fall between 0 and 0.1
var = @ (w) w'*corR*w
I have tried to use the quadprog function, but I still can't seem to get the right answer.
Could anyone help ?
2 件のコメント
Thiago Henrique Gomes Lobato
2020 年 4 月 5 日
編集済み: Thiago Henrique Gomes Lobato
2020 年 4 月 5 日
Why you believe you don't get the right answer? Quadprog should actually work, here is a minimalist example:
rng(42)
corR = randn(10,10);
corR = convR+eye(10)-diag(corR); % 1 diagonal
corR = 1/2*(corR+corR'); % Covariance is symmetric
lb = zeros(10,1);
up = ones(10,1)*0.1; % changing this to 0.08, 0.09 or other value may be helpful depending of your matrix
f = zeros(10,1); % no f
[x,fval,IsGlobalMin] = quadprog(corR,f,[],[],[],[],lb,up)
採用された回答
Thiago Henrique Gomes Lobato
2020 年 4 月 5 日
If you have the additional constrain that the weights must sum to 1 than you must also increase the lower bound. Otherwise the only feasible solution is that all of them equal 0.1, so the sum is 1. Saying this you have an equality constrain that the sum of all weightings equal ones, this can be done using the Aeq and Beq options, a full example:
rng(42)
convR = randn(10,10);
convR = convR+eye(10)-diag(convR);
convR = 1/2*(convR+convR');
lb = zeros(10,1);
up = ones(10,1)*0.15;% changing this may be helpful depending of your matrix
f = zeros(10,1);
% Equality constrain
Aeq = zeros(10);
Aeq(1,1:10) = 1;
beq = zeros(10,1);
beq(1) = 1;
[x,fval,IsGlobalMin] = quadprog(convR,f,[],[],Aeq,beq,lb,up)
sum(x) % Sum of x
Aeq*beq % first element is sum of x
Another option in order to retain your initial constrain of 0.1 is just to normalize the result:
x = x/sum(x);
その他の回答 (1 件)
Ameer Hamza
2020 年 4 月 5 日
編集済み: Ameer Hamza
2020 年 4 月 5 日
As Thiago pointed out, you can use Quadprog, and in this case, it will work, but the portfolio optimization model can become quite complex, which cannot be handled by quadprog. So this shows you a general way to handle your optimization problem, and implement the constraint that the sum of all portfolios should be one. Remember, in this case, the upper limit of 0.1 does not make sense because if there are 10 portfolios, then each one will take the value of 0.1, so I placed the upper limit of 1 on each portfolio.
A = ones(1,10); % A and B define A*x = B constraint
B = 1;
lb = zeros(size(corR,1), 1);
ub = ones(size(corR,1), 1);
obj_fun = @(w) w*corR*w'; % objective function
q = fmincon(obj_fun, rand(1,10), [], [], A, B, lb, ub);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Portfolio Optimization and Asset Allocation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!