Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculate interest rate
Message
From
14/03/2004 23:04:03
 
 
To
23/02/2004 11:23:23
Joel Leach
Memorial Business Systems, Inc.
Tennessee, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00879962
Message ID:
00886194
Views:
13
>I'm doing a data conversion, and I need to determine the interest rate on each customer's account. The source data does not provide this, but it does provide amount financed, number of payments, the monthly payment, and the total interest expected. Assuming the same rules as VFP's Payment() function, is there any easy way to determine the interest rate from this information?
>
>Thanks.

Hi Joel.

I was facing a similar situation with a financial software some years ago. What you need to calculate is the Internal Return Rate.
I used an iterative method to solve equations, and the solution is found very fast: less than 10 iterations in most cases.
With your values, the solution 0.0083333 is found after 4 iterations. Fast ?
** Internal Return Rate
** Calculates interest rate, based on Cash Flow

LOCAL lyInvestment, lyPayment, lnPayments, lyEstimated, lnInterestRate


lyInvestment = 1000.00

lyPayment = 87.92

lnPayments  = 12

dimension laFlow (lnPayments)  

FOR i = 1 TO lnPayments
	laFlow(i) = lyPayment
ENDFOR


lyEstimated = 0.01     && Assumes any seed value (guess)   i.e  1.00 %

lnInterestRate = IRR (lyInvestment, @laFlow, lyEstimated, lnPayments )





***************************************************************************


FUNCTION IRR

LPARAMETERS tyInvestment, taFlow, tyEstimated, tnPayments


LOCAL x1, x2, x3, fx1, fx2, nTries, j, k

** This is an algorithm to solve equations

**  Assumes first couple of values based on the estimate

x1 = tyEstimated * 0.9    	&&  A value lower than estimate
x2 = tyEstimated * 1.1		&& A value greater than estiamte
x3 = 0
fx1 = 0						&& Calculated function using X1 value
fx2 = 0						&& Calculated function using X2 value

nTries = 0

do while .T.
	
	nTries = nTries + 1
	
	If nTries = 50
		Wait window 'Could not calculate values' 
		RETURN 0.00
	Endif
	
	
	** Calculate Function FX1 .    Net Present value of the cash flow


	FX1 = tyInvestment * (-1)    && Initial investment

	FOR j = 1 TO tnPayments

		FX1 = FX1 + taFlow(j) / ( 1 + x1 ) ^ j	&& Net present value for each cash flow

	ENDFOR

	** IF FX1 is very close to zero, the solution was found (X1)
	** it is not necesary to calculate more iterations.
	
	IF ABS(fx1) < 0.01
		Exit
	ENDIF




	** Calculate Function FX2 .    Net Present value of the cash flow


	FX2 = tyInvestment * (-1)    && Initial investment

	FOR k = 1 TO tnPayments

		FX2 = FX2 + taFlow(k) / ( 1 + x2 ) ^ k	&& Net present value for each cash flow

	ENDFOR


	** Calculates next iteration value  (X3)

	** Avoids division by 0

	IF (fx1 - fx2) <> 0
		x3 = round(x2 - (x1-x2) * fx2 / (fx1 - fx2),11)
	ENDIF

	** Re-Assign values and continue with iterations

	x1 = x2
	x2 = x3	

enddo


** X1 is the solution

X1 = round(X1,4)


WAIT WINDOW TRANSFORM(x1) + " found after " + TRANSFORM(nTries)  + " tries."

RETURN x1
Previous
Reply
Map
View

Click here to load this message in the networking platform