私募股权小组数据季度回报

时间:2019-03-18 17:30:57

标签: r excel panel

我正在尝试为带有R的私募股权基金的面板数据集计算季度内部收益率。由于我是R的新手,并且已经尝试了几天却没有任何结果,所以希望您能为您提供帮助我。 在下面的链接中,您可以看到我的数据的示例。

我有几百个资金,它们均按交易日期排序。 因此,数据具有面板数据的形式。现在的困难是要计算每个私募股权基金的季度收益(IRR)。 这将在Excel中使用XIRR公式完成。我通常使用以下代码将excel的XIRR公式转换为R。

xirr <- function(cashflow, dates){
if (!length(cashflow)) return(NA)
dates<-dates[!is.na(cashflow)]
cashflow<-cashflow[!is.na(cashflow)]
npv <- function(irr){
    timeDiff <- diff(dates)
    units(timeDiff) <- "days"
    day <- cumsum(c(0, as.numeric(timeDiff)))
    if (!is.na(sum(cashflow/(1 + irr/1000)^(day/365)))){
                return(sum(cashflow/(1 + irr/1000)^(day/365)))
}else{
    # prevent from getting stuck? 
    return(runif(1,1,100))
}
}
## try up to 1000% (irr = 10), but still allow extension for extreme cases
## bounded below by -1000 (irr = -1)
irr <- try(uniroot(npv, c(-999.99999, 10000), extendInt = "downX",maxiter=1000),
           silent = TRUE)
if (inherits(irr, "try-error")) {
    return(NA)
} else return(irr$root/1000)
}

我必须为每个季度包括所有具有相应日期的交易。贡献为负现金流量和分配,以及会计资产净值为正现金流量。但是,为了计算资金的季度收益,上一季度的会计净资产值也必须为负现金流量。

基本上,我想R只需从一个会计资产净值转到下一个会计资产净值,并在XIRR公式中包括所有交易以及日期。

有人知道怎么做吗?

As you can see in the link, you have two Funds and their cash flows. I want to calculate the Quarterly Returns which are on the right side. This is done in Excel with the IRR Formula. Therefore, the Accounting NAV at the beginning of the period has to be converted into a negative cash flow. The IRR formula will then calculate the return by considering the time. This has to be done for each fund and for each quarter

0 个答案:

没有答案