Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-26 Thread Berend Hasselman
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 -

[R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Adrian Ng
Hi, I am new to R, and as a first exercise, I decided to try to implement an XIRR function using the secant method. I did a quick search and saw another posting that used the Bisection method but wanted to see if it was possible using the secant method. I would input a Cash Flow and Date

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
] 0.1429934 $npv [1] 1.705303e-12 Hope this helps, Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Adrian Ng Sent: Wednesday, August 25, 2010 8:39 AM To: r-help@r-project.org Subject: [R] Secant Method Convergence (Method

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
(Method to replicate Excel XIRR/IRR) Hi, I am new to R, and as a first exercise, I decided to try to implement an XIRR function using the secant method. I did a quick search and saw another posting that used the Bisection method but wanted to see if it was possible using the secant method. I would

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
: [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 + irr)^{0: (n-1)}) } uniroot(f=npv, interval=c(0,1

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
] 0.4106115 $npv [1] 2.984279e-13 Ravi. -Original Message- From: Adrian Ng [mailto:a...@hamiltonlane.com] Sent: Wednesday, August 25, 2010 6:23 PM To: Ravi Varadhan Subject: RE: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR) The forum is kind of slow so I'm just re

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Adrian Ng a...@hamiltonlane.com Date: Wednesday, August 25, 2010 8:33 pm Subject: RE: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR) To: Ravi Varadhan rvarad

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Ravi Varadhan
. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Adrian Ng a...@hamiltonlane.com Date: Wednesday, August 25, 2010 8:33 pm Subject: RE: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR) To: Ravi Varadhan rvarad...@jhmi.edu Cc: r-help@r

Re: [R] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-25 Thread Adrian Ng
[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 conversion of dates to elapsed