I have a logic problem to calculate the NPV and IRR.
NPV formula:
TIRFormula:
Fromtheseformulas,Icameupwiththefollowingmethod:
publicdouble[]calcularVPLTIR(){if(fluxosProducao==null)fluxosProducao=fluxoCaixaProducaoDAO.listar(cenario.getIdCenario());//CálculodoVPLdoublevpl=0;intsize=fluxosProducao.size();for(intt=0;t<size;t++){System.out.println("Fluxo ano "+t+" = "+fluxosProducao.get(t).getFluxoCaixa());
vpl += fluxosProducao.get(t).getFluxoCaixa() / Math.pow((1 + tributosParametros.getTaxaDesconto()/100), (t+1));
}
System.out.println("DESCONTO = "+tributosParametros.getTaxaDesconto()/100);
System.out.println("VPL ANTES DO ANO 0 = "+vpl);
vpl -= 1261306.64;//cenario.getSaldoFinalFluxoExploracao();
//Cálculo da TIR
double tir = 0.0;
double aux;
do {
aux = 0;
tir += 0.01;
for(int i = 0; i < size; i++)
aux += fluxosProducao.get(i).getFluxoCaixa()/Math.pow((1 + tir), (i+1));
System.out.println("VPL - TIR = "+(aux-vpl));
} while((aux-vpl) < 0);
System.out.println("TIR = "+String.valueOf(tir));
return new double[]{vpl, tir};
}
A VPL I think I've already been able to do. The one in the TIR is creating me some problems because the value I need is this IRR present in the formula and within the summation.