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" <[email protected]>
To   [email protected]
Subject   Re: st: Setting up optimize for 2 equations in 2 unknowns
Date   Mon, 28 Jul 2008 20:06:12 -0400

Thomas Jacobs <[email protected]>:
It may have to do with your loop, since this runs in Mata:
T = 5
sqrtT = sqrt(T)
X = 0.5
E = 0
Evol = 1
Avol = Evol/2
AoX = (E + X)/X
EoX = E/X
c = (sqrT, T, EoX, Evol)
void Mert(todo, A, c, lnf, g, H)
{
f1=A[1]*normal((ln(A[1])+c[2]*0.5*A[2]^2)/(A[2]*c[1]))
f2=-normal((ln(A[1])-c[2]*0.5*A[2]^2)/(A[2]*c[1]))- c[3]
f3=normal((ln(A[1])+c[2]*0.5*A[2]^2)/(A[2]*c[1]))*A[1]*A[2]
f4=c[3] * c[4]
lnf=(f1-f2)^2 + (f3-f4)^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)
A


On Mon, Jul 28, 2008 at 7:39 PM, Thomas Jacobs <[email protected]> wrote:
> 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
*
*   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