I am trying to implement the following equality constraint for using it in fmincon:
and TargetVariance is a fixed numeric value. The size of w is 1xN.
This is a minimal example of my code.
Mu = [.1, .15, .12];
Cov = [.3, .1, .2;
.1, .5, .1;
.2, .1, .7];
N = numel(Mu);
one = ones(1,N);
NegPFMu = @(w) -Mu * w';
w0 = one * (1/N);
Aeq = one;
beq = 1;
lb = zeros(1,N);
wopt = fmincon(NegPFMu, w0, , , Aeq, beq, lb);
Can you help me with the constraint?
I was thinking about something like the following but I don't how to call that as my nonlcon then.
function [c, ceq] = mycon(w, Cov, TargetVariance)
PortfolioVariance = @(w) w*Cov*w'
ceq = PortfolioVariance(w) - Targetvariance;
c = ;
Could you help me please?