Hi,
I am trying to write a simple optimization problem in mata. I have to find the vector of weights which minimizes a function (the other matrices are external and I label them as such in the code). However, for some reason it keeps returning an error that S is not found. Any ideas on what the problem could be?
mata
void triald1(todo,w, y, g, H)
{
external varcov,vol
y = (w'*vol)*(w'*varcov*w)
}
end
corrmat retioous retvxxus retjph retdbcus , covmat
matrix define varcov=r(cov)
matrix define vol=J(4,1,.)
matrix define vol[1,1]=varcov[1,1]
matrix define vol[2,1]=varcov[2,2]
matrix define vol[3,1]=varcov[3,3]
matrix define vol[4,1]=varcov[4,4]
mata
init=J(4,1,0)
C=(1,1,1,1)
c=(1)
Cc=(C,c)
S=optimize_init()
optimize_init_constraints(S,Cc)
optimize_init_evaluator(S, &triald1())
optimize_init_which(S, "min" )
optimize_init_evaluatortype(S,"d0")
optimize_init_params(S,(0.5,0.5,0,0))
p = optimize(S)
p
end
Thanks
I am trying to write a simple optimization problem in mata. I have to find the vector of weights which minimizes a function (the other matrices are external and I label them as such in the code). However, for some reason it keeps returning an error that S is not found. Any ideas on what the problem could be?
mata
void triald1(todo,w, y, g, H)
{
external varcov,vol
y = (w'*vol)*(w'*varcov*w)
}
end
corrmat retioous retvxxus retjph retdbcus , covmat
matrix define varcov=r(cov)
matrix define vol=J(4,1,.)
matrix define vol[1,1]=varcov[1,1]
matrix define vol[2,1]=varcov[2,2]
matrix define vol[3,1]=varcov[3,3]
matrix define vol[4,1]=varcov[4,4]
mata
init=J(4,1,0)
C=(1,1,1,1)
c=(1)
Cc=(C,c)
S=optimize_init()
optimize_init_constraints(S,Cc)
optimize_init_evaluator(S, &triald1())
optimize_init_which(S, "min" )
optimize_init_evaluatortype(S,"d0")
optimize_init_params(S,(0.5,0.5,0,0))
p = optimize(S)
p
end
Thanks
Comment