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. prometheus consul docker redis_exporter 自动注册配置

    0.启动redis_exporter redis_exporter: version: '2'services: redis_exporter: image: oliver006/redis_expo ...

  2. mac os 使用 from scipy.misc import imread ImportError: cannot import name 'imread'

    mac os 使用 from scipy.misc import imread ImportError: cannot import name 'imread' 问题1: 我原先安装了 pillow ...

  3. Windbg断点调试.net程序

    程序员都知道,在生产环境中,如果没有系统日志,对问题的分析将非常的困难.即使有日志,有时候也会因为日志记录的不全面,而导致问题不能分析清楚.其实,Windbg里面有Live Debug功能,正好可以借 ...

  4. 基础知识---IEnumerable、ICollection、IList、IQueryable

    一.定义 IEnumerable public interface IEnumerable<out T> : IEnumerable ICollection public interfac ...

  5. HTML--元素居中各种处理方法2

    紧接上一篇. 如果要居中的是一个块元素呢. 1)如果你知道这个块元素的高度: <main> <div> I'm a block-level element with a fix ...

  6. MobaXterm的安装和使用

    MobaXterm的安装和使用 安装 1 下载网址:https://mobaxterm.mobatek.net/,选择“Download”,选择免费版的下载. 2 解压压缩包,双击exe文件安装软件, ...

  7. GET请求的请求参数最大长度

    在HTTP规范RFC-2616中有这样一段描述: The HTTP protocol does not place any a priori limit on the length of a URI. ...

  8. java设计模式单例模式

    创建型模式: – 单例模式.工厂模式.抽象工厂模式.建造者模式.原型模式. • 结构型模式: – 适配器模式.桥接模式.装饰模式.组合模式.外观模式.享元模式.代理模 式. • 行为型模式: – 模版 ...

  9. requests方法中content和text区别

    requests对象的get和post方法都会返回一个Response对象,这个对象里面存的是服务器返回的所有信息,包括响应头,响应状态码等.其中返回的网页部分会存在.content和.text两个对 ...

  10. DjangoDRF总结

    思维导图xmind文件:https://files-cdn.cnblogs.com/files/benjieming/DRF%E6%A8%A1%E5%9D%97.zip