On this website I saw a function, that I would like to use with postgresql:
https://raresql.com/2013/05/16/sql-server-excel-financial-functions-pmt/
Here is the
CREATE OR REPLACE FUNCTION UDF_PMT (
InterestRate NUMERIC(18,8),
Nper INTEGER,
Pv NUMERIC(18,4),
Fv NUMERIC(18,4),
Typ INTEGER
)
RETURNS NUMERIC(18,2)
AS $$
SELECT round(
CASE
WHEN Typ = 0 THEN
(InterestRate / 100) /
(Power(1 + InterestRate / 100, Nper) - 1) *
(Pv * Power(1 + InterestRate / 100, Nper) + Fv)
WHEN Typ = 1 THEN
(InterestRate / 100) /
(Power(1 + InterestRate / 100, Nper) - 1) *
(Pv * Power(1 + InterestRate / 100, Nper) + Fv) /
(1 + InterestRate / 100)
END, 2)
$$ LANGUAGE SQL;