Problem: Invalid quadratic form(s): not a square


(Diego) #1

Hi, everyone.I have problem to solve the following question.

function[Optimo,xoptimo]=OptPortafolioEpsilonInf(Sample,alpha,rho,epsilon)

% Sample is a matrix where amount of rows are amount of assets and
% amount of columns is sample size

[m,N]=size(Sample);       %m is amount of assets and N is size of the sample

cvx_begin
variables x(m) s(N) q(2,N) r(m,N) l
minimize( epsilon*l+(1/N)*sum(s) )
subject to
min(x)>= 0;
sum(x)==1;
diag(((repmat([rho;rho-rho/alpha],1,N)+([x,(1+rho/alpha)*x]')*Muestras)')*q)+ (r')*ones(m,1) <=s;
(max(abs(-([x,(1+rho/alpha)*x]')*q)))' <= l*ones(N,1);
(q')*ones(2,1)==ones(N,1);
r>=0;
q>=0;
cvx_end

Optimo=cvx_optval;
xoptimo=x;

Error

Error using  *  (line 126)
Disciplined convex programming error:
Only scalar quadratic forms can be specified in CVX.

Error in OptPortafolioEpsilonInf (line 20)
diag(((repmat([rho;rho-rho/alpha],1,N)+([x,(1+rho/alpha)*x]')*Muestras)')*q)+ (r')*ones(m,1) <=s;

I have replaced the line where the problem is presented by the following options that are equivalent:

for i=1:N
   [rho,rho-rho/alpha]*q(:,i)+([1,1+rho/alpha]*q(:,i))*((x')*Muestras(:,i))+ones(1,m)*r(:,i)<=s(i);
end

,

 [rho,rho-rho/alpha]*q+([1,1+rho/alpha]*q).*((x')*Muestras)+ones(1,m)*r<=s';

and

 (q')*[rho;rho-rho/alpha]+((q')*[1;1+rho/alpha]).*((Muestras')*x)+(r')*ones(m,1)<=s;

But these still generate errors, in particular generate the following error:

Error using  .*  (line 262)
Disciplined convex programming error:
Invalid quadratic form(s): not a square.


Error in OptPortafolioEpsilonInferior (line 19)
(q')*[rho;rho-rho/alpha]+((q')*[1;1+rho/alpha]).*((Muestras')*x)+(r')*ones(m,1)<=s;

The same error occurs for the other options.

Please help me


(Mark L. Stone) #2

Your code has x times q, in which q and x are both CVX variables. That is not allowed in CVX, and when viewed by itself, is not convex. Why isn't CVX accepting my model? READ THIS FIRST!

If the constraint in question is actually convex, how have you proven it so?