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

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

From   "Thomas Jacobs" <>
Subject   Re: st: Setting up optimize for 2 equations in 2 unknowns
Date   Tue, 29 Jul 2008 17:48:42 -0500


Thanks very much for the reply.  At least I can now get optimize to
run.  After a number of experiments it came down to its location
inside the loop as you suggested.

While I have not spent a lot of time with taking the logs or
reparameterizing, I have found as you did that for many of my more
difficult firms (those with high leverage and yet high equity
volatility - pre-Fed bailout Bear Stearns is typical) the program with
the default optimizer (modified newton-raphson) typically fails as a
result of not calculating a numerical derivative.  If I change the
starting point for firm asset volatility from half the starting equity
volatility to a proportion of the firms equity normalized by its
assets it often does not converge (at least before I give up and hit

Given that I coded a two variable newton raphson search in mata in my
prior attempts at this problem, that while taking a long time for
firms like Bear Stearns (thousands of iterations) always does
converge, do you think the problem is that optimize() is only
calculating one numerical derivative of the formula for sum of squares
for each of the two variables where my newton raphson is calculating
it for each piece (that is two for each of the two equations)?  If so,
is there a way to set up optimize() to separate the two equations in
some fashion as opposed to working with their sum of squares?

Thanks again for your time and thoughts.


On Mon, Jul 28, 2008 at 7:49 PM, Austin Nichols <> wrote:
> Thomas Jacobs <>:
> 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:
> *
> *
> *

Thomas Jacobs
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index