Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting Excel Formula to FoxPro
Message
From
21/08/2007 10:14:32
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01249012
Message ID:
01249366
Views:
20
Hi Julie,

Try these functions. It was a nice exercise:)

Regards,
Sergey
*==================================
FUNCTION Rate_Simple(nPer, nPay, nPrincipal)

LOCAL nRate, nPay0, nDif, nRate2, nPay2

nPay0= nPrincipal/nPer
nDif= nPay - nPay0
IF nDif<=0
	RETURN 0 && zero or no solution
ENDIF

nRate= 2*nDif/nPrincipal &&first approximation
nPay2= PAYMENT(nPrincipal, nRate, nPer)
DO WHILE ABS(nPay2-nPay)*nPer>0.005
	nRate= nRate*nDif/(nPay2-nPay0)
	nPay2= PAYMENT(nPrincipal, nRate, nPer)
ENDDO

RETURN nRate

*==================================
FUNCTION Rate_Fast(nPer, nPay0, nPrincipal)

LOCAL nRate, nPay, nRate1, nPay1, nRate2, nPay2

nRate1= 0
nPay1= nPrincipal/nPer &&min payment
IF nPay0<=nPay1
	RETURN 0 && zero or no solution
ENDIF

nRate2= 2*(nPay0-nPay1)/nPrincipal &&first approximation
nPay2= PAYMENT(nPrincipal, nRate2, nPer)
DO WHILE .T.
	nRate= (nRate2-nRate1)*(nPay0-nPay1)/(nPay2-nPay1) + nRate1
	nPay= PAYMENT(nPrincipal, nRate, nPer)
	DO CASE
		CASE ABS(nPay-nPay0)*nPer<=0.005
	EXIT

		CASE nPay>nPay0
	nRate2= nRate
	nPay2= nPay

		OTHERWISE
	nRate1= nRate
	nPay1= nPay
	ENDCASE 
ENDDO

RETURN nRate
>yes it is. What I am looking for is called equivalent rate.
Previous
Reply
Map
View

Click here to load this message in the networking platform