任何可用于计算特定日期不均匀付款的内部收益率的套餐?

时间:2021-01-19 12:33:57

Are there any R packages available that have some form of function that can calculate IRR based on uneven payments on specific dates for a lump sum distribution.

是否有任何R套餐具有某种形式的功能,可以根据特定日期的不均匀支付来计算IRR,以便进行一次性分配。

Example:

df <- data.frame(date = c(as.Date("2010-1-24"), as.Date("2011-5-6"), as.Date("2012-3-24")), pmts=c(-2000,-1000,-800))
today <- as.Date("2012-7-25")
lumpsum <- 4580

I'm looking for an easy way to calculate the rate of return of $4580 received today in exchange for the payment schedule defined above.

我正在寻找一种简单的方法来计算今天收到的4580美元的回报率,以换取上面定义的付款时间表。

Thanks in advance, --JT

在此先感谢, - .JT

2 个解决方案

#1


5  

As already noted in the comments it would be easier to write something simple:

正如评论中已经指出的那样,写一些简单的东西会更容易:

NPV<-function(paym,pdates,IRR){
   ptimes<-as.Date(pdates)-min(as.Date(pdates))
   ptimes<-as.numeric(ptimes,units="days")/365.25
   NPV<-sum(paym*(1+IRR)^{-ptimes})
   NPV
}

nlm(function(p){NPV(c(lumpsum,df$pmts),c(today,df$date),p)^2},p=0.1)

gives a IRR of 11.26%

IRR为11.26%

EDIT:

after a quick scout around the lifecontingencies package has a present value function if you want to use that instead.

如果你想使用它,那么在生活应急包周围快速侦察后会有一个现值函数。

library(lifecontingencies)
capitals<-c(lumpsum,df$pmts)
times<-c(today,df$date)
times<-as.Date(times)-min(as.Date(times))
times<-as.numeric(times,units="days")/365.25
presentValue(cashFlows=capitals, timeIds=times,interestRates=0.03)
nlm(function(p){presentValue(capitals,times,p)^2},p=0.1)

#2


5  

utilising "stats" package uniroot function IRR can be coded as below:

利用“stats”包uniroot函数IRR可以编码如下:

   cf <- c(-10000, 1300, -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.0686
   irrinpercent<- irr(cf)*100
   [1] 6.86

#1


5  

As already noted in the comments it would be easier to write something simple:

正如评论中已经指出的那样,写一些简单的东西会更容易:

NPV<-function(paym,pdates,IRR){
   ptimes<-as.Date(pdates)-min(as.Date(pdates))
   ptimes<-as.numeric(ptimes,units="days")/365.25
   NPV<-sum(paym*(1+IRR)^{-ptimes})
   NPV
}

nlm(function(p){NPV(c(lumpsum,df$pmts),c(today,df$date),p)^2},p=0.1)

gives a IRR of 11.26%

IRR为11.26%

EDIT:

after a quick scout around the lifecontingencies package has a present value function if you want to use that instead.

如果你想使用它,那么在生活应急包周围快速侦察后会有一个现值函数。

library(lifecontingencies)
capitals<-c(lumpsum,df$pmts)
times<-c(today,df$date)
times<-as.Date(times)-min(as.Date(times))
times<-as.numeric(times,units="days")/365.25
presentValue(cashFlows=capitals, timeIds=times,interestRates=0.03)
nlm(function(p){presentValue(capitals,times,p)^2},p=0.1)

#2


5  

utilising "stats" package uniroot function IRR can be coded as below:

利用“stats”包uniroot函数IRR可以编码如下:

   cf <- c(-10000, 1300, -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.0686
   irrinpercent<- irr(cf)*100
   [1] 6.86