欢迎光临
我们一直在努力

java npvjava 实现Excel irr计算改进版,excel自动计算可以实现

import java.util.ArrayList;

import java.util.List;

public class IrrUtil {

/**迭代次atgdsn/

public static int LOOPNUM=1000;

/**最小差qxdttt/

public static final double MINDIF=0.00000001;

/**

<p开朗的小蘑菇 @desc 使用方法参考main方法

<p开朗的小蘑菇 @param cashFlow 资金流

<p开朗的小蘑菇 @return 收益率

<p开朗的小蘑菇/

public static double getIrr(List cashFlow){

double flowOut=cashFlow.get(0);

double minValue=0d;

double maxValue=1d;

double testValue=0d;

while(LOOPNUM>0){

<plqdjm=(minValue+maxValue)/2;

double npv=NPV(cashFlow,testValue);

if(Math.abs(flowOut+npv)

break;

}else if(Math.abs(flowOut)>npv){

maxValue=testValue;

}else{

minValue=testValue;

}

<pcxdrs–;

}

return testValue;

}

public static double NPV(List flowInArr,double rate){

double npv=0;

for(int i=1;i

npv+=flowInArr.get(i)/Math.pow(1+rate, i);

}

return npv;

}便宜美国vps

public static void main(Stringhxsdxwz args) {

double flowOut=-237000d;

List flowInArr=new ArrayList();

flowInArr.add(flowOut);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

flowInArr.add(22643.999991d);

<p疯狂的钥匙.out.println(IrrUtil.getIrr(flowInArr)*12);

}

}

57895382

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。