Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • generate input variable when output variable is known

    Hello,

    I have 1 output variable called E and several input variables from which A is unknown, this is the equition which has to be solved:
    E=(A*N(d1))-(D*e-rT*N(d2)), N is a cumulative standard normal distribution.
    d1 = (ln((A*erT)/D)+((1/2)*s2*AT))/(s*T1/2)
    d2= d1-(s*T1/2)
    How can I genereate the variable A?

    With kind regards,
    Lieke Janssen

  • #2
    Hello,

    I have still no solution for my problem.
    This is what I have but I've got an error:

    . clear mata

    . mata:
    ------------------------------------------------- mata (type end to exit) -------------------------------------------------------------------
    : T = 5

    : sqrtT = sqrt(T)

    : X = 0.5

    : E = 0

    : Evol = 1

    : Avol = Evol/2

    : AoX = (E + X)/X

    : EoX = E/X

    : c = (sqrtT, 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
    > }
    note: argument todo unused
    note: argument g unused
    note: argument H unused

    : S = optimize_init()

    : optimize_init_evaluator(S, &Mert())

    : 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)
    Iteration 0: f(p) = 1.1267093
    Iteration 1: f(p) = .00156144 (not concave)
    Iteration 2: f(p) = 1.811e-11 (not concave)
    could not calculate numerical derivatives -- discontinuous region with missing values encountered
    could not calculate numerical derivatives -- discontinuous region with missing values encountered
    (1 line skipped)
    ---------------------------------------------------------------------------------------------------------------------------------------------
    r(430);

    end of do-file

    r(430);
    .

    Comment


    • #3
      First notice that your Mata implementation differs from your initial problem. With your implementation you are trying to solve an equation with two unknowns, while in the initial case you have only one unknown. I am not sure if this is intentional or not, but an (hopefully correct) implementation of your initial problem is given below.
      Secondly, I am not sure what is causing the discontinuous region with missing values, but my guess is that the solution of A[1] may be close to zero. However, if the search algorithm “tries” a value of zero (or smaller), for A[1] the lnf will be set to missing. A solution to this is to use exp(A[1]) instead of A[1]. If you find a solution you can always transform this back.

      Mata implementation:
      Code:
      mata:
      
      T = 5
      E = 1
      r = 2
      D = 3
      s = 4
      c = (T, r, D, s, E)
      
      void Mert2(todo, A, c, lnf, g, H){
          T = c[1]
          r = c[2]
          D = c[3]
          s = c[4]
          d1 = (ln((A * exp(r * T)) / D) + ((1/2) * s ^ 2 * A ^ T)) / (s * T ^ (1/2))
          d2 = d1 - (s * T ^ (1/2))
          E = (A * normal(d1)) - (D * exp(-r * T) * normal(d2))
          lnf = (E - c[5]) ^ 2
          
      }    
      
      S = optimize_init()
      optimize_init_evaluator(S, &Mert2())
      optimize_init_evaluatortype(S, "d0")
      optimize_init_params(S, (1))
      optimize_init_which(S, "min")
      optimize_init_argument(S,1,c)
      A = optimize(S)
      A
      
      end

      Comment

      Working...
      X