0

How do I calculate internal rate of return (IRR) and yield to maturity (YTM) in Maxima? I am trying to calculate the YTM of a bond of $1000 face value that pays $50 in coupons every year. The bond is currently selling for $900, and matures in 3 years. Using the formula for the YTM:

900 = [50 / (1 + r)] + [50 / (1 + r)^2] + [50 / (1 + r)^3] + [1000 / (1 + r)^3]

How do I use Maxima to solve for r, the YTM?

Flux
  • 9,805
  • 5
  • 46
  • 92

1 Answers1

1

The equation is a cubic polynomial, so it has an exact solution, which Maxima can find, but for problems like it's probably more useful to just look for a numerical approximation.

First note that Maxima only recognizes parentheses for grouping; square brackets are only for lists.

(%i1) eqn: 900 = (50 / (1 + r)) + (50 / (1 + r)^2) + (50 / (1 + r)^3) + (1000 / (1 + r)^3);
                              50        50        1050
(%o1)                  900 = ----- + -------- + --------
                             r + 1          2          3
                                     (r + 1)    (r + 1)

Call find_root to find an approximate root.

(%i2) find_root (eqn, r, 0, 1);
(%o2)                         0.08946802632716268

By the way, there is an add-on package named finance which might be relevant. Try: ?? finance to get some info.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48