## Java版的IRR(内部收益率)实现 原

kanlianhui

``````public static double irr(double[] income) {
return irr(income, 0.1D);
}

public static double irr(double[] values, double guess) {
int maxIterationCount = 20;
double absoluteAccuracy = 1.0E-007D;

double x0 = guess;

int i = 0;
while (i < maxIterationCount) {
double fValue = 0.0D;
double fDerivative = 0.0D;
for (int k = 0; k < values.length; k++) {
fValue += values[k] / Math.pow(1.0D + x0, k);
fDerivative += -k * values[k] / Math.pow(1.0D + x0, k + 1);
}
double x1 = x0 - fValue / fDerivative;
if (Math.abs(x1 - x0) <= absoluteAccuracy) {
return x1;
}
x0 = x1;
i++;
}
return (0.0D / 0.0D);
}

public static void main(String[] args) {
double[] income = {-9272.49,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,888.49,};
double ret = irr(income,0.00001d) ;
System.out.println(new BigDecimal(ret));

}``````

### 评论(1)

s

Java 10大优点—Part4—Java内存模型

foxlee
2013/12/09
339
1
JDK 9 中有哪些 jmod 文件？

JDK 9 jmods 目录中有97个jmod文件，这些文件都是干嘛的呢？我们在写代码的时候，都应该怎么用呢？ 「Project Jigsaw，或者说Java Modularity想要解决的问题，其实在它的项目官网上有非常精确...

2017/09/23
0
0
Java平台标准版Oracle JDK 9中的新增功能

2017/12/05
0
0

.net工作流系统开发体会 公司的eworkflow自定义工作流系统，最初是开发了java版的。待java版的功能稳定后，就开始开发.net版的。 java版的eworkflow工作流系统，我们没有依赖于任何框架，如s...

2012/10/11
251
0
java程序员基础进阶篇，万丈高楼平地起

05/26
0
0

EOS docker开发环境

12
0
《唐史原来超有趣》的读后感优秀范文3700字

《唐史原来超有趣》的读后感优秀范文3700字： 作者：花若离。我今天分享的内容《唐史原来超有趣》这本书的读后感，我将这本书看了一遍之后就束之高阁了，不过里面的内容一直在在脑海中回放，...

19
0

19
0
CompletableFuture get方法一直阻塞或抛出TimeoutException

xiaolyuh

9
0
dubbo 搭建与使用

20
0