Announcement

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

  • Implied cost of capital - mm_root with > 10 arguments

    Dear all,

    In the course of my Master's thesis I intend to calculate an implied cost of capital (ICC) from a 16-period earnings forecast. With the help of Statalist I was able to reproduce the code below that functions when limiting the forecasting horizon to 6 periods. Yet, when running the code with the full horizon (as presented), I encounter the problem that the number of additional arguments for mm_root is restricted to 10. I went through several older posts dealing with a similar problem, but cannot manage to apply the proposed solutions to my dataset.

    Comments or instructions on how to solve this issue and retrieve r would be of great help. Any other feedback to improve the code is also highly appreciated.
    Thanks in advance!

    https://www.statalist.org/forums/for...equity-capital
    https://www.stata.com/statalist/arch.../msg00023.html

    Code:
    generate icc=.
    mata
    mata clear
    z=J(1,1,.)
    st_view(z,., "icc GDP_g_lag1 P b1 FE1 FE2 FE3 FE4 FE5 FE6 FE7 FE8 FE9 FE10 FE11 FE12 FE13 FE14 FE15 FE16")
    function w(r,g,p,b1,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16)
    {
        t1 = f1*(1-b1)/(1+r)
        t2 = f2*(1-(b1-(b1-g/r)/15))/(1+r)^2
        t3 = f3*(1-(b1-2/15*(b1-g/r)))/(1+r)^3
        t4 = f4*(1-(b1-3/15*(b1-g/r)))/(1+r)^4
        t5 = f5*(1-(b1-4/15*(b1-g/r)))/(1+r)^5
        t6 = f6*(1-(b1-5/15*(b1-g/r)))/(1+r)^6
        t7 = f7*(1-(b1-6/15*(b1-g/r)))/(1+r)^7
        t8 = f8*(1-(b1-7/15*(b1-g/r)))/(1+r)^8
        t9 = f9*(1-(b1-8/15*(b1-g/r)))/(1+r)^9
        t10 = f10*(1-(b1-9/15*(b1-g/r)))/(1+r)^10
        t11 = f11*(1-(b1-10/15*(b1-g/r)))/(1+r)^11
        t12 = f12*(1-(b1-11/15*(b1-g/r)))/(1+r)^12
        t13 = f13*(1-(b1-12/15*(b1-g/r)))/(1+r)^13
        t14 = f14*(1-(b1-13/15*(b1-g/r)))/(1+r)^14
        t15 = f15*(1-(b1-14/15*(b1-g/r)))/(1+r)^15
        tv = f16/(r*(1+r)^15)
        return(-p+t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14+t15+tv)
    }
    for (i=1;i<=rows(z);i++) {
        x=mm_root(icc=.,&w(),smallestdouble(),1-epsilon(1),1e-9,1000,z[i,2],z[i,3],z[i,4],z[i,5],z[i,6],z[i,7],z[i,8],z[i,9],z[i,10],z[i,11],z[i,12],z[i,13],z[i,14],z[i,15],z[i,16],z[i,17],z[i,18],z[i,19],z[i,20])
        z[i,1]=icc
    }
    end

  • #2
    A look at the output of help mm_root does not suggest that the arguments passed to your function w() must be scalars. So one approach that might work would be to place all of your scalar arguments into a vector and pass the vector as a single argument to mm_root and rewrite your function w() to retrieve its arguments from the vector that mm_root passes through to it.

    Comment


    • #3
      Thanks for the feedback. I tried to implement your advice and followed (among others) instructions you posted in another thread (https://www.statalist.org/forums/for...ent-limitation). I adjusted the code to the following (see below) which functions and yields reasonable and mathematically correct solutions for several observations. Yet, for the majority of observations I receive no solution even though when manually solving in excel, these observations yield results that are within the specified boundaries of mm_root.

      Have you or anyone else encountered this problem and/or know a possible solution? Happy to receive further feedback to improve the code.
      For further info I attached a sample file.

      Code:
      generate icc=.
      mata
      mata clear
      z=J(1,1,.)
      st_view(z,., "icc GDP_g_lag1 P b1 FE1 FE2 FE3 FE4 FE5 FE6 FE7 FE8 FE9 FE10 FE11 FE12 FE13 FE14 FE15 FE16")
      function w(r,b) {
          g=b[2]
          p=b[3]
          b1=b[4]
          f1=b[5]
          f2=b[6]
          f3=b[7]
          f4=b[8]
          f5=b[9]
          f6=b[10]
          f7=b[11]
          f8=b[12]
          f9=b[13]
          f10=b[14]
          f11=b[15]
          f12=b[16]
          f13=b[17]
          f14=b[18]
          f15=b[19]
          f16=b[20]
      
          t1 = f1*(1-b1)/(1+r)
          t2 = f2*(1-(b1-(b1-g/r)/15))/(1+r)^2
          t3 = f3*(1-(b1-2/15*(b1-g/r)))/(1+r)^3
          t4 = f4*(1-(b1-3/15*(b1-g/r)))/(1+r)^4
          t5 = f5*(1-(b1-4/15*(b1-g/r)))/(1+r)^5
          t6 = f6*(1-(b1-5/15*(b1-g/r)))/(1+r)^6
          t7 = f7*(1-(b1-6/15*(b1-g/r)))/(1+r)^7
          t8 = f8*(1-(b1-7/15*(b1-g/r)))/(1+r)^8
          t9 = f9*(1-(b1-8/15*(b1-g/r)))/(1+r)^9
          t10 = f10*(1-(b1-9/15*(b1-g/r)))/(1+r)^10
          t11 = f11*(1-(b1-10/15*(b1-g/r)))/(1+r)^11
          t12 = f12*(1-(b1-11/15*(b1-g/r)))/(1+r)^12
          t13 = f13*(1-(b1-12/15*(b1-g/r)))/(1+r)^13
          t14 = f14*(1-(b1-13/15*(b1-g/r)))/(1+r)^14
          t15 = f15*(1-(b1-14/15*(b1-g/r)))/(1+r)^15
          tv = f16/(r*(1+r)^15)
          return(-p+t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14+t15+tv)
      }
      for (i=1;i<=rows(z);i++) {
          x=mm_root(icc=.,&w(),smallestdouble(),1-epsilon(1),1e-9,1000,z[i,.])
          z[i,1]=icc
      }
      end


      Attached Files

      Comment


      • #4
        I believe your bounds on the range are too close to zero and 1, causing mm_root to venture into perilous territory. Consider the following.
        Code:
        : for (i=1;i<=rows(z);i++) {
        >     x=mm_root(icc=.,&w(),smallestdouble(),1-epsilon(1),1e-9,1000,z[i,.])
        >     z[i,1]=icc
        > }
        
        : ans = z[.,1]
        
        :  for (i=1;i<=rows(z);i++) {
        >     x=mm_root(icc=.,&w(),.0001,.9999,1e-9,1000,z[i,.])
        >     z[i,1]=icc
        > }
        
        : ans = ans, z[.,1]
        
        : ans[21..40,.]
                          1             2
             +-----------------------------+
           1 |            .   .0992243662  |
           2 |            .   .1240556762  |
           3 |            .   .2113425881  |
           4 |            .   .1208846271  |
           5 |  .0988930017   .0988930017  |
           6 |  .0408103429   .0408103429  |
           7 |            .   .2557891011  |
           8 |            .   .1757969707  |
           9 |            .   .1206262484  |
          10 |            .    .117015332  |
          11 |            .   .1216343939  |
          12 |            .   .1406791061  |
          13 |            .   .1835439801  |
          14 |            .   .1946141422  |
          15 |            .   .1262899339  |
          16 |            .   .1259935051  |
          17 |            .   .2081568688  |
          18 |  .0580006279   .0580006279  |
          19 |  .0484659001   .0484659001  |
          20 |            .   .0989307314  |
             +-----------------------------+

        Comment


        • #5
          The adjustment of the bounds indeed solved my issue. Thanks a lot for your help, much appreciated!

          Comment

          Working...
          X