Statalist


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

st: Setting up optimize for 2 equations in 2 unknowns


From   "Thomas Jacobs" <[email protected]>
To   StataList <[email protected]>
Subject   st: Setting up optimize for 2 equations in 2 unknowns
Date   Mon, 28 Jul 2008 18:39:41 -0500

I have tried in vain to get a 2 equation in 2 unknowns problem to work
with optimize.  Would someone be kind enough to give me some advice?

I have the following parameters which will be fixed during the optimization:

T (time)
sqrT (squareroot of time)
Evol (equity volatility)
EoX (firm equity normalized by firm debt)

and the following parameters which I wish to solve for:

Avol (asset volatility)
AoX (firm assets normalized by firm debt

The two equations are:

F1 = AoX * normal(d1) - normal(d2) - EoX
F2 = normal(d1) * AoX * Avol - EoX * Evol

where

d1 = (ln(AoX)+ T*0.5*Avol^2)/(Avol*sqrtT)
d2 = d1 - Avol * sqrtT

I am taking the square of each equation and trying to minimize the
sum.  Here is what I have most recently tried where the I[] matrix is
input data that I will read for each firm on a given trading day and
the calculated values for Avol and AoX are starting values for the
optimization:

T = 5
sqrtT = sqrt(T)

for (j=1; j<=rows(I); j++) {

  X = (I[j,15] - I[j,16])
  E = I[j,13]

  Evol = I[j,14]
  Avol = Evol/2

  AoX = (E + X)/X
  EoX = E/X

  c = (sqrT, T, EoX, Evol)

  void Merton(todo, A, c, lnf, g, H)
	{
		lnf = (A[1]*normal((ln(A[1])+c[2]*0.5*A[2]^2)/(A[2]*c[1]))-
normal((ln(A[1])-c[2]*0.5*A[2]^2)/(A[2]*c[1]))- c[3])^2 +
(normal((ln(A[1])+c[2]*0.5*A[2]^2)/(A[2]*c[1])) * A[1] * A[2] - c[3] *
c[4])^2
	}
  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)
  A = optimize(S)

  printf("A:")
  A

}

Here is the reply I get:

>   c = (sqrT, T, EoX, Evol)
>
>   void Merton(todo, A, c, lnf, g, H)
expression invalid
(16 lines skipped)

I am unsure what I am doing wrong and have tried several variations
based upon the manual always receiving the same error.

Tom

--
Thomas Jacobs
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index