Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Setting up optimize for 2 equations in 2 unknowns


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Setting up optimize for 2 equations in 2 unknowns
Date   Mon, 28 Jul 2008 20:49:44 -0400

Thomas Jacobs <thomasjacobs@gmail.com>:
You may also want to reparametrize--I had trouble finding fake
starting values that would not crash your program.  For example, if
Avol and AoX are always positive, try logs:

clear all
mata
void Merton(todo, A, c, lnf, g, H)
{
f1=A[1]*normal((A[1]+c[2]*0.5*exp(A[2])^2)/(exp(A[2])*c[1]))
f2=-normal((A[1]-c[2]*0.5*exp(A[2])^2)/(exp(A[2])*c[1]))- c[3]
f3=normal((A[1]+c[2]*0.5*exp(A[2])^2)/(exp(A[2])*c[1]))*exp(A[1]+A[2])
f4=c[3] * c[4]
lnf=(f1-f2)^2 + (f3-f4)^2
}
T = 5
sqrtT = sqrt(T)
X = 0.65
E = 0.25
Evol = 0.15
Avol = ln(Evol/2)
AoX = ln(E + X)-ln(X)
EoX = E/X
c = (sqrtT, T, EoX, Evol)
S = optimize_init()
optimize_init_evaluator(S, &Merton())
optimize_init_evaluatortype(S,"d0")
optimize_init_params(S,(AoX,Avol))
optimize_init_which(S, "min")
optimize_init_argument(S,1,c)
B=optimize(S)
exp(B[1]),exp(B[2])
*
*   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   |   What's new   |   Site index