Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: optimize with unequality constraints


From   Alberto Dorantes <alberto.dorantes@finanzastec.net>
To   statalist@hsphsun2.harvard.edu
Subject   st: optimize with unequality constraints
Date   Sun, 1 Apr 2012 09:41:24 -0500

Hi all.
 Is there a way to specify unequality constraints to the optimize function
in Mata?
I have f(p) as a function to maximize. I found a way to put an
equality constraint
(the sum of p[i] is equal to one), but I could not specify the non-negative
constraint to each p[i] (p[i]>0).

I read in Statalist that using logs can solve the problem, but I have not
figure out how to transform my p vector to logs since I', afraid that my
function will not work correctly.

To be more specific, here is my code:

mata:
void retorno_ajustado(real scalar todo, real vector p,
                     real vector R, real matrix COV,
                    ret, grad, Hess)
{
   ret= p*R' / sqrt(p*COV*p')
}

S = optimize_init()
optimize_init_evaluator(S, &retorno_ajustado())
optimize_init_evaluatortype(S, "d0")
optimize_init_params(S,(0,1))
C=J(1,2,1)
c=(1)
COV=st_matrix("COVA")
R = [0.28, 0.19]
optimize_init_argument(S,1,R)
optimize_init_argument(S,2,COV)
optimize_init_constraints(S,(C,c))
optimize(S)
optimize_result_params(S)
optimize_result_value(S)
end

(COVA is a Var-Cov matrix of 2x2)

Thanks in advance!

Carlos A. Dorantes

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index