Supplied objective function must return a scalar value
Afficher commentaires plus anciens
When I analyze the stock's return style through share model,I want to determine the sensitive coefficients through the fmincon code of Matlab. However, I encounter some problem about "supplied objective function must return a scalar value", anyone who can help me? Thank you very much.
E=xlsread("data.xlsx")
F=E(:,1) % the target stock return time series (with 755*6 matrix)
G=E(:,2) % the large cap return time series (with 755*1 matrix)
H=E(:,3) % the mid cap return time series (with 755*1 matrix)
I=E(:,4) % the small cap return time series (with 755*1 matrix)
J=E(:,5) % the aggregate bond return time series (with 755*1 matrix)
K=E(:,6) % the treasury time series (with 755*1 matrix)
Benchmark=[G,H,I,J,K]
fun=@(x)var(F-Benchmark.*x) % establishing the objective function (with 1*1 value)
x0=[0,0,0,0,1] % the initial point
A=[]
b=[] % no inequity constraints
Aeq=ones(1,5)
beq=1 % equity constraints
lb=zeros(1,5) % lower bound
ub=ones(1,5) % upper bound
x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
In principle, the output of x should be a 5*1 matrix. However, I always get the error that "supplied objective function must return a scalar value". In fact, fun can be handled with value. So I can not understand the "supplied objective function mus t trturn a scalar value". Anyone who can help me? Thank you very much. The data is included in the attachment.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
