我喜欢使用 XIRR 计算我的投资回报。但是,这只适用于我出售了我的投资。因此,我通过假设我今天已出售投资来计算 XIRR。
由于现金流量和当前投资在不同的表中,我尝试使用非连续范围但不起作用。
问题:我可以知道是否有替代方法吗? Javascript 解决方案也很好。
=xirr({ARRAYFORMULA((B2:B5="IBM")*C2:C5),A8},{ARRAYFORMULA( (B2:B5="IBM")*A2:A5),C8})
Column A: transaction date
Column B: Stock symbol. I use IBM as an example
Column C: Cash flow
Row 8 is the current value
如果我不包括 A8 和 C8,该公式有效,但也不包括当前市场价值,这不是我想要的。
答案 0 :(得分:0)
由于非连续范围表示法不起作用,我编写了一个函数来合并范围。
{A1:A3,A10} does not work. Do I do
MR(A1:A3,A10)
function MR(r,c=[]){
var result=r;
if (c.constructor==Array){
c.forEach((f)=>{
result.push(f);
});
}else{
result.push(c)
}
return result;
}
我第 29 行的最终公式:
=xirr(filter(MR(Transections!R:R,$O$2:$O),MR(Transections!C:C,$B$2:$B)=B29),filter(MR(Transections!A:A,$Y$2:$Y),MR(Transections!C:C,$B$2:$B)=B29))
For the active sheet
column O: The current market value of the stock.
column B: The stock code
column Y: Current date. XIRR does not accept Now() so need to type in current date.
On the Transections sheet:
Column R: Cash flow from buy/sell
Column C: Stock code
Column A: Transections date.
如果有更简单的方法,请告诉我。