Using Math Functions

Using math functions from UDFlib in your stored procedures is easy. You use them just like a function in most other languages.

Description

Mortgage payments are always of Interest. The pmnt stored procedure calculates your mortgage payments based upon, principal, interest rate, and number of payments. It assumes that the interest rate is annual, is compounded annually and that the payments are made monthly.

Example Stored Procedure

CREATE PROCEDURE pmnt(p double precision, i double precision, n integer)

RETURNS (Payments double precision) AS

BEGIN

/*

Calculate the amount of payments that must be made to pay back an inital

payment p

over n periods

with an annual interest rate of i

This similar to how mortgage rates are calcualted.

the formula is payments = P(i/12(1+i/12)^n)/(((1+i/12)^n) -1)

*/

payments = p * (i/12* pow((1+i/12),n) )/( (pow((1+i/12),n) -1));

END!!

WISQL - calling the pmnt stored procedure

execute procedure payments(155000, .10,275);

PAYMENTS

======================

1438.481564202172

execute procedure payments(155000, .06,275);

PAYMENTS

======================

1038.466586147796

Notes:

This is a start but you will want ot add some error checking to on the range of the input variables.