DECCF pension templates
This package provides generic, country-neutral building blocks for defined-contribution (DC) and defined-benefit (DB) pensions, plus a declarative profile model for agreement rules. The Swedish agreement catalog, dropdown input, pension case and payout scenarios are in Swedish pension agreements. Older direct calculation adapters are in Swedish DC and Swedish DB.
Import from ./domainpacks/pension/index.js or the package export. Register the returned component in the model's components. Loading deccfPack does not create a pension automatically.
import { definedContributionPension, definedBenefitPension } from "./domainpacks/pension/index.js";
const dc = definedContributionPension({
id: "work-pension", owner, currency: currencies.SEK, calculationScope: "contributions",
contributionPolicy: {
id: "country-neutral", version: "1", assessmentPeriod: "month", salary: pensionableSalary, eligible: 1,
bands: [{ id: "employer", contributionKey: "main", payer: "employer", lower: 0, upper: null, rate: 0.05 }],
},
});
const db = definedBenefitPension({
id: "career-pension", owner, currency: currencies.SEK, basis: { mode: "projected-retirement" },
benefitPolicy: { id: "career-final-pay", version: "1", annualSalaryBasis: finalSalary, serviceFactor,
bands: [{ lower: 0, upper: null, rate: 0.01 }] },
});Agreement-specific calculation profiles are defined with definePensionAgreementProfile(). The supported operations are declared DC contributions in salary bands and DB final-salary benefits with a service fraction. Base amounts, cohort tables, and age/employment conditions are supplied as data; the calculator does not contain agreement-specific names. Each profile declares its period, source and status (supported, partial or statement-only).
Generic capabilities
- DC calculations support marginal salary bands, multiple payers and contribution keys, fixed and optional premiums, matching, supplements, fees and employer cost. Calendar years and half-years can be calculated cumulatively using marginal deltas; starting partway through a period requires historical period data. Fixed amounts in a policy apply to its assessment period and are posted once in the first eligible active month, even if monthly salary is zero. When starting partway through such a period,
periodSeed.fixedAssessmentPaidstates whether the period's fixed amount has already been posted. Capital projections reuse DECCF's savings calculation instead of copying a capital engine. - DB calculations distinguish projected pension rights, career-average benefits and imported accrued rights. Benefit bands, service factor, offsets, protected amounts and payout start are separate inputs.
grossPensionremains zero until a payout window is explicitly opened. - Pure functions cover service fractions, merging qualifying service intervals, capital events, indexation, career-average benefits, term-limited payouts and annuity factors.
- Versioned assumption registries and monthly survival use explicit qx data, population, cohort, interpolation and tail rules. No Swedish insurer mortality table is assumed or bundled.
Each numeric policy source can be a number, declared numeric input or pure callback with declared preconditions. All amounts use the plan's currency. cashflows: "none" is reporting mode; "person" creates only the worker's own premium outflows and pension inflows. Results keep annual benefits and actual monthly payments as separate values.
Unknown options are rejected. Missing history, assumptions, eligibility or provenance produce an error instead of an assumed zero. Rounding, currency conversion, lifetime annuity quotes, death, survivor protection and Swedish tax calculations are not created automatically.
Funded pension accounts and ledger flows
fundedPension() is a monthly account component for a supplied capital amount and fixed payout. It reuses savingsPeriod and fixedTermPayment. The account holds the balance; no separate recursive calculation series stores it.
const { fundedPension } = modules.pension;
const pension = fundedPension({
owner: person,
currency: currencies.SEK,
openingCapital: statementCapital,
valuedAt: statementDate,
contribution: monthlyPremium,
annualReturn: stockGrowth,
payout: { from: firstPayoutMonth, months: payoutMonths, annualReturn: payoutReturn },
});
// Register pension.component in the model's components.accounts.capitalholds the pension capital.equityfunds opening capital and premiums,revaluationposts value changes, andbenefitsoffsets withdrawals. Every flow has balanced debit and credit rows.- Returns are calculated effectively each month on the opening capital. The premium is added at month-end. After payout begins, the explicitly supplied payout return applies; each payment is calculated using the remaining months and capped at available capital. Negative returns produce reversing entries.
valuedAtis optional. A statement dated after the projection starts is posted in its valuation month. Capital from an older statement must be restated to the model's start; the Swedish composition performs that restatement using its stated assumptions.outputs.paymentis the actual withdrawal,outputs.capitalis the account balance andoutputs.periodis the period assessment basis. The final payment empties the balance; later periods do not pay the same capital again.- Postings have
cashAccount: null: they describe the value of pension rights, not a second bank payment. Connectoutputs.paymentto the person's ordinary pension income flow, for example throughhouseholdPeople. - Inputs, expressions and declared calculations can be amount sources. The registered component recipe supports
repeat()and gives each pension right separate accounts.
Verification
Run from deccf:
node --experimental-test-isolation=none --test domainpacks/pension/test/*.test.js domainpacks/swedish-pension-dc/test/*.test.js domainpacks/swedish-pension-db/test/*.test.js
node domainpacks/pension/examples/basic.jsPublic types are in index.d.ts. Scope limits and further integration points are in HANDOFF.md.