1
I have a logic problem to calculate NPV and IRR.
Formula for the NPV:
Formula for the IRR:
From these formulas I arrived at the following method:
public double[] calcularVPLTIR () {
if(fluxosProducao == null)
fluxosProducao = fluxoCaixaProducaoDAO.listar(cenario.getIdCenario());
//Cálculo do VPL
double vpl = 0;
int size = fluxosProducao.size();
for(int t = 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};
}
The VPL I think I’ve already done. The IRR is creating me some problems because the value I need is this IRR present in the formula and within the sum.
When you say logic problem, are you referring to not knowing how to solve the mathematical part, or is it some problem in the implementation? Here is a reference of the problematization of calculus, it would be good to give a read: https://pt.wikipedia.org/wiki/Taxa_interna_de_retorno
– Bacco
The mathematical question itself. I have no idea how to get the IRR out of the summation.
– HDeiro
Viva Keynes and formulas that have become political hypotheses defended with hammer and sickle (by people who do not know economy :)). Follow code to get the IRR used by Apache POI (by / Newton Method as in Excel): Code
– Anthony Accioly