Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Financial Function
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00096470
Message ID:
00096505
Vues:
16
>I want to write a function for IRR (Internal Rate of Return) and MIRR (Modified Internal Rate of Return). If someone already did it or know anything about IRR and MIRR function or IS there any component ? so please let me know ?
>
>Ashish Kanoongo


* Hello Ashish

* I have been using this function for some years and it works well.
* It helps you with the IRR, but i don't know the MIRR.
* Anyways, they are similar, so i think you can modify the function.
* Please, tell me how it works on your project.
*
*
*
* Juan Carlos.



function tir
parameters xfecha_ini, xtasa_efec

* xtasa_efec = An estimated initial value for IRR.
* xfecha_ini = Initial date.


* Create a table with two fields (Date and value)


create table flujo ;
(tirfflujo d ,;
tirvflujo n(15,2) )

*
*
* Write your code in order to generate the cash flow in the table (Dates and values).
* Remember: Investment must be a negative value.
*
*

*

* Description:
* This function calculates two NPV using two initial values (rates x1 and x2)
* Each NPV (fx1 and fx2) is the basis for estimating the next value (x3)
* The loop is repeated until you get a NPV close to 0.0 or until it tries
* 50 times and returns 0

* Normally, i get the solution during the first 6 - 10 loops.



* tirvtir = IRR (The value you are looking for)

go top

tirvtir = 0
x1 = xtasa_efec / 100 - 0.02
x2 = xtasa_efec / 100 + 0.02
x3 = 0
fx1 = 1
fx2 = 0

if eof()
use
return 0
endif

intentos = 0

do while abs(fx1) > 0.09

intentos = intentos + 1
if intentos = 50
use
return 0
endif

go top
fx1 = 0
fx2 = 0
scan
tiempo = tirfflujo - xfecha_ini
fx1 = fx1 + tirvflujo / (1+x1)^(tiempo/365)
fx2 = fx2 + tirvflujo / (1+x2)^(tiempo/365)
endscan

x3 = round(x2 - (x1-x2) * fx2 / (fx1 - fx2),11)
x1 = x2
x2 = x3

enddo

tirvtir = x1 * 100


return tirvtir
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform