I am trying to predict the weights for my stocks that optimize my portfolio by reducing variance. My equation that I am using to predict the variance is
>>function f = varmin(x,VCV) >>f = ((x' * VCV) * x);
where x is the weights and VCV is the variance covariance matrix. Every time I run the program fmincon, I get an error relating to my function "varmin" saying
>>Not enough input arguments.
>>Error in varmin (line 2) >>f = ((x' * VCV) * x);
>>error in fmincon (line 536) >> initVals.f = feval(funfcn{3},X,varargin{:});
>>Caused by: >> Failure in initial objective function evaluation. FMINCON cannot >>continue.
this is what the fmincon equation looks like
>>w = fmincon('varmin',x,a,b,Aeq,Beq,MinWt,MaxWt);
if anyone has any advice that would be greatly appreciated.

 채택된 답변

Alan Weiss
Alan Weiss 2017년 3월 13일

1 개 추천

If VCV is a given matrix in your workspace, take
fun = @(x)x'*VCV*x;
and then call
w = fmincon(fun,x,a,b,Aeq,Beq,MinWt,MaxWt);
Make sure that your initial x (which I would call x0) is a column vector.
Alan Weiss
MATLAB mathematical toolbox documentation

댓글 수: 6

Nathaniel Comar
Nathaniel Comar 2017년 3월 13일
편집: Nathaniel Comar 2017년 3월 13일
That did not work. My objective function is now
function f = varmin(x0,VCV)
f = @(x0)x0'*VCV*x0;
And the fmincon equation is
w = fmincon(varmin,x0,a,b,Aeq,Beq,MinWt,MaxWt);
And i received the error
Error: File: varmin.m Line: 2 Column: 8
Unexpected MATLAB expression.
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
Alan Weiss
Alan Weiss 2017년 3월 13일
Please read my previous answer and use it verbatim.
Alan Weiss
MATLAB mathematical toolbox documentation
Nathaniel Comar
Nathaniel Comar 2017년 3월 13일
편집: Nathaniel Comar 2017년 3월 13일
I believe I did. I do not see the discrepency you are referring to. Could you please tell me?
I'm sorry that I was not clear.
Please try the following. Do not use your varmin function. Instead, once you have the VCV matrix in your workspace, at the MATLAB command line issue the command
fun = @(x)x'*VCV*x;
Then, once you have all the other relevant inputs in your workspace (such as x, a, b, etc.), issue the command
w = fmincon(fun,x,a,b,Aeq,Beq,MinWt,MaxWt);
Alan Weiss
MATLAB mathematical toolbox documentation
Nathaniel Comar
Nathaniel Comar 2017년 3월 13일
편집: Nathaniel Comar 2017년 3월 13일
Ah thank you for clarifying. I got it to work. Thank you for your help
Muhammad Zain Razak
Muhammad Zain Razak 2019년 7월 26일
Hi
Does the VCV is the 3x3 matrix?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by