portfolio optimization using fmincon
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nathaniel Comar
le 13 Mar 2017
Commenté : Muhammad Zain Razak
le 26 Juil 2019
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.
1 commentaire
Réponse acceptée
Alan Weiss
le 13 Mar 2017
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!