@casomoltd/nhs-pay 0.11.0 → 0.12.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.
- package/README.md +48 -0
- package/dist/award.d.ts +8 -8
- package/dist/award.js +8 -8
- package/dist/circulars/england-md-1-2026r.d.ts +2 -3
- package/dist/circulars/england-md-1-2026r.js +2 -3
- package/dist/circulars/england-md-1-2026r.js.map +1 -1
- package/dist/circulars/ni-hsc-tc8-05-2025.d.ts +2 -2
- package/dist/circulars/ni-hsc-tc8-05-2025.js +2 -2
- package/dist/circulars/scotland-pcs-dd-2025-01.d.ts +2 -3
- package/dist/circulars/scotland-pcs-dd-2025-01.js +2 -3
- package/dist/circulars/scotland-pcs-dd-2025-01.js.map +1 -1
- package/dist/circulars/scotland-pcs-dd-2026-01.d.ts +2 -2
- package/dist/circulars/scotland-pcs-dd-2026-01.js +2 -2
- package/dist/circulars/wales-mdw-01-2025.d.ts +2 -2
- package/dist/circulars/wales-mdw-01-2025.js +2 -2
- package/dist/circulars/wales-mdw-01-2026.d.ts +2 -2
- package/dist/circulars/wales-mdw-01-2026.js +2 -2
- package/dist/gad/erf-2023-06-30.d.ts +39 -3
- package/dist/gad/erf-2023-06-30.js +39 -3
- package/dist/gad/erf-2023-06-30.js.map +1 -1
- package/dist/gad/factor-table.d.ts +10 -0
- package/dist/gad/factor-table.js.map +1 -1
- package/dist/gad/lrf-2023-06-30.d.ts +39 -3
- package/dist/gad/lrf-2023-06-30.js +39 -3
- package/dist/gad/lrf-2023-06-30.js.map +1 -1
- package/dist/hcas-pcts.js +3 -1
- package/dist/hcas-pcts.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/pension/history.d.ts +105 -0
- package/dist/pension/history.js +115 -0
- package/dist/pension/history.js.map +1 -0
- package/dist/pension/ledger.d.ts +146 -0
- package/dist/pension/ledger.js +193 -0
- package/dist/pension/ledger.js.map +1 -0
- package/dist/pension/prices.d.ts +125 -0
- package/dist/pension/prices.js +108 -0
- package/dist/pension/prices.js.map +1 -0
- package/dist/pension/seed.d.ts +75 -0
- package/dist/pension/seed.js +82 -0
- package/dist/pension/seed.js.map +1 -0
- package/dist/pension/uplift.d.ts +151 -0
- package/dist/pension/uplift.js +135 -0
- package/dist/pension/uplift.js.map +1 -0
- package/dist/pension-projection.d.ts +189 -46
- package/dist/pension-projection.js +365 -201
- package/dist/pension-projection.js.map +1 -1
- package/dist/pension.js +9 -10
- package/dist/pension.js.map +1 -1
- package/dist/post.d.ts +24 -16
- package/dist/post.js +2 -3
- package/dist/post.js.map +1 -1
- package/dist/revaluation.d.ts +119 -30
- package/dist/revaluation.js +175 -29
- package/dist/revaluation.js.map +1 -1
- package/dist/scales.d.ts +17 -10
- package/dist/scales.js +17 -10
- package/dist/scales.js.map +1 -1
- package/dist/take-home.d.ts +9 -5
- package/dist/take-home.js +9 -5
- package/dist/take-home.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The member's pension as a balance-forward periodic ledger.
|
|
3
|
+
*
|
|
4
|
+
* closing(N) = [closing(N−1) × (1 + uplift(N)) + earned(N)]
|
|
5
|
+
* × factor(N) − cash(N)
|
|
6
|
+
*
|
|
7
|
+
* One uniform row per scheme year. `factor` is 1 and `cash` is 0
|
|
8
|
+
* on every row but the retirement one, so there is no branch in
|
|
9
|
+
* the recurrence — only a multiplier that is usually the
|
|
10
|
+
* identity, the same trick as an uplift of zero.
|
|
11
|
+
*
|
|
12
|
+
* **The order is load-bearing.** The pot is revalued FIRST and
|
|
13
|
+
* the year's slice added after, so a slice earns no revaluation
|
|
14
|
+
* in the scheme year it is earned. The other order overstates a
|
|
15
|
+
* real statement by 3.2% while every internal test still passes.
|
|
16
|
+
*
|
|
17
|
+
* This is a READ MODEL, not a book of record: it is rebuilt from
|
|
18
|
+
* source on every call, never stored, and every row is frozen at
|
|
19
|
+
* construction.
|
|
20
|
+
*/
|
|
21
|
+
import { invariant } from '../errors.js';
|
|
22
|
+
import { periodInYearsMonths } from '../dates.js';
|
|
23
|
+
import { openingUpliftFor, phaseAt } from './uplift.js';
|
|
24
|
+
import { schemeYearEndDate, schemeYearEndFor, schemeYearStartDate, } from './seed.js';
|
|
25
|
+
/** Complete months from `from` to `to`, capped at a scheme year. */
|
|
26
|
+
function completeMonths(from, to) {
|
|
27
|
+
if (to <= from)
|
|
28
|
+
return 0;
|
|
29
|
+
const { years, months } = periodInYearsMonths(from, to);
|
|
30
|
+
return Math.min(12, years * 12 + months);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Nominal pay for a year, scaled where the year is partial.
|
|
34
|
+
* The 1/54 divisor is never pro-rated — only the pay is.
|
|
35
|
+
*
|
|
36
|
+
* **Only the JOINING year can be partial.** A member joining in
|
|
37
|
+
* October earns two thirds of that year's pay and their
|
|
38
|
+
* statement says so; there is one join and it is handled one
|
|
39
|
+
* way, so nothing is inconsistent about counting it.
|
|
40
|
+
*
|
|
41
|
+
* Leaving is different: an exit date names a SCHEME YEAR and
|
|
42
|
+
* the member is credited the whole of it, unearned months
|
|
43
|
+
* included. That is a simplification the library should not be
|
|
44
|
+
* making — see `rowFor` and issue #12.
|
|
45
|
+
*/
|
|
46
|
+
function payFor({ year, prices, first, accruingFrom, annualPay, }) {
|
|
47
|
+
// Today's money in, this year's cash out. One conversion, so
|
|
48
|
+
// the figure cannot pick up growth on the way. At a zero
|
|
49
|
+
// assumption it is the identity, which is what makes the
|
|
50
|
+
// today's-money run credit pay / 54 every year.
|
|
51
|
+
const whole = prices.payAt(annualPay, schemeYearEndDate(year));
|
|
52
|
+
let months = 12;
|
|
53
|
+
if (year === first && accruingFrom !== null) {
|
|
54
|
+
months = completeMonths(accruingFrom, schemeYearStartDate(year + 1));
|
|
55
|
+
}
|
|
56
|
+
return (whole * months) / 12;
|
|
57
|
+
}
|
|
58
|
+
/** One row: revalue the pot, add the year's slice, then apply
|
|
59
|
+
* the retirement transform if this is the year it falls in. */
|
|
60
|
+
function rowFor(ctx) {
|
|
61
|
+
const { year, opening, req, exitYear, retireYear } = ctx;
|
|
62
|
+
const { prices, seed } = req;
|
|
63
|
+
const phase = phaseAt(year, exitYear, retireYear);
|
|
64
|
+
/* ONE RULE FOR LEAVING: an exit date names a SCHEME YEAR.
|
|
65
|
+
The member is active for all of it, earns its whole 1/54
|
|
66
|
+
slice, and from its close the in-service rate stops. Both
|
|
67
|
+
halves are the same decision.
|
|
68
|
+
|
|
69
|
+
It is a simplification the LIBRARY makes on the consumer's
|
|
70
|
+
behalf, which is the wrong way round — SI 2015/94 Sch 9
|
|
71
|
+
para 3 is finer on both counts and no caller can reach it.
|
|
72
|
+
See docs/how-it-works.md, "An exit date names a scheme
|
|
73
|
+
year, not a day", for what it costs, and issue #12 for what
|
|
74
|
+
a fix takes. */
|
|
75
|
+
/* The rate is `openingUpliftFor`'s answer, never assembled
|
|
76
|
+
here: the seed inverts this exact step, and the two must ask
|
|
77
|
+
one function rather than each name the phase, the year and
|
|
78
|
+
the series for themselves. */
|
|
79
|
+
const uplift = ctx.isFirst
|
|
80
|
+
? null
|
|
81
|
+
: openingUpliftFor(year - 1, req.exitDate, req.retirementDate, prices);
|
|
82
|
+
const revalued = uplift === null
|
|
83
|
+
? opening
|
|
84
|
+
: opening * (1 + uplift.percent / 100);
|
|
85
|
+
const pensionableEarnings = phase === 'active'
|
|
86
|
+
? payFor({
|
|
87
|
+
year, prices, first: ctx.first,
|
|
88
|
+
accruingFrom: seed.accruingFrom,
|
|
89
|
+
annualPay: req.pensionableEarnings,
|
|
90
|
+
})
|
|
91
|
+
: null;
|
|
92
|
+
const earned = pensionableEarnings === null
|
|
93
|
+
? 0
|
|
94
|
+
: pensionableEarnings / 54;
|
|
95
|
+
const drawing = year === retireYear
|
|
96
|
+
? req.drawingFor(revalued + earned)
|
|
97
|
+
: null;
|
|
98
|
+
const factor = drawing?.factor ?? 1;
|
|
99
|
+
const givenUp = drawing?.commuted?.pensionGivenUp ?? 0;
|
|
100
|
+
// The one nonsense the shape still permits. An invariant
|
|
101
|
+
// rather than three row subtypes: nothing about a row's
|
|
102
|
+
// BEHAVIOUR differs by phase, so there is nothing to dispatch
|
|
103
|
+
// and subtypes would override nothing.
|
|
104
|
+
invariant(phase === 'active' || pensionableEarnings === null, `${phase} year ${year} carries pensionable earnings`);
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
schemeYearEnd: year,
|
|
107
|
+
phase,
|
|
108
|
+
pensionableEarnings,
|
|
109
|
+
earned,
|
|
110
|
+
earningsBasis: earned === 0 ? 'none' : 'assumed',
|
|
111
|
+
opening,
|
|
112
|
+
uplift: uplift === null ? null : Object.freeze(uplift),
|
|
113
|
+
revalued,
|
|
114
|
+
drawing: drawing === null ? null : Object.freeze(drawing),
|
|
115
|
+
closing: (revalued + earned) * factor - givenUp,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export function buildLedger(req) {
|
|
119
|
+
const { seed, exitDate, retirementDate, through } = req;
|
|
120
|
+
const exitYear = schemeYearEndFor(exitDate);
|
|
121
|
+
const retireYear = schemeYearEndFor(retirementDate);
|
|
122
|
+
const first = seed.atSchemeYearEnd + 1;
|
|
123
|
+
const years = [];
|
|
124
|
+
let opening = seed.opening;
|
|
125
|
+
for (let year = first; year <= through; year++) {
|
|
126
|
+
const row = rowFor({
|
|
127
|
+
year,
|
|
128
|
+
opening,
|
|
129
|
+
isFirst: years.length === 0 && seed.basis === 'derived',
|
|
130
|
+
req, first, exitYear, retireYear,
|
|
131
|
+
});
|
|
132
|
+
years.push(row);
|
|
133
|
+
opening = row.closing;
|
|
134
|
+
}
|
|
135
|
+
return readerOver(Object.freeze(years), seed);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The read side, over rows already walked.
|
|
139
|
+
*
|
|
140
|
+
* Separated from the walk because they are different jobs: one
|
|
141
|
+
* produces the record, the other answers questions of it. Also
|
|
142
|
+
* keeps each honest about its own complexity.
|
|
143
|
+
*/
|
|
144
|
+
function readerOver(frozen, seed) {
|
|
145
|
+
/** The earliest date this ledger can answer for: the close of
|
|
146
|
+
* the year its seed sits at. */
|
|
147
|
+
const startsAt = schemeYearEndDate(seed.atSchemeYearEnd);
|
|
148
|
+
/**
|
|
149
|
+
* Asked about a date BEFORE the ledger begins, answer at the
|
|
150
|
+
* beginning instead — the balance is the seed's, and the seed
|
|
151
|
+
* is a figure at a stated date.
|
|
152
|
+
*
|
|
153
|
+
* Returning the seed against the DATE ASKED made leaving
|
|
154
|
+
* earlier look worth more: the cash figure was unchanged but
|
|
155
|
+
* deflated over a longer window, so a member who left in
|
|
156
|
+
* January 2024 read £3,849 in today's money where one who
|
|
157
|
+
* left in January 2025 read £3,607, off the same statement.
|
|
158
|
+
* Monotonic nonsense, and in the one regime where it shows —
|
|
159
|
+
* a statement issued after the member had already left.
|
|
160
|
+
*/
|
|
161
|
+
const answerableAt = (date) => date < startsAt ? startsAt : date;
|
|
162
|
+
/** Replay the steps up to `date`. `preDrawing` reads the row
|
|
163
|
+
* carrying the retirement event at its pre-factor value. */
|
|
164
|
+
const walkTo = (date, preDrawing) => {
|
|
165
|
+
let value = seed.opening;
|
|
166
|
+
for (const row of frozen) {
|
|
167
|
+
if (row.uplift !== null && row.uplift.appliedOn <= date) {
|
|
168
|
+
value = row.revalued;
|
|
169
|
+
}
|
|
170
|
+
if (schemeYearEndDate(row.schemeYearEnd) <= date) {
|
|
171
|
+
value = preDrawing
|
|
172
|
+
? row.revalued + row.earned
|
|
173
|
+
: row.closing;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return value;
|
|
177
|
+
};
|
|
178
|
+
return Object.freeze({
|
|
179
|
+
years: frozen,
|
|
180
|
+
atDate: (date) => walkTo(answerableAt(date), false),
|
|
181
|
+
accruedAt: (date) => walkTo(answerableAt(date), true),
|
|
182
|
+
closingAt(schemeYearEnd) {
|
|
183
|
+
if (schemeYearEnd <= seed.atSchemeYearEnd) {
|
|
184
|
+
return seed.opening;
|
|
185
|
+
}
|
|
186
|
+
const row = frozen.find((r) => r.schemeYearEnd === schemeYearEnd);
|
|
187
|
+
invariant(row !== undefined, `scheme year ${schemeYearEnd} is beyond the walk`);
|
|
188
|
+
return row.closing;
|
|
189
|
+
},
|
|
190
|
+
earningsRows: () => frozen.filter((row) => row.pensionableEarnings !== null),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/pension/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAC;AAIhD,OAAO,EAAC,gBAAgB,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAEtD,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AA+HnB,oEAAoE;AACpE,SAAS,cAAc,CAAC,IAAU,EAAE,EAAQ;IAC1C,IAAI,EAAE,IAAI,IAAI;QAAE,OAAO,CAAC,CAAC;IACzB,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACtD,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,MAAM,CAAC,EACd,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,GAO7C;IACC,6DAA6D;IAC7D,yDAAyD;IACzD,yDAAyD;IACzD,gDAAgD;IAChD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,i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,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The caller's CPI assumption, and the one conversion that
|
|
3
|
+
* needs it.
|
|
4
|
+
*
|
|
5
|
+
* Two jobs. The assumption itself, read as a `CpiEntry` for any
|
|
6
|
+
* scheme year, and expressing the caller's pay in the money of
|
|
7
|
+
* a given scheme year, which is that same rate applied.
|
|
8
|
+
*
|
|
9
|
+
* ── There is no deflator here any more ──────────────
|
|
10
|
+
*
|
|
11
|
+
* Today's money is NOT this projection divided by inflation. It
|
|
12
|
+
* is the SAME projection run with the inflation assumption set
|
|
13
|
+
* to zero, so the pension revalues at 1.5% a year while a
|
|
14
|
+
* member is paying in and not at all once they are deferred.
|
|
15
|
+
* `pension-projection.ts` runs the model twice and pairs the
|
|
16
|
+
* two readings; neither one is derived from the other.
|
|
17
|
+
*
|
|
18
|
+
* That is a real difference, not a restatement of the same
|
|
19
|
+
* arithmetic. Dividing a CPI + 1.5 projection by CPI gives
|
|
20
|
+
* 1.5 / (1 + cpi) — 1.47% at a 2% assumption, because the 1.5
|
|
21
|
+
* points are added before the growth and then eaten into by
|
|
22
|
+
* the same year's inflation. Running at zero gives 1.5% flat.
|
|
23
|
+
* The second is what the scheme's own rule reduces to when
|
|
24
|
+
* inflation is ignored, and it is what the tool means by
|
|
25
|
+
* today's money.
|
|
26
|
+
*
|
|
27
|
+
* Deleting the deflator deleted a great deal with it: an anchor
|
|
28
|
+
* date, a face-value window, and the rule that a stated balance
|
|
29
|
+
* must not be restated. At a zero assumption there is nothing
|
|
30
|
+
* to restate, so that property now holds by construction rather
|
|
31
|
+
* than by a clamp — which is why three separate attempts at
|
|
32
|
+
* placing the anchor all failed and this does not.
|
|
33
|
+
*
|
|
34
|
+
* An uplift rule reads whatever entry it is handed and carries
|
|
35
|
+
* it through to its receipt; it never branches on whether the
|
|
36
|
+
* figure was measured or assumed. A PROJECTION is always handed
|
|
37
|
+
* `assumedFor`: an Order is a nominal rate, and the
|
|
38
|
+
* today's-money run is this same model at an assumption of
|
|
39
|
+
* zero, so an Order applied inside it puts a whole year of CPI
|
|
40
|
+
* into a reading defined to contain none. So there is one rate
|
|
41
|
+
* here and it is the assumption.
|
|
42
|
+
*
|
|
43
|
+
* Reading the published record itself is a different question,
|
|
44
|
+
* and `revaluation.ts` answers it: `revaluationFor` for one
|
|
45
|
+
* year, `publishedInflationBetween` for a window, both beside
|
|
46
|
+
* the table they read.
|
|
47
|
+
*/
|
|
48
|
+
/** One year of the September CPI series, and where it came from. */
|
|
49
|
+
export interface CpiEntry {
|
|
50
|
+
/** Scheme year END, e.g. 2016 for the 2015/16 year. */
|
|
51
|
+
readonly schemeYearEnd: number;
|
|
52
|
+
/** Percentage points. Negative is legal: September 2015 was
|
|
53
|
+
* -0.1, which is the scheme's very first uplift. */
|
|
54
|
+
readonly cpi: number;
|
|
55
|
+
/** The Order that published this figure; null when it is the
|
|
56
|
+
* caller's assumption. Never an empty string.
|
|
57
|
+
*
|
|
58
|
+
* This one nullable field IS the published-versus-assumed
|
|
59
|
+
* distinction — not a variant of uplift, not a flag on a ledger
|
|
60
|
+
* row. A year either has the Order that set it or it does not,
|
|
61
|
+
* which leaves pro-rating free to vary independently of it. */
|
|
62
|
+
readonly si: string | null;
|
|
63
|
+
}
|
|
64
|
+
/** Where one year's CPI figure is read from. The uplift rule is
|
|
65
|
+
* a function of phase and a series, so `upliftsFor` takes the
|
|
66
|
+
* CHOICE rather than a table and a condition — WHICH series
|
|
67
|
+
* stays the caller's question and never the rule's. A projection
|
|
68
|
+
* makes that choice exactly once, in `openingUpliftFor`. */
|
|
69
|
+
export type CpiSource = (schemeYearEnd: number) => CpiEntry;
|
|
70
|
+
/** The rate a projection revalues at, and the money readings
|
|
71
|
+
* that follow from it. Two members and no third: reading the
|
|
72
|
+
* published record is `revaluation.ts`'s job, and a reader here
|
|
73
|
+
* would be a second answer to a question already answered. */
|
|
74
|
+
export interface Prices {
|
|
75
|
+
/**
|
|
76
|
+
* A scheme year read as the caller's ASSUMPTION, whatever the
|
|
77
|
+
* published table holds for it.
|
|
78
|
+
*
|
|
79
|
+
* Not a fallback and not a test seam. This is the ONLY rate a
|
|
80
|
+
* projection uses, for every uplift after its seed and for
|
|
81
|
+
* published years as readily as unpublished ones — see the
|
|
82
|
+
* header, and `openingUpliftFor`, which is where a projection
|
|
83
|
+
* reaches for it.
|
|
84
|
+
*/
|
|
85
|
+
assumedFor(schemeYearEnd: number): CpiEntry;
|
|
86
|
+
/**
|
|
87
|
+
* The caller's pay, given in today's money, expressed in the
|
|
88
|
+
* cash of `asAt`.
|
|
89
|
+
*
|
|
90
|
+
* The only conversion left in this module. At a zero
|
|
91
|
+
* assumption it is the identity, which is exactly why the
|
|
92
|
+
* today's-money run credits `pay / 54` every year without
|
|
93
|
+
* anything having to enforce it.
|
|
94
|
+
*/
|
|
95
|
+
payAt(todaysMoney: number, asAt: Date): number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* How much more a pound of `asAt` money is than a pound of
|
|
99
|
+
* `from` money, under the caller's assumption.
|
|
100
|
+
*
|
|
101
|
+
* **Annual STEPS, never a continuous power.** Pay is a slice of
|
|
102
|
+
* a scheme year and the pot moves once a year, so a ruler that
|
|
103
|
+
* compounded smoothly would drift against both inside every
|
|
104
|
+
* year. The steps are the days the Orders actually land, read
|
|
105
|
+
* from the table: 1 April through 2022, 6 April after. Reading
|
|
106
|
+
* them off a hardcoded 6 April put a five-day window either
|
|
107
|
+
* side of every pre-2023 April and counted a step that had not
|
|
108
|
+
* happened.
|
|
109
|
+
*
|
|
110
|
+
* Symmetric, so a year behind the run date is divided by
|
|
111
|
+
* exactly what a year ahead is multiplied by, and a caller
|
|
112
|
+
* converting out and back lands where it started.
|
|
113
|
+
*/
|
|
114
|
+
export declare function inflationFactor(asAt: Date, from: Date, assumedCpi: number): number;
|
|
115
|
+
/**
|
|
116
|
+
* Build the price series for one run.
|
|
117
|
+
*
|
|
118
|
+
* @param assumedCpi Decimal, e.g. 0.02 — the caller's single
|
|
119
|
+
* assumption, and the rate behind every uplift a projection
|
|
120
|
+
* applies.
|
|
121
|
+
* @param asOf The date the caller's pay is quoted at — the run
|
|
122
|
+
* date. Pay is the only thing converted, so this is the only
|
|
123
|
+
* date the module needs.
|
|
124
|
+
*/
|
|
125
|
+
export declare function createPrices(assumedCpi: number, asOf: Date): Prices;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The caller's CPI assumption, and the one conversion that
|
|
3
|
+
* needs it.
|
|
4
|
+
*
|
|
5
|
+
* Two jobs. The assumption itself, read as a `CpiEntry` for any
|
|
6
|
+
* scheme year, and expressing the caller's pay in the money of
|
|
7
|
+
* a given scheme year, which is that same rate applied.
|
|
8
|
+
*
|
|
9
|
+
* ── There is no deflator here any more ──────────────
|
|
10
|
+
*
|
|
11
|
+
* Today's money is NOT this projection divided by inflation. It
|
|
12
|
+
* is the SAME projection run with the inflation assumption set
|
|
13
|
+
* to zero, so the pension revalues at 1.5% a year while a
|
|
14
|
+
* member is paying in and not at all once they are deferred.
|
|
15
|
+
* `pension-projection.ts` runs the model twice and pairs the
|
|
16
|
+
* two readings; neither one is derived from the other.
|
|
17
|
+
*
|
|
18
|
+
* That is a real difference, not a restatement of the same
|
|
19
|
+
* arithmetic. Dividing a CPI + 1.5 projection by CPI gives
|
|
20
|
+
* 1.5 / (1 + cpi) — 1.47% at a 2% assumption, because the 1.5
|
|
21
|
+
* points are added before the growth and then eaten into by
|
|
22
|
+
* the same year's inflation. Running at zero gives 1.5% flat.
|
|
23
|
+
* The second is what the scheme's own rule reduces to when
|
|
24
|
+
* inflation is ignored, and it is what the tool means by
|
|
25
|
+
* today's money.
|
|
26
|
+
*
|
|
27
|
+
* Deleting the deflator deleted a great deal with it: an anchor
|
|
28
|
+
* date, a face-value window, and the rule that a stated balance
|
|
29
|
+
* must not be restated. At a zero assumption there is nothing
|
|
30
|
+
* to restate, so that property now holds by construction rather
|
|
31
|
+
* than by a clamp — which is why three separate attempts at
|
|
32
|
+
* placing the anchor all failed and this does not.
|
|
33
|
+
*
|
|
34
|
+
* An uplift rule reads whatever entry it is handed and carries
|
|
35
|
+
* it through to its receipt; it never branches on whether the
|
|
36
|
+
* figure was measured or assumed. A PROJECTION is always handed
|
|
37
|
+
* `assumedFor`: an Order is a nominal rate, and the
|
|
38
|
+
* today's-money run is this same model at an assumption of
|
|
39
|
+
* zero, so an Order applied inside it puts a whole year of CPI
|
|
40
|
+
* into a reading defined to contain none. So there is one rate
|
|
41
|
+
* here and it is the assumption.
|
|
42
|
+
*
|
|
43
|
+
* Reading the published record itself is a different question,
|
|
44
|
+
* and `revaluation.ts` answers it: `revaluationFor` for one
|
|
45
|
+
* year, `publishedInflationBetween` for a window, both beside
|
|
46
|
+
* the table they read.
|
|
47
|
+
*/
|
|
48
|
+
import { appliedOnFor } from '../revaluation.js';
|
|
49
|
+
/**
|
|
50
|
+
* How much more a pound of `asAt` money is than a pound of
|
|
51
|
+
* `from` money, under the caller's assumption.
|
|
52
|
+
*
|
|
53
|
+
* **Annual STEPS, never a continuous power.** Pay is a slice of
|
|
54
|
+
* a scheme year and the pot moves once a year, so a ruler that
|
|
55
|
+
* compounded smoothly would drift against both inside every
|
|
56
|
+
* year. The steps are the days the Orders actually land, read
|
|
57
|
+
* from the table: 1 April through 2022, 6 April after. Reading
|
|
58
|
+
* them off a hardcoded 6 April put a five-day window either
|
|
59
|
+
* side of every pre-2023 April and counted a step that had not
|
|
60
|
+
* happened.
|
|
61
|
+
*
|
|
62
|
+
* Symmetric, so a year behind the run date is divided by
|
|
63
|
+
* exactly what a year ahead is multiplied by, and a caller
|
|
64
|
+
* converting out and back lands where it started.
|
|
65
|
+
*/
|
|
66
|
+
export function inflationFactor(asAt, from, assumedCpi) {
|
|
67
|
+
const ahead = asAt >= from;
|
|
68
|
+
const steps = ahead
|
|
69
|
+
? aprilsBetween(from, asAt)
|
|
70
|
+
: aprilsBetween(asAt, from);
|
|
71
|
+
return Math.pow(1 + assumedCpi, ahead ? steps : -steps);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* How many uplift dates fall in `(from, to]` — the days the pot
|
|
75
|
+
* moves, read from the table so that a pre-2023 Order counts on
|
|
76
|
+
* 1 April and a later one on the 6th. Whole steps, never a
|
|
77
|
+
* fraction: the pension does not move on any other day, so
|
|
78
|
+
* neither does the ruler used to read it.
|
|
79
|
+
*/
|
|
80
|
+
function aprilsBetween(from, to) {
|
|
81
|
+
let count = 0;
|
|
82
|
+
for (let year = from.getFullYear(); year <= to.getFullYear(); year++) {
|
|
83
|
+
const applied = appliedOnFor(year);
|
|
84
|
+
if (applied > from && applied <= to)
|
|
85
|
+
count += 1;
|
|
86
|
+
}
|
|
87
|
+
return count;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Build the price series for one run.
|
|
91
|
+
*
|
|
92
|
+
* @param assumedCpi Decimal, e.g. 0.02 — the caller's single
|
|
93
|
+
* assumption, and the rate behind every uplift a projection
|
|
94
|
+
* applies.
|
|
95
|
+
* @param asOf The date the caller's pay is quoted at — the run
|
|
96
|
+
* date. Pay is the only thing converted, so this is the only
|
|
97
|
+
* date the module needs.
|
|
98
|
+
*/
|
|
99
|
+
export function createPrices(assumedCpi, asOf) {
|
|
100
|
+
const assumedPct = assumedCpi * 100;
|
|
101
|
+
return {
|
|
102
|
+
assumedFor: (schemeYearEnd) => ({
|
|
103
|
+
schemeYearEnd, cpi: assumedPct, si: null,
|
|
104
|
+
}),
|
|
105
|
+
payAt: (todaysMoney, asAt) => todaysMoney * inflationFactor(asAt, asOf, assumedCpi),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=prices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prices.js","sourceRoot":"","sources":["../../src/pension/prices.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,EAAC,YAAY,EA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AAC;KACxD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the walk starts, and what it starts from.
|
|
3
|
+
*
|
|
4
|
+
* This is the ENTIRETY of the statement-versus-estimation
|
|
5
|
+
* difference: the two input variants are read exactly once, here,
|
|
6
|
+
* to fill this object, and nothing downstream may ask which
|
|
7
|
+
* produced it.
|
|
8
|
+
*/
|
|
9
|
+
/** An initial condition, not an abstraction. */
|
|
10
|
+
export interface LedgerSeed {
|
|
11
|
+
/** Nominal £/yr already banked at the close of
|
|
12
|
+
* `atSchemeYearEnd`. Zero when there is nothing to start
|
|
13
|
+
* from. */
|
|
14
|
+
readonly opening: number;
|
|
15
|
+
/** The scheme year the opening balance sits AT. The walk
|
|
16
|
+
* starts at the year after this one. */
|
|
17
|
+
readonly atSchemeYearEnd: number;
|
|
18
|
+
/** The date service actually begins INSIDE the first walked
|
|
19
|
+
* year, when that year is a part year — null when it is whole.
|
|
20
|
+
* Only the join route can produce a value here: a statement
|
|
21
|
+
* lands on a scheme year end, so the year after it is always
|
|
22
|
+
* whole. The first year's PAY is scaled by this; the 1/54
|
|
23
|
+
* divisor never is. */
|
|
24
|
+
readonly accruingFrom: Date | null;
|
|
25
|
+
/** Whether `opening` is the scheme's own figure or ours. No
|
|
26
|
+
* arithmetic reads this — it exists so a consumer can tell a
|
|
27
|
+
* figure a member could check against paper from one this
|
|
28
|
+
* library produced. */
|
|
29
|
+
readonly basis: 'given' | 'derived';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The scheme year a date falls in, named by the year it ENDS.
|
|
33
|
+
*
|
|
34
|
+
* The cycle is the scheme's own — 1 April to 31 March — and it
|
|
35
|
+
* is the same one an Annual Benefit Statement closes on: a
|
|
36
|
+
* statement marked *Updated To 31/03/2025* reports scheme year
|
|
37
|
+
* 2025, so its figure seeds that row's close untouched. 1 Apr
|
|
38
|
+
* 2025 and 31 Mar 2026 are both scheme year 2026.
|
|
39
|
+
*/
|
|
40
|
+
export declare function schemeYearEndFor(date: Date): number;
|
|
41
|
+
/** 31 March of the given scheme year. */
|
|
42
|
+
export declare function schemeYearEndDate(schemeYearEnd: number): Date;
|
|
43
|
+
/** 1 April opening the given scheme year. */
|
|
44
|
+
export declare function schemeYearStartDate(schemeYearEnd: number): Date;
|
|
45
|
+
/**
|
|
46
|
+
* The scheme year that had already CLOSED by `date` — the year
|
|
47
|
+
* a balance stated on that date belongs to.
|
|
48
|
+
*
|
|
49
|
+
* Taking the day after makes 31 March land on the year it ends
|
|
50
|
+
* rather than the one before it. Shared with the caller that
|
|
51
|
+
* picks the real-terms anchor, which has to know the seed's year
|
|
52
|
+
* BEFORE a `Prices` exists to build the seed with.
|
|
53
|
+
*/
|
|
54
|
+
export declare function schemeYearClosedBy(date: Date): number;
|
|
55
|
+
/**
|
|
56
|
+
* Route 1: the scheme has already told us the balance.
|
|
57
|
+
*
|
|
58
|
+
* Precondition: `statementDate` IS a scheme year end (31 March).
|
|
59
|
+
* A mid-year statement date is a caller error, not a value to
|
|
60
|
+
* round — the accrued figure would not correspond to any closing
|
|
61
|
+
* balance. Throw; never silently snap to a year end.
|
|
62
|
+
*
|
|
63
|
+
* Yields basis 'given', and `accruingFrom` null: the first walked
|
|
64
|
+
* year is the one AFTER the statement's, which is always whole.
|
|
65
|
+
*/
|
|
66
|
+
export declare function seedFromStatement(accruedPension: number, statementDate: Date): LedgerSeed;
|
|
67
|
+
/**
|
|
68
|
+
* Route 2: we compute the balance from the beginning.
|
|
69
|
+
*
|
|
70
|
+
* Opening is zero and the walk starts in the join date's own
|
|
71
|
+
* scheme year, which is a PART year whenever the member did not
|
|
72
|
+
* join on 1 April — hence `accruingFrom`, which scales that
|
|
73
|
+
* year's pay.
|
|
74
|
+
*/
|
|
75
|
+
export declare function seedFromJoinDate(joinDate: Date): LedgerSeed;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the walk starts, and what it starts from.
|
|
3
|
+
*
|
|
4
|
+
* This is the ENTIRETY of the statement-versus-estimation
|
|
5
|
+
* difference: the two input variants are read exactly once, here,
|
|
6
|
+
* to fill this object, and nothing downstream may ask which
|
|
7
|
+
* produced it.
|
|
8
|
+
*/
|
|
9
|
+
import { invariant } from '../errors.js';
|
|
10
|
+
/**
|
|
11
|
+
* The scheme year a date falls in, named by the year it ENDS.
|
|
12
|
+
*
|
|
13
|
+
* The cycle is the scheme's own — 1 April to 31 March — and it
|
|
14
|
+
* is the same one an Annual Benefit Statement closes on: a
|
|
15
|
+
* statement marked *Updated To 31/03/2025* reports scheme year
|
|
16
|
+
* 2025, so its figure seeds that row's close untouched. 1 Apr
|
|
17
|
+
* 2025 and 31 Mar 2026 are both scheme year 2026.
|
|
18
|
+
*/
|
|
19
|
+
export function schemeYearEndFor(date) {
|
|
20
|
+
return date.getMonth() >= 3
|
|
21
|
+
? date.getFullYear() + 1
|
|
22
|
+
: date.getFullYear();
|
|
23
|
+
}
|
|
24
|
+
/** 31 March of the given scheme year. */
|
|
25
|
+
export function schemeYearEndDate(schemeYearEnd) {
|
|
26
|
+
return new Date(schemeYearEnd, 2, 31);
|
|
27
|
+
}
|
|
28
|
+
/** 1 April opening the given scheme year. */
|
|
29
|
+
export function schemeYearStartDate(schemeYearEnd) {
|
|
30
|
+
return new Date(schemeYearEnd - 1, 3, 1);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The scheme year that had already CLOSED by `date` — the year
|
|
34
|
+
* a balance stated on that date belongs to.
|
|
35
|
+
*
|
|
36
|
+
* Taking the day after makes 31 March land on the year it ends
|
|
37
|
+
* rather than the one before it. Shared with the caller that
|
|
38
|
+
* picks the real-terms anchor, which has to know the seed's year
|
|
39
|
+
* BEFORE a `Prices` exists to build the seed with.
|
|
40
|
+
*/
|
|
41
|
+
export function schemeYearClosedBy(date) {
|
|
42
|
+
const dayAfter = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1);
|
|
43
|
+
return schemeYearEndFor(dayAfter) - 1;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Route 1: the scheme has already told us the balance.
|
|
47
|
+
*
|
|
48
|
+
* Precondition: `statementDate` IS a scheme year end (31 March).
|
|
49
|
+
* A mid-year statement date is a caller error, not a value to
|
|
50
|
+
* round — the accrued figure would not correspond to any closing
|
|
51
|
+
* balance. Throw; never silently snap to a year end.
|
|
52
|
+
*
|
|
53
|
+
* Yields basis 'given', and `accruingFrom` null: the first walked
|
|
54
|
+
* year is the one AFTER the statement's, which is always whole.
|
|
55
|
+
*/
|
|
56
|
+
export function seedFromStatement(accruedPension, statementDate) {
|
|
57
|
+
invariant(statementDate.getMonth() === 2 && statementDate.getDate() === 31, 'statementDate must be a scheme year end (31 March), got '
|
|
58
|
+
+ statementDate.toDateString());
|
|
59
|
+
return {
|
|
60
|
+
opening: accruedPension,
|
|
61
|
+
atSchemeYearEnd: statementDate.getFullYear(),
|
|
62
|
+
accruingFrom: null,
|
|
63
|
+
basis: 'given',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Route 2: we compute the balance from the beginning.
|
|
68
|
+
*
|
|
69
|
+
* Opening is zero and the walk starts in the join date's own
|
|
70
|
+
* scheme year, which is a PART year whenever the member did not
|
|
71
|
+
* join on 1 April — hence `accruingFrom`, which scales that
|
|
72
|
+
* year's pay.
|
|
73
|
+
*/
|
|
74
|
+
export function seedFromJoinDate(joinDate) {
|
|
75
|
+
return {
|
|
76
|
+
opening: 0,
|
|
77
|
+
atSchemeYearEnd: schemeYearEndFor(joinDate) - 1,
|
|
78
|
+
accruingFrom: joinDate,
|
|
79
|
+
basis: 'derived',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=seed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../../src/pension/seed.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH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