MATLAB Answers


how to run optimisation problem

Asked by DAN TURMACU on 20 Mar 2019
Latest activity Commented on by DAN TURMACU on 21 Mar 2019
How can I run such kind of optimization :
max Q subject to x = x1,..., xn, where = Rp / σp
and constraints :
Rp = R' * x
σp^2 =x' * Σ * x
sum(x) = 1
Can someone help me about how to write down my objective function ...and the rest of the constraints. What type of sover I need to use ?
Best regards,


I think part of the equations got lost?
What is Q?
You say "where = " but what needs to equal that?
Why do you say "subject to" and list variable names?
In Rp / op is that matrix division (least squared fitting) or is it element-by-element division ?
Q = Rp / σp
Rp - Return of portfolio it is a number
σp - Risk of portfolio it is a number
but R' , Σ are matrix
The constraint is sum(x) = 1.

Sign in to comment.




2 Answers

Answer by DAN TURMACU on 21 Mar 2019
 Accepted Answer

Dear Torsten,
I have another unexpected problem.
When I run x = fmincon(fun,x0,A,b,Aeq,beq) in Command Window, I receive the error message:
Undefined function or variable 'returns'.
Error in @(x)-(x'*returns)/sqrt(x'*sigma*x)
Error in fmincon (line 564)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON
cannot continue.
I do not understand. I provided with returns and sigma matrixes in Workspace Window.
Thank you.


Write a .m file and load it into matlab.
BTW: "returns" must be a vector of the same length as x, not a matrix.
Now it is ok. I have to run fun script first.
Many thanks,

Sign in to comment.

Answer by Torsten
on 21 Mar 2019
Edited by Torsten
on 21 Mar 2019

Use fmincon with objective function
f = @(x)(R'*x)/sqrt(x'*sigma*x)
and linear constraint
Aeq = ones(size(x))
beq = 1
Best wishes


How may I ? I do not know.
f = @(x)-(R'*x)/sqrt(x'*sigma*x)

Sign in to comment.