@pyverret/ratejs 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/assertions.ts","../src/interest/cagr.ts","../src/interest/compound.ts","../src/interest/effectiveAnnualRate.ts","../src/interest/futureValue.ts","../src/interest/inflationAdjustedAmount.ts","../src/interest/investmentGrowth.ts","../src/interest/irr.ts","../src/interest/paymentFromPresentValue.ts","../src/interest/periodsToReachGoal.ts","../src/interest/presentValue.ts","../src/interest/presentValueOfAnnuity.ts","../src/interest/rateToReachGoal.ts","../src/interest/realReturn.ts","../src/interest/ruleOf72.ts","../src/loans/loanPayment.ts","../src/loans/amortizationSchedule.ts","../src/loans/payoffPeriodWithExtra.ts","../src/loans/remainingBalance.ts","../src/utils/roundToCurrency.ts"],"names":["presentValue","futureValue","pmt","pv"],"mappings":";;;AAAO,SAAS,kBAAA,CAAmB,OAAe,IAAA,EAAoB;AACpE,EAAA,IAAI,CAAC,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG;AAC3B,IAAA,MAAM,IAAI,UAAA,CAAW,CAAA,EAAG,IAAI,CAAA,wBAAA,CAA0B,CAAA;AAAA,EACxD;AACF;AAEO,SAAS,iBAAA,CAAkB,OAAe,IAAA,EAAoB;AACnE,EAAA,kBAAA,CAAmB,OAAO,IAAI,CAAA;AAC9B,EAAA,IAAI,QAAQ,CAAA,EAAG;AACb,IAAA,MAAM,IAAI,UAAA,CAAW,CAAA,EAAG,IAAI,CAAA,aAAA,CAAe,CAAA;AAAA,EAC7C;AACF;AAEO,SAAS,cAAA,CAAe,OAAe,IAAA,EAAoB;AAChE,EAAA,kBAAA,CAAmB,OAAO,IAAI,CAAA;AAC9B,EAAA,IAAI,SAAS,CAAA,EAAG;AACd,IAAA,MAAM,IAAI,UAAA,CAAW,CAAA,EAAG,IAAI,CAAA,YAAA,CAAc,CAAA;AAAA,EAC5C;AACF;;;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AA,GAAW,CAAA,EAAG,IAAA,GAAO,WAAU,GAAI,MAAA;AAClD,EAAA,kBAAA,CAAmB,OAAO,OAAO,CAAA;AACjC,EAAA,MAAM,IAAI,IAAA,CAAK,GAAA,CAAI,GAAG,IAAA,CAAK,KAAA,CAAM,QAAQ,CAAC,CAAA;AAC1C,EAAA,MAAM,SAAS,EAAA,IAAM,CAAA;AACrB,EAAA,IAAI,SAAS,WAAA,EAAa;AACxB,IAAA,MAAM,SAAS,KAAA,GAAQ,MAAA;AACvB,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA;AACjC,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,GAAA,CAAI,MAAA,GAAS,OAAO,CAAA;AAC3C,IAAA,IAAI,cAAc,GAAA,EAAK;AACrB,MAAA,MAAM,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA;AAC9B,MAAA,OAAA,CAAQ,IAAA,GAAO,CAAA,KAAM,CAAA,GAAI,IAAA,GAAO,OAAO,CAAA,IAAK,MAAA;AAAA,IAC9C;AACA,IAAA,OAAO,OAAA,GAAU,MAAA;AAAA,EACnB;AACA,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,KAAA,GAAQ,MAAM,CAAA,GAAI,MAAA;AACtC","file":"index.cjs","sourcesContent":["export function assertFiniteNumber(value: number, name: string): void {\n if (!Number.isFinite(value)) {\n throw new RangeError(`${name} must be a finite number`);\n }\n}\n\nexport function assertNonNegative(value: number, name: string): void {\n assertFiniteNumber(value, name);\n if (value < 0) {\n throw new RangeError(`${name} must be >= 0`);\n }\n}\n\nexport function assertPositive(value: number, name: string): void {\n assertFiniteNumber(value, name);\n if (value <= 0) {\n throw new RangeError(`${name} must be > 0`);\n }\n}\n","import { assertPositive } from \"../utils/assertions.js\";\n\nexport type CagrParams = {\n startValue: number;\n endValue: number;\n years: number;\n};\n\n/**\n * Compound annual growth rate (CAGR) between start and end value over the given years.\n * CAGR = (endValue/startValue)^(1/years) - 1\n */\nexport function cagr(params: CagrParams): number {\n const { startValue, endValue, years } = params;\n assertPositive(startValue, \"startValue\");\n assertPositive(years, \"years\");\n if (endValue <= 0) return -1;\n return (endValue / startValue) ** (1 / years) - 1;\n}\n","import { assertNonNegative, assertPositive } from \"../utils/assertions.js\";\n\nexport type CompoundParams = {\n principal: number;\n rate: number;\n timesPerYear: number;\n years: number;\n};\n\n/**\n * Computes compound growth using nominal annual `rate` compounded `timesPerYear`.\n * Returns the final amount (principal + interest).\n */\nexport function compound(params: CompoundParams): number {\n const { principal, rate, timesPerYear, years } = params;\n assertNonNegative(principal, \"principal\");\n assertPositive(timesPerYear, \"timesPerYear\");\n assertNonNegative(years, \"years\");\n\n if (rate === 0 || years === 0) return principal;\n\n const n = timesPerYear;\n const t = years;\n return principal * (1 + rate / n) ** (n * t);\n}\n","import { assertFiniteNumber, assertPositive } from \"../utils/assertions.js\";\n\nexport type EffectiveAnnualRateParams = {\n nominalRate: number;\n timesPerYear: number;\n};\n\n/**\n * Converts a nominal annual rate to effective annual rate (EAR).\n * EAR = (1 + nominalRate/timesPerYear)^timesPerYear - 1\n */\nexport function effectiveAnnualRate(params: EffectiveAnnualRateParams): number {\n const { nominalRate, timesPerYear } = params;\n assertFiniteNumber(nominalRate, \"nominalRate\");\n assertPositive(timesPerYear, \"timesPerYear\");\n\n const r = nominalRate / timesPerYear;\n return (1 + r) ** timesPerYear - 1;\n}\n","import { assertNonNegative, assertPositive } from \"../utils/assertions.js\";\n\nexport type FutureValueParams = {\n presentValue: number;\n rate: number;\n timesPerYear: number;\n years: number;\n};\n\n/**\n * Future value of a lump sum using nominal annual `rate` compounded `timesPerYear`.\n */\nexport function futureValue(params: FutureValueParams): number {\n const { presentValue, rate, timesPerYear, years } = params;\n assertNonNegative(presentValue, \"presentValue\");\n assertPositive(timesPerYear, \"timesPerYear\");\n assertNonNegative(years, \"years\");\n\n if (rate === 0 || years === 0) return presentValue;\n\n const n = timesPerYear;\n const t = years;\n return presentValue * (1 + rate / n) ** (n * t);\n}\n","import { assertFiniteNumber, assertNonNegative } from \"../utils/assertions.js\";\n\nexport type InflationAdjustedAmountParams = {\n amount: number;\n annualInflationRate: number;\n years: number;\n direction: \"toPast\" | \"toFuture\";\n};\n\n/**\n * Purchasing power across time. toPast: amount/(1+rate)^years. toFuture: amount*(1+rate)^years.\n */\nexport function inflationAdjustedAmount(params: InflationAdjustedAmountParams): number {\n const { amount, annualInflationRate, years, direction } = params;\n assertFiniteNumber(amount, \"amount\");\n assertFiniteNumber(annualInflationRate, \"annualInflationRate\");\n assertNonNegative(years, \"years\");\n const factor = (1 + annualInflationRate) ** years;\n return direction === \"toPast\" ? amount / factor : amount * factor;\n}\n","import { assertNonNegative, assertPositive } from \"../utils/assertions.js\";\n\nexport type InvestmentGrowthParams = {\n initial: number;\n contributionPerPeriod?: number;\n rate: number;\n timesPerYear: number;\n years: number;\n contributionTiming?: \"end\" | \"begin\";\n};\n\nexport type InvestmentGrowthResult = {\n futureValue: number;\n totalContributions: number;\n totalInterest: number;\n};\n\n/**\n * Future value of an investment with optional periodic contributions.\n *\n * - `rate` is nominal annual rate (e.g. 0.05 for 5%)\n * - contributions occur each compounding period (`timesPerYear`)\n */\nexport function investmentGrowth(params: InvestmentGrowthParams): InvestmentGrowthResult {\n const {\n initial,\n contributionPerPeriod = 0,\n rate,\n timesPerYear,\n years,\n contributionTiming = \"end\",\n } = params;\n\n assertNonNegative(initial, \"initial\");\n assertNonNegative(contributionPerPeriod, \"contributionPerPeriod\");\n assertPositive(timesPerYear, \"timesPerYear\");\n assertNonNegative(years, \"years\");\n\n const periods = Math.round(timesPerYear * years);\n if (periods === 0) {\n return {\n futureValue: initial,\n totalContributions: 0,\n totalInterest: 0,\n };\n }\n\n const r = rate / timesPerYear;\n\n // Lump sum growth\n const fvInitial = rate === 0 ? initial : initial * (1 + r) ** periods;\n\n // Annuity future value (ordinary vs due)\n let fvContrib = 0;\n if (contributionPerPeriod !== 0) {\n if (rate === 0) {\n fvContrib = contributionPerPeriod * periods;\n } else {\n const ordinary = contributionPerPeriod * (((1 + r) ** periods - 1) / r);\n fvContrib = contributionTiming === \"begin\" ? ordinary * (1 + r) : ordinary;\n }\n }\n\n const futureValue = fvInitial + fvContrib;\n const totalContributions = contributionPerPeriod * periods;\n const totalInterest = futureValue - initial - totalContributions;\n\n return { futureValue, totalContributions, totalInterest };\n}\n","import { assertFiniteNumber } from \"../utils/assertions.js\";\n\nexport type IrrParams = {\n cashFlows: number[];\n guess?: number;\n maxIterations?: number;\n};\n\nfunction npv(rate: number, cashFlows: number[]): number {\n let sum = 0;\n for (let t = 0; t < cashFlows.length; t++) {\n const cf = cashFlows[t];\n if (cf !== undefined) sum += cf / (1 + rate) ** t;\n }\n return sum;\n}\n\nfunction npvDerivative(rate: number, cashFlows: number[]): number {\n let sum = 0;\n for (let t = 1; t < cashFlows.length; t++) {\n const cf = cashFlows[t];\n if (cf !== undefined) sum -= (t * cf) / (1 + rate) ** (t + 1);\n }\n return sum;\n}\n\nexport function irr(params: IrrParams): number {\n const { cashFlows, guess = 0.1, maxIterations = 100 } = params;\n if (cashFlows.length === 0) return NaN;\n for (const cf of cashFlows) assertFiniteNumber(cf, \"cashFlows[]\");\n let r = guess;\n for (let i = 0; i < maxIterations; i++) {\n const val = npv(r, cashFlows);\n if (Math.abs(val) < 1e-10) return r;\n const der = npvDerivative(r, cashFlows);\n if (!Number.isFinite(der) || Math.abs(der) < 1e-15) break;\n r = r - val / der;\n if (r < -0.99) r = -0.99;\n if (r > 10) r = 10;\n }\n return r;\n}\n","import { assertNonNegative } from \"../utils/assertions.js\";\n\nexport type PaymentFromPresentValueParams = {\n presentValue: number;\n ratePerPeriod: number;\n periods: number;\n /** Payment at start of each period (annuity due). Default end (ordinary). */\n timing?: \"end\" | \"begin\";\n};\n\n/**\n * Periodic payment required to pay off a present value (e.g. loan) over periods.\n * PMT = PV * r / (1 - (1+r)^-n). For due: divide by (1+r).\n */\nexport function paymentFromPresentValue(params: PaymentFromPresentValueParams): number {\n const { presentValue, ratePerPeriod, periods, timing = \"end\" } = params;\n assertNonNegative(presentValue, \"presentValue\");\n assertNonNegative(periods, \"periods\");\n\n if (presentValue === 0 || periods === 0) return 0;\n if (ratePerPeriod === 0) {\n const pmt = presentValue / periods;\n return timing === \"begin\" ? pmt / (1 + ratePerPeriod) : pmt;\n }\n let pmt = (ratePerPeriod * presentValue) / (1 - (1 + ratePerPeriod) ** -periods);\n if (timing === \"begin\") pmt /= 1 + ratePerPeriod;\n return pmt;\n}\n","import { assertFiniteNumber, assertNonNegative, assertPositive } from \"../utils/assertions.js\";\n\nexport type PeriodsToReachGoalParams = {\n principal: number;\n targetFutureValue: number;\n rate: number;\n timesPerYear: number;\n contributionPerPeriod?: number;\n contributionTiming?: \"end\" | \"begin\";\n};\n\n/**\n * Number of compounding periods until future value reaches the goal.\n * With no contributions: closed form. With contributions: iterative.\n */\nexport function periodsToReachGoal(params: PeriodsToReachGoalParams): number {\n const {\n principal,\n targetFutureValue,\n rate,\n timesPerYear,\n contributionPerPeriod = 0,\n contributionTiming = \"end\",\n } = params;\n\n assertNonNegative(principal, \"principal\");\n assertNonNegative(targetFutureValue, \"targetFutureValue\");\n assertFiniteNumber(rate, \"rate\");\n assertPositive(timesPerYear, \"timesPerYear\");\n assertNonNegative(contributionPerPeriod, \"contributionPerPeriod\");\n\n if (targetFutureValue <= principal) return 0;\n\n const r = rate / timesPerYear;\n if (r <= -1) {\n throw new RangeError(\"rate / timesPerYear must be > -1\");\n }\n\n if (contributionPerPeriod === 0) {\n if (principal === 0) return Number.POSITIVE_INFINITY;\n if (rate === 0) return targetFutureValue <= principal ? 0 : Number.POSITIVE_INFINITY;\n if (r < 0) return Number.POSITIVE_INFINITY;\n const n = Math.log(targetFutureValue / principal) / Math.log(1 + r);\n return Number.isFinite(n) && n >= 0 ? Math.ceil(n) : Number.POSITIVE_INFINITY;\n }\n\n if (rate === 0) {\n const needed = targetFutureValue - principal;\n if (needed <= 0) return 0;\n return Math.ceil(needed / contributionPerPeriod);\n }\n\n // With contributions: iterate until FV >= target\n let fv = principal;\n let periods = 0;\n const maxPeriods = 10000;\n while (fv < targetFutureValue && periods < maxPeriods) {\n if (contributionTiming === \"begin\") fv += contributionPerPeriod;\n fv = fv * (1 + r) + (contributionTiming === \"end\" ? contributionPerPeriod : 0);\n periods++;\n }\n return fv >= targetFutureValue ? periods : Number.POSITIVE_INFINITY;\n}\n","import { assertNonNegative, assertPositive } from \"../utils/assertions.js\";\n\nexport type PresentValueParams = {\n futureValue: number;\n rate: number;\n timesPerYear: number;\n years: number;\n};\n\n/**\n * Present value of a lump sum using nominal annual `rate` compounded `timesPerYear`.\n */\nexport function presentValue(params: PresentValueParams): number {\n const { futureValue: fv, rate, timesPerYear, years } = params;\n assertNonNegative(fv, \"futureValue\");\n assertPositive(timesPerYear, \"timesPerYear\");\n assertNonNegative(years, \"years\");\n\n if (rate === 0 || years === 0) return fv;\n\n const n = timesPerYear;\n const t = years;\n return fv / (1 + rate / n) ** (n * t);\n}\n","import { assertNonNegative } from \"../utils/assertions.js\";\n\nexport type PresentValueOfAnnuityParams = {\n paymentPerPeriod: number;\n ratePerPeriod: number;\n periods: number;\n timing?: \"end\" | \"begin\";\n};\n\n/**\n * Present value of an annuity. PV = PMT * (1 - (1+r)^-n) / r. Due: multiply by (1+r).\n */\nexport function presentValueOfAnnuity(params: PresentValueOfAnnuityParams): number {\n const { paymentPerPeriod, ratePerPeriod, periods, timing = \"end\" } = params;\n assertNonNegative(paymentPerPeriod, \"paymentPerPeriod\");\n assertNonNegative(periods, \"periods\");\n\n if (periods === 0) return 0;\n if (ratePerPeriod === 0) {\n const pv = paymentPerPeriod * periods;\n return timing === \"begin\" ? pv * (1 + ratePerPeriod) : pv;\n }\n const pv = (paymentPerPeriod * (1 - (1 + ratePerPeriod) ** -periods)) / ratePerPeriod;\n return timing === \"begin\" ? pv * (1 + ratePerPeriod) : pv;\n}\n","import { assertNonNegative, assertPositive } from \"../utils/assertions.js\";\n\nexport type RateToReachGoalParams = {\n principal: number;\n targetFutureValue: number;\n periods: number;\n contributionPerPeriod?: number;\n contributionTiming?: \"end\" | \"begin\";\n};\n\n/**\n * Rate per period required to reach target future value in given periods.\n * Uses Newton-Raphson when contributions are present; closed form for lump sum.\n */\nexport function rateToReachGoal(params: RateToReachGoalParams): number {\n const {\n principal,\n targetFutureValue,\n periods,\n contributionPerPeriod = 0,\n contributionTiming = \"end\",\n } = params;\n\n assertNonNegative(principal, \"principal\");\n assertNonNegative(targetFutureValue, \"targetFutureValue\");\n assertPositive(periods, \"periods\");\n assertNonNegative(contributionPerPeriod, \"contributionPerPeriod\");\n\n if (periods === 0) return 0;\n if (targetFutureValue <= principal && contributionPerPeriod === 0) return 0;\n\n if (contributionPerPeriod === 0) {\n if (targetFutureValue <= principal) return 0;\n return (targetFutureValue / principal) ** (1 / periods) - 1;\n }\n\n // FV = principal*(1+r)^n + PMT * ((1+r)^n - 1)/r (ordinary) or PMT * (1+r) * ((1+r)^n - 1)/r (due)\n // Solve for r with Newton-Raphson\n const dueFactor = contributionTiming === \"begin\" ? 1 : 0;\n let r = (targetFutureValue / (principal + contributionPerPeriod * periods)) ** (1 / periods) - 1;\n if (r <= -1) r = 0.01;\n\n for (let i = 0; i < 100; i++) {\n const onePlusR = 1 + r;\n const onePlusRN = onePlusR ** periods;\n const fvLump = principal * onePlusRN;\n const annuity = contributionPerPeriod * ((onePlusRN - 1) / (r || 1e-14)) * (1 + dueFactor * r);\n const fv = fvLump + annuity;\n const err = fv - targetFutureValue;\n if (Math.abs(err) < 1e-10) return r;\n // Derivative approximation\n const dr = r * 1e-6 || 1e-10;\n const r2 = r + dr;\n const onePlusR2 = 1 + r2;\n const onePlusR2N = onePlusR2 ** periods;\n const fv2 =\n principal * onePlusR2N +\n contributionPerPeriod * ((onePlusR2N - 1) / r2) * (1 + dueFactor * r2);\n const dFvDr = (fv2 - fv) / dr;\n r = r - err / dFvDr;\n if (r <= -1) r = 0.01;\n if (r > 10) r = 10;\n }\n return r;\n}\n","import { assertFiniteNumber } from \"../utils/assertions.js\";\n\nexport type RealReturnParams = { nominalReturn: number; inflationRate: number };\n\nexport function realReturn(params: RealReturnParams): number {\n const { nominalReturn, inflationRate } = params;\n assertFiniteNumber(nominalReturn, \"nominalReturn\");\n assertFiniteNumber(inflationRate, \"inflationRate\");\n if (inflationRate <= -1) return NaN;\n return (1 + nominalReturn) / (1 + inflationRate) - 1;\n}\n","import { assertFiniteNumber, assertPositive } from \"../utils/assertions.js\";\n\nexport type RuleOf72Params = {\n rate: number;\n /** Use 69 for continuous-ish approximation (e.g. daily compounding). Default 72. */\n constant?: 72 | 69;\n};\n\n/**\n * Approximate years to double a lump sum at the given annual rate.\n * rate is decimal (e.g. 0.07 for 7%). Uses rule of 72 by default, or 69 if specified.\n */\nexport function ruleOf72(params: RuleOf72Params): number {\n const { rate, constant = 72 } = params;\n assertFiniteNumber(rate, \"rate\");\n assertPositive(rate, \"rate\");\n return constant / 100 / rate;\n}\n","import { assertNonNegative, assertPositive } from \"../utils/assertions.js\";\n\nexport type LoanPaymentParams = {\n principal: number;\n annualRate: number;\n paymentsPerYear: number;\n years: number;\n};\n\n/**\n * Fixed periodic payment for an amortizing loan.\n *\n * - `annualRate` is nominal annual rate (e.g. 0.06 for 6%)\n * - payment returned is per period (`paymentsPerYear`)\n */\nexport function loanPayment(params: LoanPaymentParams): number {\n const { principal, annualRate, paymentsPerYear, years } = params;\n assertNonNegative(principal, \"principal\");\n assertPositive(paymentsPerYear, \"paymentsPerYear\");\n assertNonNegative(years, \"years\");\n\n const n = Math.round(paymentsPerYear * years);\n if (n === 0) return 0;\n\n const r = annualRate / paymentsPerYear;\n if (r === 0) return principal / n;\n\n return (r * principal) / (1 - (1 + r) ** -n);\n}\n","import { assertNonNegative, assertPositive } from \"../utils/assertions.js\";\nimport { loanPayment } from \"./loanPayment.js\";\n\nexport type AmortizationScheduleParams = {\n principal: number;\n annualRate: number;\n paymentsPerYear: number;\n years: number;\n extraPaymentPerPeriod?: number;\n};\n\nexport type AmortizationRow = {\n period: number;\n payment: number;\n principalPayment: number;\n interestPayment: number;\n balance: number;\n};\n\nexport type AmortizationScheduleResult = {\n paymentPerPeriod: number;\n schedule: AmortizationRow[];\n totalPaid: number;\n totalInterest: number;\n};\n\nexport function amortizationSchedule(\n params: AmortizationScheduleParams,\n): AmortizationScheduleResult {\n const { principal, annualRate, paymentsPerYear, years, extraPaymentPerPeriod = 0 } = params;\n assertNonNegative(principal, \"principal\");\n assertPositive(paymentsPerYear, \"paymentsPerYear\");\n assertNonNegative(years, \"years\");\n assertNonNegative(extraPaymentPerPeriod, \"extraPaymentPerPeriod\");\n\n const scheduledN = Math.round(paymentsPerYear * years);\n if (scheduledN === 0 || principal === 0) {\n return { paymentPerPeriod: 0, schedule: [], totalPaid: 0, totalInterest: 0 };\n }\n\n const basePayment = loanPayment({ principal, annualRate, paymentsPerYear, years });\n const r = annualRate / paymentsPerYear;\n\n const schedule: AmortizationRow[] = [];\n let balance = principal;\n let totalPaid = 0;\n let totalInterest = 0;\n\n for (let period = 1; period <= scheduledN && balance > 0; period++) {\n const interestPayment = r === 0 ? 0 : balance * r;\n let payment = basePayment + extraPaymentPerPeriod;\n let principalPayment = payment - interestPayment;\n\n if (principalPayment > balance) {\n principalPayment = balance;\n payment = principalPayment + interestPayment;\n }\n\n balance = balance - principalPayment;\n if (Math.abs(balance) < 1e-12) balance = 0;\n\n totalPaid += payment;\n totalInterest += interestPayment;\n\n schedule.push({\n period,\n payment,\n principalPayment,\n interestPayment,\n balance,\n });\n }\n\n return {\n paymentPerPeriod: basePayment,\n schedule,\n totalPaid,\n totalInterest,\n };\n}\n","import { assertFiniteNumber, assertNonNegative, assertPositive } from \"../utils/assertions.js\";\n\nexport type PayoffPeriodWithExtraParams = {\n principal: number;\n annualRate: number;\n paymentsPerYear: number;\n basePaymentPerPeriod: number;\n extraPaymentPerPeriod: number;\n};\n\n/**\n * Number of periods until the loan is paid off with the given base + extra payment.\n */\nexport function payoffPeriodWithExtra(params: PayoffPeriodWithExtraParams): number {\n const { principal, annualRate, paymentsPerYear, basePaymentPerPeriod, extraPaymentPerPeriod } =\n params;\n\n assertNonNegative(principal, \"principal\");\n assertFiniteNumber(annualRate, \"annualRate\");\n assertPositive(paymentsPerYear, \"paymentsPerYear\");\n assertNonNegative(basePaymentPerPeriod, \"basePaymentPerPeriod\");\n assertNonNegative(extraPaymentPerPeriod, \"extraPaymentPerPeriod\");\n\n if (principal <= 0) return 0;\n const payment = basePaymentPerPeriod + extraPaymentPerPeriod;\n if (payment <= 0) return Number.POSITIVE_INFINITY;\n\n const r = annualRate / paymentsPerYear;\n let balance = principal;\n let period = 0;\n\n while (balance > 1e-12 && period < 100000) {\n const interest = r > 0 ? balance * r : 0;\n if (payment <= interest) return Number.POSITIVE_INFINITY;\n const principalPaid = Math.min(payment - interest, balance);\n balance -= principalPaid;\n period++;\n }\n return balance <= 1e-12 ? period : Number.POSITIVE_INFINITY;\n}\n","import { assertNonNegative, assertPositive } from \"../utils/assertions.js\";\nimport { loanPayment } from \"./loanPayment.js\";\n\nexport type RemainingBalanceParams = {\n principal: number;\n annualRate: number;\n paymentsPerYear: number;\n years: number;\n afterPeriodNumber: number;\n};\n\n/**\n * Remaining balance after a given number of payments on an amortizing loan.\n */\nexport function remainingBalance(params: RemainingBalanceParams): number {\n const { principal, annualRate, paymentsPerYear, years, afterPeriodNumber } = params;\n assertNonNegative(principal, \"principal\");\n assertPositive(paymentsPerYear, \"paymentsPerYear\");\n assertNonNegative(years, \"years\");\n assertNonNegative(afterPeriodNumber, \"afterPeriodNumber\");\n\n const n = Math.round(paymentsPerYear * years);\n if (n === 0 || afterPeriodNumber >= n) return 0;\n if (afterPeriodNumber <= 0) return principal;\n\n const payment = loanPayment({ principal, annualRate, paymentsPerYear, years });\n const r = annualRate / paymentsPerYear;\n const k = afterPeriodNumber;\n\n if (r === 0) return Math.max(0, principal - payment * k);\n const balance = principal * (1 + r) ** k - payment * (((1 + r) ** k - 1) / r);\n return Math.max(0, balance);\n}\n","import { assertFiniteNumber } from \"./assertions.js\";\n\nexport type RoundToCurrencyParams = {\n value: number;\n /** Decimal places. Default 2. */\n decimals?: number;\n /** 'half-up': 0.5 rounds up. 'half-even': banker's rounding. Default 'half-up'. */\n mode?: \"half-up\" | \"half-even\";\n};\n\n/**\n * Rounds a number to currency (default 2 decimals). half-up: 2.125 -> 2.13. half-even: 2.125 -> 2.12.\n */\nexport function roundToCurrency(params: RoundToCurrencyParams): number {\n const { value, decimals = 2, mode = \"half-up\" } = params;\n assertFiniteNumber(value, \"value\");\n const d = Math.max(0, Math.floor(decimals));\n const factor = 10 ** d;\n if (mode === \"half-even\") {\n const scaled = value * factor;\n const rounded = Math.round(scaled);\n const remainder = Math.abs(scaled - rounded);\n if (remainder === 0.5) {\n const down = Math.floor(scaled);\n return (down % 2 === 0 ? down : down + 1) / factor;\n }\n return rounded / factor;\n }\n return Math.round(value * factor) / factor;\n}\n"]}
@@ -0,0 +1,235 @@
1
+ type CagrParams = {
2
+ startValue: number;
3
+ endValue: number;
4
+ years: number;
5
+ };
6
+ /**
7
+ * Compound annual growth rate (CAGR) between start and end value over the given years.
8
+ * CAGR = (endValue/startValue)^(1/years) - 1
9
+ */
10
+ declare function cagr(params: CagrParams): number;
11
+
12
+ type CompoundParams = {
13
+ principal: number;
14
+ rate: number;
15
+ timesPerYear: number;
16
+ years: number;
17
+ };
18
+ /**
19
+ * Computes compound growth using nominal annual `rate` compounded `timesPerYear`.
20
+ * Returns the final amount (principal + interest).
21
+ */
22
+ declare function compound(params: CompoundParams): number;
23
+
24
+ type EffectiveAnnualRateParams = {
25
+ nominalRate: number;
26
+ timesPerYear: number;
27
+ };
28
+ /**
29
+ * Converts a nominal annual rate to effective annual rate (EAR).
30
+ * EAR = (1 + nominalRate/timesPerYear)^timesPerYear - 1
31
+ */
32
+ declare function effectiveAnnualRate(params: EffectiveAnnualRateParams): number;
33
+
34
+ type FutureValueParams = {
35
+ presentValue: number;
36
+ rate: number;
37
+ timesPerYear: number;
38
+ years: number;
39
+ };
40
+ /**
41
+ * Future value of a lump sum using nominal annual `rate` compounded `timesPerYear`.
42
+ */
43
+ declare function futureValue(params: FutureValueParams): number;
44
+
45
+ type InflationAdjustedAmountParams = {
46
+ amount: number;
47
+ annualInflationRate: number;
48
+ years: number;
49
+ direction: "toPast" | "toFuture";
50
+ };
51
+ /**
52
+ * Purchasing power across time. toPast: amount/(1+rate)^years. toFuture: amount*(1+rate)^years.
53
+ */
54
+ declare function inflationAdjustedAmount(params: InflationAdjustedAmountParams): number;
55
+
56
+ type InvestmentGrowthParams = {
57
+ initial: number;
58
+ contributionPerPeriod?: number;
59
+ rate: number;
60
+ timesPerYear: number;
61
+ years: number;
62
+ contributionTiming?: "end" | "begin";
63
+ };
64
+ type InvestmentGrowthResult = {
65
+ futureValue: number;
66
+ totalContributions: number;
67
+ totalInterest: number;
68
+ };
69
+ /**
70
+ * Future value of an investment with optional periodic contributions.
71
+ *
72
+ * - `rate` is nominal annual rate (e.g. 0.05 for 5%)
73
+ * - contributions occur each compounding period (`timesPerYear`)
74
+ */
75
+ declare function investmentGrowth(params: InvestmentGrowthParams): InvestmentGrowthResult;
76
+
77
+ type IrrParams = {
78
+ cashFlows: number[];
79
+ guess?: number;
80
+ maxIterations?: number;
81
+ };
82
+ declare function irr(params: IrrParams): number;
83
+
84
+ type PaymentFromPresentValueParams = {
85
+ presentValue: number;
86
+ ratePerPeriod: number;
87
+ periods: number;
88
+ /** Payment at start of each period (annuity due). Default end (ordinary). */
89
+ timing?: "end" | "begin";
90
+ };
91
+ /**
92
+ * Periodic payment required to pay off a present value (e.g. loan) over periods.
93
+ * PMT = PV * r / (1 - (1+r)^-n). For due: divide by (1+r).
94
+ */
95
+ declare function paymentFromPresentValue(params: PaymentFromPresentValueParams): number;
96
+
97
+ type PeriodsToReachGoalParams = {
98
+ principal: number;
99
+ targetFutureValue: number;
100
+ rate: number;
101
+ timesPerYear: number;
102
+ contributionPerPeriod?: number;
103
+ contributionTiming?: "end" | "begin";
104
+ };
105
+ /**
106
+ * Number of compounding periods until future value reaches the goal.
107
+ * With no contributions: closed form. With contributions: iterative.
108
+ */
109
+ declare function periodsToReachGoal(params: PeriodsToReachGoalParams): number;
110
+
111
+ type PresentValueParams = {
112
+ futureValue: number;
113
+ rate: number;
114
+ timesPerYear: number;
115
+ years: number;
116
+ };
117
+ /**
118
+ * Present value of a lump sum using nominal annual `rate` compounded `timesPerYear`.
119
+ */
120
+ declare function presentValue(params: PresentValueParams): number;
121
+
122
+ type PresentValueOfAnnuityParams = {
123
+ paymentPerPeriod: number;
124
+ ratePerPeriod: number;
125
+ periods: number;
126
+ timing?: "end" | "begin";
127
+ };
128
+ /**
129
+ * Present value of an annuity. PV = PMT * (1 - (1+r)^-n) / r. Due: multiply by (1+r).
130
+ */
131
+ declare function presentValueOfAnnuity(params: PresentValueOfAnnuityParams): number;
132
+
133
+ type RateToReachGoalParams = {
134
+ principal: number;
135
+ targetFutureValue: number;
136
+ periods: number;
137
+ contributionPerPeriod?: number;
138
+ contributionTiming?: "end" | "begin";
139
+ };
140
+ /**
141
+ * Rate per period required to reach target future value in given periods.
142
+ * Uses Newton-Raphson when contributions are present; closed form for lump sum.
143
+ */
144
+ declare function rateToReachGoal(params: RateToReachGoalParams): number;
145
+
146
+ type RealReturnParams = {
147
+ nominalReturn: number;
148
+ inflationRate: number;
149
+ };
150
+ declare function realReturn(params: RealReturnParams): number;
151
+
152
+ type RuleOf72Params = {
153
+ rate: number;
154
+ /** Use 69 for continuous-ish approximation (e.g. daily compounding). Default 72. */
155
+ constant?: 72 | 69;
156
+ };
157
+ /**
158
+ * Approximate years to double a lump sum at the given annual rate.
159
+ * rate is decimal (e.g. 0.07 for 7%). Uses rule of 72 by default, or 69 if specified.
160
+ */
161
+ declare function ruleOf72(params: RuleOf72Params): number;
162
+
163
+ type AmortizationScheduleParams = {
164
+ principal: number;
165
+ annualRate: number;
166
+ paymentsPerYear: number;
167
+ years: number;
168
+ extraPaymentPerPeriod?: number;
169
+ };
170
+ type AmortizationRow = {
171
+ period: number;
172
+ payment: number;
173
+ principalPayment: number;
174
+ interestPayment: number;
175
+ balance: number;
176
+ };
177
+ type AmortizationScheduleResult = {
178
+ paymentPerPeriod: number;
179
+ schedule: AmortizationRow[];
180
+ totalPaid: number;
181
+ totalInterest: number;
182
+ };
183
+ declare function amortizationSchedule(params: AmortizationScheduleParams): AmortizationScheduleResult;
184
+
185
+ type LoanPaymentParams = {
186
+ principal: number;
187
+ annualRate: number;
188
+ paymentsPerYear: number;
189
+ years: number;
190
+ };
191
+ /**
192
+ * Fixed periodic payment for an amortizing loan.
193
+ *
194
+ * - `annualRate` is nominal annual rate (e.g. 0.06 for 6%)
195
+ * - payment returned is per period (`paymentsPerYear`)
196
+ */
197
+ declare function loanPayment(params: LoanPaymentParams): number;
198
+
199
+ type PayoffPeriodWithExtraParams = {
200
+ principal: number;
201
+ annualRate: number;
202
+ paymentsPerYear: number;
203
+ basePaymentPerPeriod: number;
204
+ extraPaymentPerPeriod: number;
205
+ };
206
+ /**
207
+ * Number of periods until the loan is paid off with the given base + extra payment.
208
+ */
209
+ declare function payoffPeriodWithExtra(params: PayoffPeriodWithExtraParams): number;
210
+
211
+ type RemainingBalanceParams = {
212
+ principal: number;
213
+ annualRate: number;
214
+ paymentsPerYear: number;
215
+ years: number;
216
+ afterPeriodNumber: number;
217
+ };
218
+ /**
219
+ * Remaining balance after a given number of payments on an amortizing loan.
220
+ */
221
+ declare function remainingBalance(params: RemainingBalanceParams): number;
222
+
223
+ type RoundToCurrencyParams = {
224
+ value: number;
225
+ /** Decimal places. Default 2. */
226
+ decimals?: number;
227
+ /** 'half-up': 0.5 rounds up. 'half-even': banker's rounding. Default 'half-up'. */
228
+ mode?: "half-up" | "half-even";
229
+ };
230
+ /**
231
+ * Rounds a number to currency (default 2 decimals). half-up: 2.125 -> 2.13. half-even: 2.125 -> 2.12.
232
+ */
233
+ declare function roundToCurrency(params: RoundToCurrencyParams): number;
234
+
235
+ export { type AmortizationRow, type AmortizationScheduleParams, type AmortizationScheduleResult, type CagrParams, type CompoundParams, type EffectiveAnnualRateParams, type FutureValueParams, type InflationAdjustedAmountParams, type InvestmentGrowthParams, type InvestmentGrowthResult, type IrrParams, type LoanPaymentParams, type PaymentFromPresentValueParams, type PayoffPeriodWithExtraParams, type PeriodsToReachGoalParams, type PresentValueOfAnnuityParams, type PresentValueParams, type RateToReachGoalParams, type RealReturnParams, type RemainingBalanceParams, type RoundToCurrencyParams, type RuleOf72Params, amortizationSchedule, cagr, compound, effectiveAnnualRate, futureValue, inflationAdjustedAmount, investmentGrowth, irr, loanPayment, paymentFromPresentValue, payoffPeriodWithExtra, periodsToReachGoal, presentValue, presentValueOfAnnuity, rateToReachGoal, realReturn, remainingBalance, roundToCurrency, ruleOf72 };
@@ -0,0 +1,235 @@
1
+ type CagrParams = {
2
+ startValue: number;
3
+ endValue: number;
4
+ years: number;
5
+ };
6
+ /**
7
+ * Compound annual growth rate (CAGR) between start and end value over the given years.
8
+ * CAGR = (endValue/startValue)^(1/years) - 1
9
+ */
10
+ declare function cagr(params: CagrParams): number;
11
+
12
+ type CompoundParams = {
13
+ principal: number;
14
+ rate: number;
15
+ timesPerYear: number;
16
+ years: number;
17
+ };
18
+ /**
19
+ * Computes compound growth using nominal annual `rate` compounded `timesPerYear`.
20
+ * Returns the final amount (principal + interest).
21
+ */
22
+ declare function compound(params: CompoundParams): number;
23
+
24
+ type EffectiveAnnualRateParams = {
25
+ nominalRate: number;
26
+ timesPerYear: number;
27
+ };
28
+ /**
29
+ * Converts a nominal annual rate to effective annual rate (EAR).
30
+ * EAR = (1 + nominalRate/timesPerYear)^timesPerYear - 1
31
+ */
32
+ declare function effectiveAnnualRate(params: EffectiveAnnualRateParams): number;
33
+
34
+ type FutureValueParams = {
35
+ presentValue: number;
36
+ rate: number;
37
+ timesPerYear: number;
38
+ years: number;
39
+ };
40
+ /**
41
+ * Future value of a lump sum using nominal annual `rate` compounded `timesPerYear`.
42
+ */
43
+ declare function futureValue(params: FutureValueParams): number;
44
+
45
+ type InflationAdjustedAmountParams = {
46
+ amount: number;
47
+ annualInflationRate: number;
48
+ years: number;
49
+ direction: "toPast" | "toFuture";
50
+ };
51
+ /**
52
+ * Purchasing power across time. toPast: amount/(1+rate)^years. toFuture: amount*(1+rate)^years.
53
+ */
54
+ declare function inflationAdjustedAmount(params: InflationAdjustedAmountParams): number;
55
+
56
+ type InvestmentGrowthParams = {
57
+ initial: number;
58
+ contributionPerPeriod?: number;
59
+ rate: number;
60
+ timesPerYear: number;
61
+ years: number;
62
+ contributionTiming?: "end" | "begin";
63
+ };
64
+ type InvestmentGrowthResult = {
65
+ futureValue: number;
66
+ totalContributions: number;
67
+ totalInterest: number;
68
+ };
69
+ /**
70
+ * Future value of an investment with optional periodic contributions.
71
+ *
72
+ * - `rate` is nominal annual rate (e.g. 0.05 for 5%)
73
+ * - contributions occur each compounding period (`timesPerYear`)
74
+ */
75
+ declare function investmentGrowth(params: InvestmentGrowthParams): InvestmentGrowthResult;
76
+
77
+ type IrrParams = {
78
+ cashFlows: number[];
79
+ guess?: number;
80
+ maxIterations?: number;
81
+ };
82
+ declare function irr(params: IrrParams): number;
83
+
84
+ type PaymentFromPresentValueParams = {
85
+ presentValue: number;
86
+ ratePerPeriod: number;
87
+ periods: number;
88
+ /** Payment at start of each period (annuity due). Default end (ordinary). */
89
+ timing?: "end" | "begin";
90
+ };
91
+ /**
92
+ * Periodic payment required to pay off a present value (e.g. loan) over periods.
93
+ * PMT = PV * r / (1 - (1+r)^-n). For due: divide by (1+r).
94
+ */
95
+ declare function paymentFromPresentValue(params: PaymentFromPresentValueParams): number;
96
+
97
+ type PeriodsToReachGoalParams = {
98
+ principal: number;
99
+ targetFutureValue: number;
100
+ rate: number;
101
+ timesPerYear: number;
102
+ contributionPerPeriod?: number;
103
+ contributionTiming?: "end" | "begin";
104
+ };
105
+ /**
106
+ * Number of compounding periods until future value reaches the goal.
107
+ * With no contributions: closed form. With contributions: iterative.
108
+ */
109
+ declare function periodsToReachGoal(params: PeriodsToReachGoalParams): number;
110
+
111
+ type PresentValueParams = {
112
+ futureValue: number;
113
+ rate: number;
114
+ timesPerYear: number;
115
+ years: number;
116
+ };
117
+ /**
118
+ * Present value of a lump sum using nominal annual `rate` compounded `timesPerYear`.
119
+ */
120
+ declare function presentValue(params: PresentValueParams): number;
121
+
122
+ type PresentValueOfAnnuityParams = {
123
+ paymentPerPeriod: number;
124
+ ratePerPeriod: number;
125
+ periods: number;
126
+ timing?: "end" | "begin";
127
+ };
128
+ /**
129
+ * Present value of an annuity. PV = PMT * (1 - (1+r)^-n) / r. Due: multiply by (1+r).
130
+ */
131
+ declare function presentValueOfAnnuity(params: PresentValueOfAnnuityParams): number;
132
+
133
+ type RateToReachGoalParams = {
134
+ principal: number;
135
+ targetFutureValue: number;
136
+ periods: number;
137
+ contributionPerPeriod?: number;
138
+ contributionTiming?: "end" | "begin";
139
+ };
140
+ /**
141
+ * Rate per period required to reach target future value in given periods.
142
+ * Uses Newton-Raphson when contributions are present; closed form for lump sum.
143
+ */
144
+ declare function rateToReachGoal(params: RateToReachGoalParams): number;
145
+
146
+ type RealReturnParams = {
147
+ nominalReturn: number;
148
+ inflationRate: number;
149
+ };
150
+ declare function realReturn(params: RealReturnParams): number;
151
+
152
+ type RuleOf72Params = {
153
+ rate: number;
154
+ /** Use 69 for continuous-ish approximation (e.g. daily compounding). Default 72. */
155
+ constant?: 72 | 69;
156
+ };
157
+ /**
158
+ * Approximate years to double a lump sum at the given annual rate.
159
+ * rate is decimal (e.g. 0.07 for 7%). Uses rule of 72 by default, or 69 if specified.
160
+ */
161
+ declare function ruleOf72(params: RuleOf72Params): number;
162
+
163
+ type AmortizationScheduleParams = {
164
+ principal: number;
165
+ annualRate: number;
166
+ paymentsPerYear: number;
167
+ years: number;
168
+ extraPaymentPerPeriod?: number;
169
+ };
170
+ type AmortizationRow = {
171
+ period: number;
172
+ payment: number;
173
+ principalPayment: number;
174
+ interestPayment: number;
175
+ balance: number;
176
+ };
177
+ type AmortizationScheduleResult = {
178
+ paymentPerPeriod: number;
179
+ schedule: AmortizationRow[];
180
+ totalPaid: number;
181
+ totalInterest: number;
182
+ };
183
+ declare function amortizationSchedule(params: AmortizationScheduleParams): AmortizationScheduleResult;
184
+
185
+ type LoanPaymentParams = {
186
+ principal: number;
187
+ annualRate: number;
188
+ paymentsPerYear: number;
189
+ years: number;
190
+ };
191
+ /**
192
+ * Fixed periodic payment for an amortizing loan.
193
+ *
194
+ * - `annualRate` is nominal annual rate (e.g. 0.06 for 6%)
195
+ * - payment returned is per period (`paymentsPerYear`)
196
+ */
197
+ declare function loanPayment(params: LoanPaymentParams): number;
198
+
199
+ type PayoffPeriodWithExtraParams = {
200
+ principal: number;
201
+ annualRate: number;
202
+ paymentsPerYear: number;
203
+ basePaymentPerPeriod: number;
204
+ extraPaymentPerPeriod: number;
205
+ };
206
+ /**
207
+ * Number of periods until the loan is paid off with the given base + extra payment.
208
+ */
209
+ declare function payoffPeriodWithExtra(params: PayoffPeriodWithExtraParams): number;
210
+
211
+ type RemainingBalanceParams = {
212
+ principal: number;
213
+ annualRate: number;
214
+ paymentsPerYear: number;
215
+ years: number;
216
+ afterPeriodNumber: number;
217
+ };
218
+ /**
219
+ * Remaining balance after a given number of payments on an amortizing loan.
220
+ */
221
+ declare function remainingBalance(params: RemainingBalanceParams): number;
222
+
223
+ type RoundToCurrencyParams = {
224
+ value: number;
225
+ /** Decimal places. Default 2. */
226
+ decimals?: number;
227
+ /** 'half-up': 0.5 rounds up. 'half-even': banker's rounding. Default 'half-up'. */
228
+ mode?: "half-up" | "half-even";
229
+ };
230
+ /**
231
+ * Rounds a number to currency (default 2 decimals). half-up: 2.125 -> 2.13. half-even: 2.125 -> 2.12.
232
+ */
233
+ declare function roundToCurrency(params: RoundToCurrencyParams): number;
234
+
235
+ export { type AmortizationRow, type AmortizationScheduleParams, type AmortizationScheduleResult, type CagrParams, type CompoundParams, type EffectiveAnnualRateParams, type FutureValueParams, type InflationAdjustedAmountParams, type InvestmentGrowthParams, type InvestmentGrowthResult, type IrrParams, type LoanPaymentParams, type PaymentFromPresentValueParams, type PayoffPeriodWithExtraParams, type PeriodsToReachGoalParams, type PresentValueOfAnnuityParams, type PresentValueParams, type RateToReachGoalParams, type RealReturnParams, type RemainingBalanceParams, type RoundToCurrencyParams, type RuleOf72Params, amortizationSchedule, cagr, compound, effectiveAnnualRate, futureValue, inflationAdjustedAmount, investmentGrowth, irr, loanPayment, paymentFromPresentValue, payoffPeriodWithExtra, periodsToReachGoal, presentValue, presentValueOfAnnuity, rateToReachGoal, realReturn, remainingBalance, roundToCurrency, ruleOf72 };