RetirementCalculator provides various methods to calculate retirement finances, including inflation adjustments, balance after inflation, and compound interest calculations.

Hierarchy

  • default

Constructors

Methods

  • Private

    Validate that a numeric input is a finite real number. Rejects NaN, Infinity, -Infinity, and non-number types.

    Parameters

    • value: number
    • name: string

    Returns void

  • Private

    Validate that a numeric input is finite and non-negative (>= 0).

    Parameters

    • value: number
    • name: string

    Returns void

  • Private

    Validate that a numeric input is finite and strictly positive (> 0).

    Parameters

    • value: number
    • name: string

    Returns void

  • Private

    Validate that a frequency is a positive whole number of events per year.

    Parameters

    • value: number
    • name: string

    Returns void

  • Private

    Validate an annual return rate. A loss of 100% or more cannot be converted to a periodic compounding rate, so it is rejected.

    Parameters

    • value: number
    • name: string

    Returns void

  • Private

    Validate a nominal interest rate against its compounding frequency. The rate per compounding period must stay above -100%.

    Parameters

    • interestRate: number
    • compoundingFrequency: number

    Returns void

  • Private

    Validate an inflation rate. At -100% or below, deflating a balance divides by zero or a negative base.

    Parameters

    • inflationRate: number

    Returns void

  • Private

    Validate that a numeric input is finite and within [MIN_WEIGHT, MAX_WEIGHT]. Used for equity allocation weights (typically [0, 1]).

    Parameters

    • value: number
    • name: string

    Returns void

  • Private

    Validate a DynamicGlidepathConfig against GLIDEPATH_VALIDATION constraints. Mode-dispatched; throws a descriptive Error for any invariant violation.

    Parameters

    Returns void

  • Formats a number with commas and limits it to two decimal places.

    Parameters

    • value: number

      The number to be formatted.

    Returns string

    A string representation of the number with formatted commas.

  • Adjust how much a balance would be with inflation added.

    Parameters

    • desiredBalance: number
    • years: number
    • inflationRate: number

    Returns number

  • Private

    Calculate the value of something subtracting inflation over a period of time.

    Parameters

    • balance: number
    • inflationRate: number
    • years: number

    Returns number

  • Calculate how much would need to be in retirement in order to spend $yearlySpend a year

    Parameters

    • yearlySpend: number
    • yearlyWithdrawalRate: number = 0.04

    Returns number

  • Calculate how much could be spent in retirement based on an x% rule.

    Parameters

    • balance: number
    • yearlyWithdrawalRate: number

    Returns number

  • Private

    Calculate the total number of periods based on years and periods per year. May be fractional when the years do not end on a period boundary; values within rounding error of a whole number are snapped to it.

    Parameters

    • years: number
    • periodsPerYear: number

    Returns number

  • Private

    Calculate the interest rate per period based on the frequency of compounding.

    Parameters

    • interestRate: number
    • compoundingFrequency: number

    Returns number

  • Private

    Compute the time-weighted annual return from a sequence of periodic returns.

    Formula: TWR = (product of (1 + r_i))^(periodsPerYear / n) - 1

    TWR isolates investment performance from contribution timing and is the standard metric for comparing portfolio performance to a benchmark (e.g., the S&P 500 over the same window).

    Parameters

    • periodicReturnRates: number[]
    • periodsPerYear: number

    Returns number

  • Private

    Compute the money-weighted annual return (internal rate of return).

    Finds the single periodic rate i that grows every deposit to the final balance: sum(amount_k * (1 + i)^periodsInvested_k) = finalBalance. Unlike the time-weighted return, this weights each period's return by how much money was invested during it.

    The left-hand side increases with i, so the root is found by bisection.

    Parameters

    • deposits: {
          amount: number;
          periodsInvested: number;
      }[]
    • finalBalance: number
    • periodsPerYear: number

    Returns number

  • Private

    Count the contributions that fall due during a span of periods.

    Contribution k falls due k / contributionFrequency years in, so the number due by the end of period p is floor(p * contributionFrequency / periodsPerYear). Differencing the two ends of the span gives an exact schedule for any pair of whole-number frequencies: yearly contributions on a monthly grid land in every 12th period, and weekly contributions land 4 or 5 to a month, totalling 52 a year.

    Parameters

    • periodStart: number

      Periods elapsed at the start of the span

    • periodEnd: number

      Periods elapsed at the end of the span (may be fractional)

    • contributionFrequency: number
    • periodsPerYear: number

    Returns number

  • Determine the amount to contribute, at the given contribution frequency, to reach a desired balance. Feeding the result back into getCompoundInterestWithAdditionalContributions reproduces the target.

    Parameters

    • startingBalance: number
    • desiredBalance: number
    • years: number
    • interestRate: number
    • contributionFrequency: number
    • compoundingFrequency: number
    • inflationRate: number = 0.02

    Returns DetermineContributionType

  • Calculate compound interest with additional contributions made over a given period of time.

    Contributions are credited at the start of the compounding period in which they fall due, so each earns interest for that period.

    Parameters

    • initialBalance: number

      The initial balance.

    • additionalContributionAmount: number

      The amount of each contribution.

    • years: number

      The number of years. If this does not end on a compounding boundary, the remainder runs as a final partial period earning simple interest.

    • interestRate: number

      The nominal annual interest rate; each period earns interestRate / compoundingFrequency.

    • contributionFrequency: number

      Contributions per year (whole number).

    • compoundingFrequency: number

      Compounding periods per year (whole number).

    Returns CompoundingInterestObjectType

    An object that contains the results, and a history.

  • Calculate compound interest with age-aware glidepath strategies. Supports fixed returns, allocation-based strategies, and custom waypoints.

    Parameters

    • initialBalance: number

      Starting account balance

    • contributionAmount: number

      Amount contributed per contribution period

    • startAge: number

      Starting age for calculation

    • endAge: number

      Ending age for calculation

    • glidepathConfig: DynamicGlidepathConfig

      Strategy configuration (fixed, allocation-based, or custom)

    • contributionFrequency: number = 12

      Number of contributions per year (default: 12). Contributions are placed in the month in which they fall due.

    • compoundingFrequency: number = 12

      How many times a year earned interest is credited to the balance (default: 12). The simulation steps monthly and treats returns as effective annual rates, so values above 12 behave exactly like 12. Below 12, interest accrues monthly on the credited balance and is added to it at the end of each compounding period (or at the end of the simulation, if that comes first).

    • contributionTiming: ContributionTiming = 'start'

      When contributions are added ('start' or 'end' of the month)

    Returns DynamicGlidepathResult

    Detailed glidepath calculation results with timeline data

  • Private

    Calculate the annual return rate for a given age using the specified glidepath strategy.

    Parameters

    • age: number

      Current age for calculation

    • config: DynamicGlidepathConfig

      Glidepath configuration

    • startAge: number

      Starting age for age-based calculations

    • endAge: number

      Ending age for age-based calculations

    Returns number

    Annual return rate (decimal format)

  • Private

    Calculate linear interpolation progress between start and end ages.

    Parameters

    • age: number

      Current age

    • startAge: number

      Starting age

    • endAge: number

      Ending age

    Returns number

    Clamped progress value between 0 and 1

  • Private

    Calculate return for fixed-return glidepath (linear interpolation).

    Parameters

    • age: number

      Current age

    • config: FixedReturnGlidepathConfig

      Fixed return configuration

    • startAge: number

      Starting age for calculation

    • endAge: number

      Ending age for calculation

    Returns number

    Annual return rate

  • Private

    Calculate return for stepped-return glidepath (Money Guy style).

    Parameters

    Returns number

    Annual return rate

  • Private

    Calculate return for allocation-based glidepath.

    Parameters

    • age: number

      Current age

    • config: AllocationBasedGlidepathConfig

      Allocation-based configuration

    • startAge: number

      Starting age for calculation

    • endAge: number

      Ending age for calculation

    Returns number

    Annual return rate

  • Private

    Interpolate a value between waypoints for a given age.

    Parameters

    • age: number

      Current age

    • waypoints: {
          age: number;
          value: number;
      }[]

      Array of waypoints (already sorted)

    Returns number

    Interpolated value at the given age

  • Private

    Calculate blended return based on equity and bond allocation.

    Parameters

    • equityWeight: number

      Equity allocation weight (0.0 to 1.0)

    • equityReturn: number

      Expected annual equity return

    • bondReturn: number

      Expected annual bond return

    Returns number

    Blended annual return rate

  • Private

    Get the current equity weight for allocation-based and custom waypoints configurations. Used for timeline data enrichment.

    Parameters

    • age: number

      Current age

    • config: DynamicGlidepathConfig

      Glidepath configuration

    • startAge: number

      Starting age for age-based calculations

    • endAge: number

      Ending age for age-based calculations

    Returns undefined | number

    Equity weight (0.0 to 1.0) or undefined for non-allocation modes

  • Private

    Number of months in the compounding period that contains a given month.

    Credit j lands in month ceil(12 * j / creditsPerYear), so periods are all 12 / creditsPerYear months long when that divides evenly, and a mix of the two nearest whole lengths otherwise (e.g. 2 and 3 months for 5 a year).

    Parameters

    • month: number
    • creditsPerYear: number

    Returns number

  • Private

    Convert an effective annual rate to the equivalent rate per period. Formula: periodicRate = (1 + annualRate)^(1/periodsPerYear) - 1

    Parameters

    • annualRate: number

      Effective annual rate (decimal)

    • periodsPerYear: number

      Number of compounding periods per year

    Returns number

    Rate per period (decimal)

Generated using TypeDoc