IRR - Calculation in R

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

IRR - Calculation in R

Thomas Etheber
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

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Reply | Threaded
Open this post in threaded view
|

Re: IRR - Calculation in R

Rory.WINSTON
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: [hidden email] [mailto:[hidden email]] On Behalf Of Thomas Etheber
Sent: 27 November 2008 14:12
To: [hidden email]
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

_______________________________________________
[hidden email] 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}}

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Reply | Threaded
Open this post in threaded view
|

Re: IRR - Calculation in R

Alberto Santini
In reply to this post by Thomas Etheber
Thomas Etheber wrote
can anyone recommend a comfortable package for the calculations of the internal rate of return (IRR)?
I developed a tiny routine to emulate the XIRR function of Excel.

http://albertosantini.blogspot.com/2008/01/xirr.html

Hope that helps,
Alberto Santini