office官网找到IRR的介绍

https://support.office.com/zh-cn/article/irr-%E5%87%BD%E6%95%B0-64925eaa-9988-495b-b290-3ad0c163c1bc

https://docs.microsoft.com/zh-cn/office/vba/language/reference/user-interface-help/irr-function?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev11.query%3FappId%3DDev11IDEF1%26l%3Dzh-CN%26k%3Dk(vblr6.chm1009282)%3Bk(TargetFrameworkMoniker-Office.Version%3Dv15)%26rd%3Dtrue

1.找js的实现

function IRR(cashFlows, estimatedResult) {
var result = "isNAN";
if (cashFlows != null && cashFlows.length > 0) {
// check if business startup costs is not zero:
if (cashFlows[0] != 0) {
var noOfCashFlows = cashFlows.length;
var sumCashFlows = 0;
// check if at least 1 positive and 1 negative cash flow exists:
var noOfNegativeCashFlows = 0;
var noOfPositiveCashFlows = 0;
for (var i = 0; i < noOfCashFlows; i++) {
sumCashFlows += cashFlows[i];
if (cashFlows[i] > 0) {
noOfPositiveCashFlows++;
} else {
if (cashFlows[i] < 0) {
noOfNegativeCashFlows++;
}
}
} // at least 1 negative and 1 positive cash flow available?
if (noOfNegativeCashFlows > 0 && noOfPositiveCashFlows > 0) {
// set estimated result:
var irrGuess = 0.1; // default: 10%
if (!isNaN(estimatedResult)) {
irrGuess = estimatedResult;
if (irrGuess <= 0) {
irrGuess = 0.5;
}
} // initialize first IRR with estimated result:
var irr = 0;
if (sumCashFlows < 0) { // sum of cash flows negative?
irr = -irrGuess;
} else { // sum of cash flows not negative
irr = irrGuess;
} // iteration:
// the smaller the distance, the smaller the interpolation
// error
var minDistance = 1e-15; // business startup costs
var cashFlowStart = cashFlows[0];
var maxIteration = 100;
var wasHi = false;
var cashValue = 0;
for (var i = 0; i <= maxIteration; i++) {
// calculate cash value with current irr:
cashValue = cashFlowStart; // init with startup costs // for each cash flow
for (var j = 1; j < noOfCashFlows; j++) {
cashValue += cashFlows[j] / Math.pow(1 + irr, j);
} // cash value is nearly zero
if (Math.abs(cashValue) < 0.01) {
result = irr;
break;
} // adjust irr for next iteration:
// cash value > 0 => next irr > current irr
if (cashValue > 0) {
if (wasHi) {
irrGuess /= 2;
}
irr += irrGuess;
if (wasHi) {
irrGuess -= minDistance;
wasHi = false;
}
} else {// cash value < 0 => next irr < current irr
irrGuess /= 2;
irr -= irrGuess;
wasHi = true;
} // estimated result too small to continue => end
// calculation
if (irrGuess <= minDistance) {
result = irr;
break;
}
}
}
}
}
return result;
}

2. var一个 [] 来验证找到的函数 是否可用

3.调用IRR,estimatedResult设置为0.1,保持与excel默认值一致

excel的IRR函数的更多相关文章

  1. 浅谈Excel开发:六 Excel 异步自定义函数

    上文介绍了Excel中的自定义函数(UDF ),它极大地扩展了Excel插件的功能,使得我们可以将业务逻辑以Excel函数的形式表示,并可以根据这些细粒度的自定义函数,构建各种复杂的分析报表. 普通的 ...

  2. 【Excel 4.0 函数】REGISTER

    REGISTER.ID 返回指定的 DLL 或 代码资源注册过的函数 ID.如果 DLL 或 代码资源没有注册,这个函数将会注册它们,并返回 注册ID. REGISTER.ID 可以用于工作表(不同于 ...

  3. Excel中COUNTIFS函数统计词频个数出现次数

    Excel中COUNTIFS函数统计词频个数出现次数   在Excel中经常需要实现如下需求:在某一列单元格中有不同的词语,有些词语相同,有的不同(如图1所示).需要统计Excel表格中每个词语出现的 ...

  4. [VBA]用一个简单例子说明如何在Excel中自定义函数

    Excel中的函数无疑是强大的,但是再强大的战士也有他脆弱的脚后跟[1].这两天在使用Excel的时候遇到了一个需求,要在某一个单元格里面自动计算今天是星期几(如显示 Today is Tuesday ...

  5. Excel中choose函数的使用方法

    你还在为Excel中choose函数的使用方法而苦恼吗,今天小编教你Excel中choose函数的使用方法,让你告别Excel中choose函数的使用方法的烦恼. 经验主要从四方面对Excel函数进行 ...

  6. Excel公式与函数——每天学一个

    说明(2018-5-29 20:35:53): 1. 根据刘伟的视频讲解进行总结,网上讲Excel公式与函数的貌似就他讲的还不错.在他的微博里看到现在的照片胖了不少,不过还挺帅的,不再是以前那个小屌丝 ...

  7. Excel中Sumproduct函数的使用方法

    1.sumproduct函数的含义 1 1.Sumproduct函数的适用范围,在给定的几组数组中,然后把数组间对应的元素相乘,最后返回乘积之和. 从字面上可以看出,sumproduct有两个英文单词 ...

  8. Excel中concatenate函数的使用方法

    你还在为Excel中concatenate函数的使用方法而苦恼吗,今天小编教你Excel中concatenate函数的使用方法,让你告别Excel中concatenate函数的使用方法的烦恼. 经验主 ...

  9. Excel中IF函数的嵌套用法(多条件)

    Excel中IF函数的嵌套用法(多条件)   Excel中IF函数的嵌套用法(多条件)   函数格式:if(logical_test,value_if_true,value_if_false).其中: ...

随机推荐

  1. java循环控制语句loop使用

    java中break和continue可以跳出指定循环,break和continue之后不加任何循环名则默认跳出其所在的循环,在其后加指定循环名,则可以跳出该指定循环(指定循环一般为循环嵌套的外循环) ...

  2. Kubernetes Dashboard 安装与认证

    1.安装dashboard $ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/ ...

  3. CentOS7 Hive 安装

    hive的安装模式有2种,一种是使用自带的derby数据库,另一种是使用mysql作为元数据库.derby方式一般没人用,因为它是单用户模式.这里主要讲解mysql方式. hive仅仅是一个客户端工具 ...

  4. alicebot

    一.   为什么Alice不支持中文因为Alice的question都会被bitoflife.chatterbean.text.Transformations类中的fit函数过滤,而过滤的表达式就是: ...

  5. Spring Boot Cache使用与整合

    Spring 提供了对缓存功能的抽象:即允许绑定不同的缓存解决方案(如Caffeine.Ehcache等),但本身不直接提供缓存功能的实现.它支持注解方式使用缓存,非常方便. SpringBoot在a ...

  6. C++语言编程规范

    前言 这里参考了<高质量C++C 编程指南 林锐>.<google C++编程指南>以及<华为C++语言编程规范>编写了这份C++语言编程规范文档,以合理使用 C+ ...

  7. 向github项目push代码后,Jenkins实现其自动构建

    配置Jenkins(添加Github服务器) 1.进入[系统管理] --> [系统设置] ,找到[Github] 2.添加Github服务器 这里需要github提供一个密钥文本,我们去gith ...

  8. 全链路追踪技术选型:pinpoint vs skywalking

    目前分布式链路追踪系统基本都是根据谷歌的<Dapper大规模分布式系统的跟踪系统>这篇论文发展而来,主流的有zipkin,pinpoint,skywalking,cat,jaeger等. ...

  9. Nginx 极简入门教程!

    上篇文章和大家聊了 Spring Session 实现 Session 共享的问题,有的小伙伴看了后表示对 Nginx 还是很懵,因此有了这篇文章,算是一个 Nginx 扫盲入门吧! 基本介绍 Ngi ...

  10. 2019-11-29-浅谈-Windows-桌面端触摸架构演进

    原文:2019-11-29-浅谈-Windows-桌面端触摸架构演进 title author date CreateTime categories 浅谈 Windows 桌面端触摸架构演进 lind ...