The question is attached Write a SQL function that accepts a principal mortgage amount, an annual percentage rate (APR), and the number of years a mortgage will be paid back over. Calculate the associated monthly mortgage payment according to the following annuity formula: A = P (i + i (1+i)n −1 ) where: A = Monthly Payment Amount P = Principle (Initial) Mortgage Amount i = APR / 12 = Monthly Interest Rate n = years * 12 = Total Number of Payments Be sure to specify that data types of the input arguments have enough significant digits to account for realistic mortgage amounts (as large as in the millions of dollars) and APRs (down to the sixth decimal place will be sufficient). CREATE OR REPLACE FUNCTION monthly_Payment('250000.00', '0.04125', '30') RETURNS @A. LANGUAGE PL/pgsql AS $$ begin Declare @p money = 250000.00 Declare @i decimal (20,8) = 0.04125 Declare @n int = 360 SELECT Monthly payment = @p * ( (@i/12 * power (1 + @i/12, @n)) / ((power (1 + @i/12, @n) -1))) ; end; $$;
The question is attached
Write a SQL function that accepts a principal mortgage amount, an annual percentage
rate (APR), and the number of years a mortgage will be paid back over. Calculate the
associated monthly mortgage payment according to the following annuity formula:
A = P (i + i
(1+i)n −1 )
where:
A = Monthly Payment Amount
P = Principle (Initial) Mortgage Amount
i = APR / 12 = Monthly Interest Rate
n = years * 12 = Total Number of Payments
Be sure to specify that data types of the input arguments have enough significant digits to
account for realistic mortgage amounts (as large as in the millions of dollars) and APRs
(down to the sixth decimal place will be sufficient).
CREATE OR REPLACE FUNCTION monthly_Payment('250000.00', '0.04125', '30')
RETURNS @A.
LANGUAGE PL/pgsql
AS
$$
begin
Declare @p money = 250000.00
Declare @i decimal (20,8) = 0.04125
Declare @n int = 360
SELECT Monthly payment =
@p * ( (@i/12 * power (1 + @i/12, @n)) / ((power (1 + @i/12, @n) -1)))
;
end;
$$;
Trending now
This is a popular solution!
Step by step
Solved in 2 steps