UNPKG

realestate-jp

Version:

不動産関連のユーティリティ関数を提供するライブラリ

43 lines (42 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isBonusMonth = isBonusMonth; exports.calculateMonthlyInterest = calculateMonthlyInterest; exports.calculateMonthlyPI = calculateMonthlyPI; const constants_js_1 = require("../constants.js"); const constants_js_2 = require("./constants.js"); /** * 指定月がボーナス月か判定する * * @param index 返済開始からの月数(0始まり、例:0 = 1月目、12 = 翌年の1月目) * @returns 指定月がボーナス月であれば true を返却する */ function isBonusMonth(index) { const month = index % constants_js_1.MONTHS_PER_YEAR; return constants_js_2.BONUS_MONTHS.includes(month); } /** * 残元金に対する月利を計算する * * @param loanAmount 借入総額 * @param monthlyPrincipal 月々の元金返済額 * @param monthIndex 現在の月インデックス(0始まり) * @param annualRate 年利(%) * @returns 月利額(円) */ function calculateMonthlyInterest(loanAmount, monthlyPrincipal, monthIndex, annualRate) { const remainingPrincipal = loanAmount - monthlyPrincipal * monthIndex; return remainingPrincipal * (annualRate / 100 / constants_js_1.MONTHS_PER_YEAR); } /** * 元利均等の月額返済額を計算する * * @param principal 借入金額(円) * @param annualRate 年利(%) * @param months 返済期間(月単位) * @returns 月々の返済額(円) */ function calculateMonthlyPI(principal, annualRate, months) { const r = annualRate / 100 / constants_js_1.MONTHS_PER_YEAR; return (principal * r) / (1 - Math.pow(1 + r, -months)); }