google-apps-script - 非连续范围
问题描述
我喜欢使用 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,则该公式有效,但也排除了当前市场价值,这不是我想要的。
解决方案
由于非连续范围表示法不起作用,我编写了一个函数来合并范围。
{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.
如果有更简单的方法,请告诉我。
推荐阅读
- github - 从 Git 存储库中删除了大文件但仍然无法推送
- r - 在任意函数的调用中检查多个丢失的参数
- ios - 如何检测 UICollectionViewCell 中的 UITableViewCell 中的按钮点击?
- javascript - 如何显示 DOM 元素
- java - 如何在 Spring 安全性中使用 CkFinder 上传图像?
- javascript - 如何按键对一组对象进行分组?
- dialogflow-es - 如何使用 Dialogflow 捕获用户文本
- android - 您如何云保存每个级别的数据。统一游戏像糖果迷恋游戏
- python-3.x - ValueError:操作数无法与形状 > (400,2) (400,) 一起广播
- android - 当默认设置为 0 时,SharedPreferences getInt 返回 -1