[R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)
Berend Hasselman
bhh at xs4all.nl
Thu Aug 26 08:04:53 CEST 2010
I couldn't resist the temptation.
Here is the example using the R package nleqslv.
<script>
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 <- as.Date(dates,format="%m/%d/%Y")
times <- as.numeric(difftime(cfDate, cfDate[1], units="days"))/365.24
irr.start <- 0.05
# default Broyden ==> secant like method
nleqslv(irr.start, npv, control=list(trace=1), cashFlow=CF, times=times)
</script>
/Berend
--
View this message in context: http://r.789695.n4.nabble.com/Secant-Method-Convergence-Method-to-replicate-Excel-XIRR-IRR-tp2338672p2339187.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list