[R-SIG-Finance] IRR - Calculation in R
Rory.WINSTON at rbs.com
Rory.WINSTON at rbs.com
Thu Nov 27 17:42:39 CET 2008
I think uniroot() is what you are looking for.
Incidentally, there have been a few posts regarding this on the main R help list.
Example:
> cf <- c(-10000, 1322, -1200, 12000)
> npv <- function(i, cf, t=seq(along=cf)) sum(cf/(1+i)^t)
> irr <- function(cf) { uniroot(npv, c(0,1), cf=cf)$root }
> irr(cf)
[1] 0.06937691
Rory
Rory Winston
RBS Global Banking & Markets
Office: +44 20 7085 4476
-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch [mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Thomas Etheber
Sent: 27 November 2008 14:12
To: r-sig-finance at stat.math.ethz.ch
Subject: [R-SIG-Finance] IRR - Calculation in R
Hi there,
can anyone recommend a comfortable package for the calculations of the internal rate of return (IRR)? I had a quick look at google and the history of this newsgroup, but couldnt find something usefull.
Is polyroot the right choice?
The polyroot function returns all values including the complex ones.
Is there a possibility to filter for real-numbers only?
Here is a piece of code:
> p <- c(-10000, 1322, -1200, 12000)
> p
[1] -10000 1322 -1200 12000
> 1/polyroot(p) - 1
[1] 0.06936167+0.000000i -1.46858084-0.950051i -1.46858084+0.950051i
> a <- 1/polyroot(p) - 1
> is.complex(a)
[1] TRUE
> is.complex(a[1])
[1] TRUE
> is.complex(a[2])
[1] TRUE
> is.complex(a[3])
[1] TRUE
> is.complex(a[4])
[1] TRUE
Why are all of those TRUE, I expected that is.complex(a[1]) would bring a FALSE?
Thx in advance
Thomas
--
Sensationsangebot nur bis 30.11: GMX FreeDSL - Telefonanschluss + DSL für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a
_______________________________________________
R-SIG-Finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
Authorised and regulated by the Financial Services Authority
This e-mail message is confidential and for use by the=2...{{dropped:22}}
More information about the R-SIG-Finance
mailing list