Internal Rate of Return - Code
Mostra commenti meno recenti
Hi, I'm trying to write a iteration- loop to calculate te internal rate of reuturn (IRR) (without the financial toolbox).
Problems are: how to set the while loop
how to set the iteration steps
solution so far: IRR= -Inf -> why -Inf ?
My code so far:
zaeler=1; %% counter
w(1)=10;
w(2)=0;
IRR=0.05;
IRR1=0.1;
IRR2=0.2;
while zaeler<10000 %% better would be: while interval by 0
for jahr=1:1:25
s(jahr) = (cashflow(jahr)/((1+IRR)^jahr));
end
w(zaeler) = sum(s)-invest ; %% w should be 0
if w(zaeler)>0
IRR=IRR1-(w(1)/(w(2)-w(1)))*(IRR2-IRR1);
IRR1=IRR;
elseif w(zaeler)<0
IRR=IRR1-(w(1)/(w(2)-w(1)))*(IRR2-IRR1);
IRR2=IRR;
end
zaeler=zaeler+1;
end
Thank you in advance for your ideas and help.
3 Commenti
Rik
il 11 Mag 2021
Did you step through your code with the debugger to see when the IRR becomes -inf?
Since you know the number of iterations: why aren't you using a for-loop instead?
Are you sure w will never be 0? Because neither branch will execute in that case, leaving IRR the same for the remaining iterations. Don't you want to put a break statement there?
MK
il 11 Mag 2021
Rik
il 11 Mag 2021
You should step through your code and closely look at what values your variables have after each line.
And why did you write for iteration<10000? It does something, but I expect you want for iteration=1:10000 instead (and remove iteration=iteration+1;).
Risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!