I couldn't resist the temptation.
Here is the example using the R package nleqslv.
library(nleqslv)
npv <- function (irr, cashFlow, times) sum(cashFlow / (1 + irr)^times)
CF <- c(-1000,500,500,500,500,500)
dates <-
c("1/1/2001","2/1/2002","3/1/2003","4/1/2004","5/1/2005","6/1/2006")
cfDate <-
---
From: Ravi Varadhan [mailto:rvarad...@jhmi.edu]
Sent: Wednesday, August 25, 2010 7:24 PM
To: Adrian Ng
Cc: r-help@r-project.org
Subject: RE: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)
The secant method converges just fine. Your problem might have occurred due
to improper
D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University
Ph. (410) 502-2619
email: rvarad...@jhmi.edu
- Original Message -
From: Ravi Varadhan
Date: Wednesday, August 25, 2010 10:51 pm
Subject: Re: [R] Secant Method Convergence
is helps,
Ravi.
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University
Ph. (410) 502-2619
email: rvarad...@jhmi.edu
- Original Message --
uot;1/1/2001","2/1/2002","3/1/2003","4/1/2004","5/1/2005","6/1/2006")
ANXIRR(CF, dates, guess=0.1)
> ANXIRR(CF, dates, guess=0.1)
$irr
[1] 0.4106115
$npv
[1] 2.984279e-13
Ravi.
-Original Message-
From: Adrian Ng [mailto:a...@hamil
: Adrian Ng; r-help@r-project.org
Subject: RE: [R] Secant Method Convergence (Method to replicate Excel
XIRR/IRR)
Another approach is to use `uniroot' to find the zero of the NPV function:
npv <- function (cashFlow, irr) {
n <- length(cashFlow)
sum(cashFlow / (1 + i
Another approach is to use `uniroot' to find the zero of the NPV function:
npv <- function (cashFlow, irr) {
n <- length(cashFlow)
sum(cashFlow / (1 + irr)^{0: (n-1)})
}
uniroot(f=npv, interval=c(0,1), cashFlow=cashFlow)
However, there may be situations where there are no
Hi Adrian,
Your code for the secant method is correct.
I just tweaked it a bit w/o the calendar time feature (assuming that the
cash flows will be available on an annual basis) as follows:
ANXIRR <- function (cashFlow, guess, tol=1.e-04){
npv <- function (cashFlow, irr) {
n <- length(ca
8 matches
Mail list logo