/** * Returns fixed rate mortgage payments in an array. Each payment is an object with the paymentId, the payment amount, the interest and capital portions of the payment, the remaining mortgage balance, and the total amount paid, total interest paid, and total capital reimbursed so far. The calculations have been tested for Canada, which requires fixed rate mortgages to be compounded semi-annually by law. But you can change the annualCompounding in the options. * * If the amortizationPeriod is smaller than the term, an error is thrown. * * These options can be passed in an object as the last parameter: * - id: a string if we want to add an id in the payment objects. * - decimals: the number of decimals to round to. By default, it's 2. * - annualCompounding: how many times the mortgage should be compounded per year. By default, it's 2. * - debug: Will log extra information if true. * * Calculations are based on https://www.yorku.ca/amarshal/mortgage.htm and https://www.mikesukmanowsky.com/blog/a-guide-to-canadian-mortgage-calculations * * @example * Basic usage * ```js * // return the monthly mortgage payments for a $250k loan with a 6.00% rate * const payments = mortgagePayments(250_000, 6, "monthly", 5, 25) * ``` * * @param mortageAmount The amount of the mortgage loan * @param rate The interest rate of the mortgage * @param paymentFrequency The frequency of the mortgage payments * @param term The term of the mortgage in years * @param amortizationPeriod The amortization period of the mortgage in years * @param options Additional options for the mortgage calculation * @param options.id A string if we want to add an id in the payment objects * @param options.decimals The number of decimals to round to. By default, it's 2 * @param options.annualCompounding How many times the mortgage should be compounded per year. By default, it's 2 * @param options.debug Will log extra information if true * * @category Finance */ export default function mortgagePayments(mortageAmount: number, rate: number, paymentFrequency: "weekly" | "biWeekly" | "monthly" | "semiMonthly" | "acceleratedWeekly" | "acceleratedBiWeekly", term: number, amortizationPeriod: number, options?: { id?: string; decimals?: number; annualCompounding?: number; debug?: boolean; }): { id?: string | undefined; paymentId: number; payment: number; interest: number; capital: number; balance: number; amountPaid: number; interestPaid: number; capitalPaid: number; }[];