This function computes the internal rate of return at which the
net present value equals zero. It requires as input a function
that computes the net present value of a series of cash flows for
a given interest rate as well as the derivative of the NPV with
respect to the interest rate (10,000 times this derivative is the
PVBP or DV01). In this package, irr.solve
is primarily
intended to be called by the irr
and
bond.yield
functions. It is made available for those
who want to find IRR of more complex instruments.
irr.solve(
f,
interval = NULL,
r.guess = NULL,
toler = 1e-06,
convergence = 1e-08,
max.iter = 100,
method = c("default", "newton", "bisection")
)
The function whose zero is to be found. An R function object that takes one numeric argument and returns a list of two components (value and gradient). In the IRR applications, these two components will be the NPV and its derivative
The interval c(lower, upper) within which to search for the IRR
The starting value (guess) from which the solver starts searching for the IRR
The argument toler
to
newton.raphson.root
. The IRR is regarded as
correct if abs(NPV) is less than toler
. Otherwise the
irr.solve
returns NA
The argument convergence
to
newton.raphson.root
.
The maximum number of iterations of the Newton-Raphson procedure
The root finding method to be used. The
default
is to try Newton-Raphson method
(newton.raphson.root
) and if that fails to try
bisection (bisection.root
). The other two
choices (newton
and bisection
force only one of
the methods to be tried.
The function irr.solve
returns NA
if the IRR/YTM
could not be found. Otherwise it returns the IRR/YTM. When
NA
is returned, a warning message is printed
The function irr.solve
is basically an interface to the
general root finder newton.raphson.root
. However, if
newton.raphson.root
fails, irr.solve
makes an
attempt to find the root using uniroot
from the R
stats package. Uniroot
uses bisection and it requires the root to
be bracketed (the function must be of opposite sign at the two end
points - lower and upper).