@casomoltd/nhs-pay 0.30.0 → 0.31.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 +69 -251
- package/dist/bands.d.ts +9 -1
- package/dist/bands.js +20 -0
- package/dist/bands.js.map +1 -1
- package/dist/document-source.d.ts +16 -0
- package/dist/document-source.js +3 -1
- package/dist/document-source.js.map +1 -1
- package/dist/errors.d.ts +46 -11
- package/dist/errors.js +68 -28
- package/dist/errors.js.map +1 -1
- package/dist/factor-basis.d.ts +14 -0
- package/dist/factor-basis.js.map +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/member/benefits.js +18 -11
- package/dist/member/benefits.js.map +1 -1
- package/dist/member/index.d.ts +1 -1
- package/dist/member/input-period.d.ts +4 -4
- package/dist/member/input-period.js +11 -9
- package/dist/member/input-period.js.map +1 -1
- package/dist/member/service.d.ts +4 -0
- package/dist/member/service.js +9 -3
- package/dist/member/service.js.map +1 -1
- package/dist/member/types.d.ts +81 -49
- package/dist/member/types.js.map +1 -1
- package/dist/member/valuation.d.ts +10 -8
- package/dist/member/valuation.js +17 -21
- package/dist/member/valuation.js.map +1 -1
- package/dist/pay-path.d.ts +21 -25
- package/dist/pay-path.js +85 -67
- package/dist/pay-path.js.map +1 -1
- package/dist/pension/ages.d.ts +6 -4
- package/dist/pension/ages.js +6 -4
- package/dist/pension/ages.js.map +1 -1
- package/dist/pension/curve.d.ts +2 -1
- package/dist/pension/curve.js +15 -7
- package/dist/pension/curve.js.map +1 -1
- package/dist/pension/history.d.ts +18 -3
- package/dist/pension/history.js +12 -5
- package/dist/pension/history.js.map +1 -1
- package/dist/pension/ledger.d.ts +15 -9
- package/dist/pension/ledger.js +91 -56
- package/dist/pension/ledger.js.map +1 -1
- package/dist/pension/prices.d.ts +11 -2
- package/dist/pension/prices.js +35 -14
- package/dist/pension/prices.js.map +1 -1
- package/dist/pension/scheme-year.d.ts +59 -0
- package/dist/pension/scheme-year.js +80 -0
- package/dist/pension/scheme-year.js.map +1 -0
- package/dist/pension/seed.d.ts +66 -50
- package/dist/pension/seed.js +111 -65
- package/dist/pension/seed.js.map +1 -1
- package/dist/pension/uplift.d.ts +13 -33
- package/dist/pension/uplift.js +11 -56
- package/dist/pension/uplift.js.map +1 -1
- package/dist/pension-projection.js +30 -22
- package/dist/pension-projection.js.map +1 -1
- package/dist/post.d.ts +1 -10
- package/dist/post.js +1 -12
- package/dist/post.js.map +1 -1
- package/dist/revaluation.d.ts +34 -35
- package/dist/revaluation.js +41 -41
- package/dist/revaluation.js.map +1 -1
- package/dist/scale-point.d.ts +6 -0
- package/dist/sections/final-salary.d.ts +3 -8
- package/dist/sections/final-salary.js +13 -9
- package/dist/sections/final-salary.js.map +1 -1
- package/dist/sections/section-2015.d.ts +2 -1
- package/dist/sections/section-2015.js.map +1 -1
- package/dist/sources.d.ts +10 -0
- package/dist/sources.js +20 -0
- package/dist/sources.js.map +1 -1
- package/dist/take-home.d.ts +4 -20
- package/dist/take-home.js +3 -23
- package/dist/take-home.js.map +1 -1
- package/package.json +3 -3
package/dist/pension/seed.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
*/
|
|
1
|
+
import type { Prices } from './prices.js';
|
|
2
|
+
import type { SchemeYearEnd } from './scheme-year.js';
|
|
9
3
|
/** An initial condition, not an abstraction. */
|
|
10
4
|
export interface LedgerSeed {
|
|
11
5
|
/** Nominal £/yr already banked at the close of
|
|
@@ -14,7 +8,7 @@ export interface LedgerSeed {
|
|
|
14
8
|
readonly opening: number;
|
|
15
9
|
/** The scheme year the opening balance sits AT. The walk
|
|
16
10
|
* starts at the year after this one. */
|
|
17
|
-
readonly atSchemeYearEnd:
|
|
11
|
+
readonly atSchemeYearEnd: SchemeYearEnd;
|
|
18
12
|
/** The date service actually begins INSIDE the first walked
|
|
19
13
|
* year, when that year is a part year — null when it is whole.
|
|
20
14
|
* Only the join route can produce a value here: a statement
|
|
@@ -22,59 +16,65 @@ export interface LedgerSeed {
|
|
|
22
16
|
* whole. The first year's PAY is scaled by this; the 1/54
|
|
23
17
|
* divisor never is. */
|
|
24
18
|
readonly accruingFrom: Date | null;
|
|
19
|
+
/** Whether the walk can answer for a date before the close of
|
|
20
|
+
* `atSchemeYearEnd`. A walk that opens the membership held
|
|
21
|
+
* nothing then, so it can; a statement gives a balance at its 31
|
|
22
|
+
* March and nothing of the dates before it, so a read there is
|
|
23
|
+
* refused rather than answered with the statement's balance.
|
|
24
|
+
* `seedFromBalanceAt` answers, for `projectPension`'s figure
|
|
25
|
+
* stated on any day: see there. */
|
|
26
|
+
readonly answersBefore: boolean;
|
|
25
27
|
/** Whether `opening` is the scheme's own figure or ours. No
|
|
26
28
|
* arithmetic reads this — it exists so a consumer can tell a
|
|
27
29
|
* figure a member could check against paper from one this
|
|
28
30
|
* library produced. */
|
|
29
|
-
readonly basis:
|
|
31
|
+
readonly basis: SeedBasis;
|
|
30
32
|
}
|
|
33
|
+
/** A balance a member was told, and the date it was stated on. */
|
|
34
|
+
interface StatedBalance {
|
|
35
|
+
readonly balance: number;
|
|
36
|
+
readonly asOf: Date;
|
|
37
|
+
}
|
|
38
|
+
/** Whose figure a seed's opening balance is: the scheme's, read off a
|
|
39
|
+
* statement or stated by the member, or this library's own. */
|
|
40
|
+
export declare const SEED_BASES: {
|
|
41
|
+
readonly given: "given";
|
|
42
|
+
readonly derived: "derived";
|
|
43
|
+
};
|
|
44
|
+
export type SeedBasis = (typeof SEED_BASES)[keyof typeof SEED_BASES];
|
|
31
45
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* on the year after it. Both the ledger and the illustrative
|
|
36
|
-
* run-up need that year — one to start its loop, the other to
|
|
37
|
-
* decide there is anything to draw — and a rule spelled out twice
|
|
38
|
-
* is a rule that can drift, so it is read from the seed that
|
|
39
|
-
* carries it.
|
|
40
|
-
*/
|
|
41
|
-
export declare function firstWalkedYear(seed: LedgerSeed): number;
|
|
42
|
-
/**
|
|
43
|
-
* The scheme year a date falls in, named by the year it ENDS.
|
|
44
|
-
*
|
|
45
|
-
* The cycle is the scheme's own — 1 April to 31 March — and it
|
|
46
|
-
* is the same one an Annual Benefit Statement closes on: a
|
|
47
|
-
* statement marked *Updated To 31/03/2025* reports scheme year
|
|
48
|
-
* 2025, so its figure seeds that row's close untouched. 1 Apr
|
|
49
|
-
* 2025 and 31 Mar 2026 are both scheme year 2026.
|
|
50
|
-
*/
|
|
51
|
-
export declare function schemeYearEndFor(date: Date): number;
|
|
52
|
-
/** 31 March of the given scheme year. */
|
|
53
|
-
export declare function schemeYearEndDate(schemeYearEnd: number): Date;
|
|
54
|
-
/** 1 April opening the given scheme year. */
|
|
55
|
-
export declare function schemeYearStartDate(schemeYearEnd: number): Date;
|
|
56
|
-
/**
|
|
57
|
-
* The scheme year that had already CLOSED by `date` — the year
|
|
58
|
-
* a balance stated on that date belongs to.
|
|
46
|
+
* Route 1: the scheme has already told us the balance, at the close
|
|
47
|
+
* of `yearEnd`. A statement is as at 31 March, so its year is all it
|
|
48
|
+
* needs: a mid-year date cannot be expressed.
|
|
59
49
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* BEFORE a `Prices` exists to build the seed with.
|
|
50
|
+
* Yields basis 'given', and `accruingFrom` null: the first walked
|
|
51
|
+
* year is the one AFTER the statement's, which is always whole.
|
|
52
|
+
* Nothing before the statement is answered.
|
|
64
53
|
*/
|
|
65
|
-
export declare function
|
|
54
|
+
export declare function seedFromStatement(accruedPension: number, yearEnd: SchemeYearEnd): LedgerSeed;
|
|
66
55
|
/**
|
|
67
|
-
*
|
|
56
|
+
* A member's stated balance, on whatever date it is stated —
|
|
57
|
+
* the day they read it, or the day their statement prints. That
|
|
58
|
+
* is a position mid-scheme-year, and a seed is a year-end
|
|
59
|
+
* closing balance, so it has to be carried back to one.
|
|
68
60
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
61
|
+
* In November the April uplift has already been applied to the
|
|
62
|
+
* figure being read, so dividing it out lands on the last
|
|
63
|
+
* year-end closing balance and the walk re-applies it — no
|
|
64
|
+
* double count, and no year of accrual thrown away. On a date
|
|
65
|
+
* before that April the figure already IS the year-end balance
|
|
66
|
+
* and nothing is divided, which is why a statement printed on
|
|
67
|
+
* 31 March passes through untouched.
|
|
73
68
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
69
|
+
* ONE route for both the dated and the undated case, because
|
|
70
|
+
* there is only one question: what was the closing balance at
|
|
71
|
+
* the year end before this date? `seedFromStatement` takes a
|
|
72
|
+
* year end and nothing else; this is what finds one.
|
|
73
|
+
* A balance is read on arbitrary days — a statement printed on
|
|
74
|
+
* 7 November is a real one — though it is valued as at 31 March,
|
|
75
|
+
* so the strict form alone could not serve a figure read today.
|
|
76
76
|
*/
|
|
77
|
-
export declare function
|
|
77
|
+
export declare function seedFromBalanceAt({ balance, asOf }: StatedBalance, exitDate: Date, retirementDate: Date, prices: Prices): LedgerSeed;
|
|
78
78
|
/**
|
|
79
79
|
* Route 2: we compute the balance from the beginning.
|
|
80
80
|
*
|
|
@@ -84,3 +84,19 @@ export declare function seedFromStatement(accruedPension: number, statementDate:
|
|
|
84
84
|
* year's pay.
|
|
85
85
|
*/
|
|
86
86
|
export declare function seedFromJoinDate(joinDate: Date): LedgerSeed;
|
|
87
|
+
/**
|
|
88
|
+
* The first scheme year a walk from this seed produces.
|
|
89
|
+
*
|
|
90
|
+
* The seed is a balance standing AT a year end, so the walk opens
|
|
91
|
+
* on the year after it. Both the ledger and the illustrative
|
|
92
|
+
* run-up need that year — one to start its loop, the other to
|
|
93
|
+
* decide there is anything to draw — and a rule spelled out twice
|
|
94
|
+
* is a rule that can drift, so it is read from the seed that
|
|
95
|
+
* carries it.
|
|
96
|
+
*/
|
|
97
|
+
export declare function firstWalkedYear(seed: LedgerSeed): SchemeYearEnd;
|
|
98
|
+
/** The first date a walk from `seed` answers on: its close, where it does
|
|
99
|
+
* not answer before itself (a statement); null where it answers every
|
|
100
|
+
* date. The one producer the ledger refuses by and the member reports. */
|
|
101
|
+
export declare function answersFrom(seed: LedgerSeed): Date | null;
|
|
102
|
+
export {};
|
package/dist/pension/seed.js
CHANGED
|
@@ -2,79 +2,83 @@
|
|
|
2
2
|
* Where the walk starts, and what it starts from.
|
|
3
3
|
*
|
|
4
4
|
* This is the ENTIRETY of the statement-versus-estimation
|
|
5
|
-
* difference:
|
|
6
|
-
*
|
|
7
|
-
* produced it.
|
|
5
|
+
* difference: every route to a seed — a statement, a balance stated
|
|
6
|
+
* on any day, or the join date — is read exactly once, here, to fill
|
|
7
|
+
* this object, and nothing downstream may ask which produced it. The
|
|
8
|
+
* one thing a reader may ask is `answersBefore`, a capability rather
|
|
9
|
+
* than a route: whether a date before the seed has an answer at all,
|
|
10
|
+
* which is the ledger's to know before it reads one.
|
|
8
11
|
*/
|
|
12
|
+
import { dayAfter, monthsCountingPart } from '../dates.js';
|
|
9
13
|
import { invariant } from '../errors.js';
|
|
14
|
+
import { pointsToDecimal } from './prices.js';
|
|
15
|
+
import { schemeYearAfter, schemeYearBefore, schemeYearClosedBy, schemeYearEndDate, schemeYearEndFor, schemeYearStartDate, } from './scheme-year.js';
|
|
16
|
+
import { openingUpliftFor } from './uplift.js';
|
|
17
|
+
/** Whose figure a seed's opening balance is: the scheme's, read off a
|
|
18
|
+
* statement or stated by the member, or this library's own. */
|
|
19
|
+
export const SEED_BASES = {
|
|
20
|
+
given: 'given',
|
|
21
|
+
derived: 'derived',
|
|
22
|
+
};
|
|
10
23
|
/**
|
|
11
|
-
*
|
|
24
|
+
* Route 1: the scheme has already told us the balance, at the close
|
|
25
|
+
* of `yearEnd`. A statement is as at 31 March, so its year is all it
|
|
26
|
+
* needs: a mid-year date cannot be expressed.
|
|
12
27
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* decide there is anything to draw — and a rule spelled out twice
|
|
17
|
-
* is a rule that can drift, so it is read from the seed that
|
|
18
|
-
* carries it.
|
|
28
|
+
* Yields basis 'given', and `accruingFrom` null: the first walked
|
|
29
|
+
* year is the one AFTER the statement's, which is always whole.
|
|
30
|
+
* Nothing before the statement is answered.
|
|
19
31
|
*/
|
|
20
|
-
export function
|
|
21
|
-
return
|
|
32
|
+
export function seedFromStatement(accruedPension, yearEnd) {
|
|
33
|
+
return givenSeed(accruedPension, yearEnd, false);
|
|
22
34
|
}
|
|
23
35
|
/**
|
|
24
|
-
*
|
|
36
|
+
* A member's stated balance, on whatever date it is stated —
|
|
37
|
+
* the day they read it, or the day their statement prints. That
|
|
38
|
+
* is a position mid-scheme-year, and a seed is a year-end
|
|
39
|
+
* closing balance, so it has to be carried back to one.
|
|
25
40
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return date.getMonth() >= 3
|
|
34
|
-
? date.getFullYear() + 1
|
|
35
|
-
: date.getFullYear();
|
|
36
|
-
}
|
|
37
|
-
/** 31 March of the given scheme year. */
|
|
38
|
-
export function schemeYearEndDate(schemeYearEnd) {
|
|
39
|
-
return new Date(schemeYearEnd, 2, 31);
|
|
40
|
-
}
|
|
41
|
-
/** 1 April opening the given scheme year. */
|
|
42
|
-
export function schemeYearStartDate(schemeYearEnd) {
|
|
43
|
-
return new Date(schemeYearEnd - 1, 3, 1);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The scheme year that had already CLOSED by `date` — the year
|
|
47
|
-
* a balance stated on that date belongs to.
|
|
41
|
+
* In November the April uplift has already been applied to the
|
|
42
|
+
* figure being read, so dividing it out lands on the last
|
|
43
|
+
* year-end closing balance and the walk re-applies it — no
|
|
44
|
+
* double count, and no year of accrual thrown away. On a date
|
|
45
|
+
* before that April the figure already IS the year-end balance
|
|
46
|
+
* and nothing is divided, which is why a statement printed on
|
|
47
|
+
* 31 March passes through untouched.
|
|
48
48
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
49
|
+
* ONE route for both the dated and the undated case, because
|
|
50
|
+
* there is only one question: what was the closing balance at
|
|
51
|
+
* the year end before this date? `seedFromStatement` takes a
|
|
52
|
+
* year end and nothing else; this is what finds one.
|
|
53
|
+
* A balance is read on arbitrary days — a statement printed on
|
|
54
|
+
* 7 November is a real one — though it is valued as at 31 March,
|
|
55
|
+
* so the strict form alone could not serve a figure read today.
|
|
53
56
|
*/
|
|
54
|
-
export function
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
57
|
+
export function seedFromBalanceAt({ balance, asOf }, exitDate, retirementDate, prices) {
|
|
58
|
+
const lastYearEnd = schemeYearClosedBy(asOf);
|
|
59
|
+
/* A figure read after leaving, before the leaving year has closed,
|
|
60
|
+
already holds that year's part slice and its leaver adjustment,
|
|
61
|
+
and the walk would re-walk that year and add both again. Refused
|
|
62
|
+
rather than guessed at. With no month served there is neither,
|
|
63
|
+
and once the year has closed the seed is its closing and the walk
|
|
64
|
+
starts after it: both round-trip. */
|
|
65
|
+
const exitYear = schemeYearEndFor(exitDate);
|
|
66
|
+
const monthsServedBeforeLeaving = monthsCountingPart(schemeYearStartDate(exitYear), dayAfter(exitDate));
|
|
67
|
+
const leavingYearStillOpen = lastYearEnd < exitYear;
|
|
68
|
+
const readAfterServingPartOfLeavingYear = asOf > exitDate
|
|
69
|
+
&& leavingYearStillOpen
|
|
70
|
+
&& monthsServedBeforeLeaving > 0;
|
|
71
|
+
invariant(!readAfterServingPartOfLeavingYear, `a balance stated on ${asOf.toDateString()}, after leaving on `
|
|
72
|
+
+ `${exitDate.toDateString()} in the same scheme year`);
|
|
73
|
+
/* The uplift undone here is the one OPENING year
|
|
74
|
+
`lastYearEnd + 1`, and it is the very object `buildLedger`
|
|
75
|
+
re-applies to that year: inverting the walk exactly is this
|
|
76
|
+
function's only job, so both sides ask `openingUpliftFor`
|
|
77
|
+
rather than each naming the phase, the year and the CPI
|
|
78
|
+
series for themselves. */
|
|
79
|
+
const applied = openingUpliftFor(lastYearEnd, exitDate, retirementDate, prices);
|
|
80
|
+
const already = applied.appliedOn <= asOf;
|
|
81
|
+
return seedFromStatedBalance(already ? balance / (1 + pointsToDecimal(applied.percent)) : balance, lastYearEnd);
|
|
78
82
|
}
|
|
79
83
|
/**
|
|
80
84
|
* Route 2: we compute the balance from the beginning.
|
|
@@ -87,9 +91,51 @@ export function seedFromStatement(accruedPension, statementDate) {
|
|
|
87
91
|
export function seedFromJoinDate(joinDate) {
|
|
88
92
|
return {
|
|
89
93
|
opening: 0,
|
|
90
|
-
atSchemeYearEnd: schemeYearEndFor(joinDate)
|
|
94
|
+
atSchemeYearEnd: schemeYearBefore(schemeYearEndFor(joinDate)),
|
|
91
95
|
accruingFrom: joinDate,
|
|
92
|
-
|
|
96
|
+
answersBefore: true,
|
|
97
|
+
basis: SEED_BASES.derived,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The first scheme year a walk from this seed produces.
|
|
102
|
+
*
|
|
103
|
+
* The seed is a balance standing AT a year end, so the walk opens
|
|
104
|
+
* on the year after it. Both the ledger and the illustrative
|
|
105
|
+
* run-up need that year — one to start its loop, the other to
|
|
106
|
+
* decide there is anything to draw — and a rule spelled out twice
|
|
107
|
+
* is a rule that can drift, so it is read from the seed that
|
|
108
|
+
* carries it.
|
|
109
|
+
*/
|
|
110
|
+
export function firstWalkedYear(seed) {
|
|
111
|
+
return schemeYearAfter(seed.atSchemeYearEnd);
|
|
112
|
+
}
|
|
113
|
+
/** The first date a walk from `seed` answers on: its close, where it does
|
|
114
|
+
* not answer before itself (a statement); null where it answers every
|
|
115
|
+
* date. The one producer the ledger refuses by and the member reports. */
|
|
116
|
+
export function answersFrom(seed) {
|
|
117
|
+
return seed.answersBefore ? null : schemeYearEndDate(seed.atSchemeYearEnd);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A balance a member gave on any day, already carried back to the
|
|
121
|
+
* close of `yearEnd` (see `seedFromBalanceAt`). `projectPension`
|
|
122
|
+
* reads its leaving and today against it, and a leaving can fall
|
|
123
|
+
* before the year end the figure is carried back to, so a date
|
|
124
|
+
* before the seed is answered with the seed's balance. The 31 March
|
|
125
|
+
* rule that refuses such a read binds `memberBenefits`' statement,
|
|
126
|
+
* which never comes through here.
|
|
127
|
+
*/
|
|
128
|
+
function seedFromStatedBalance(balance, yearEnd) {
|
|
129
|
+
return givenSeed(balance, yearEnd, true);
|
|
130
|
+
}
|
|
131
|
+
/** A balance the scheme or the member gave, at the close of `yearEnd`. */
|
|
132
|
+
function givenSeed(opening, yearEnd, answersBefore) {
|
|
133
|
+
return {
|
|
134
|
+
opening,
|
|
135
|
+
atSchemeYearEnd: yearEnd,
|
|
136
|
+
accruingFrom: null,
|
|
137
|
+
answersBefore,
|
|
138
|
+
basis: SEED_BASES.given,
|
|
93
139
|
};
|
|
94
140
|
}
|
|
95
141
|
//# sourceMappingURL=seed.js.map
|
package/dist/pension/seed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../../src/pension/seed.ts"],"names":[],"mappings":"AAAA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,SAAS,SAAS,CAChB,OAAe,EAAE,OAAsB,EAAE,aAAsB;IAE/D,OAAO;QACL,OAAO;QACP,eAAe,EAAE,OAAO;QACxB,YAAY,EAAE,IAAI;QAClB,aAAa;QACb,KAAK,EAAE,UAAU,CAAC,KAAK;KACxB,CAAC;AACJ,CAAC"}
|
package/dist/pension/uplift.d.ts
CHANGED
|
@@ -7,14 +7,16 @@
|
|
|
7
7
|
* active CPI + 1.5, a negative CPI carried through
|
|
8
8
|
* deferred/paid max(0, CPI), floored
|
|
9
9
|
*
|
|
10
|
-
* `rate = CPI + 1.5` holds on
|
|
10
|
+
* `rate = CPI + 1.5` holds on every applied rate held, 2016–2025,
|
|
11
|
+
* in `tests/fixtures/revaluation-applied.csv`. The
|
|
11
12
|
* Pensions Increase column of the 2020 Valuation Report App. E
|
|
12
13
|
* equals `max(0, CPI)` on 8 of 8 published years, 2016–2023 —
|
|
13
14
|
* including 2016, where −0.1 CPI gives 1.4 active and 0.0
|
|
14
15
|
* deferred, and 2023's 10.1 spike.
|
|
15
16
|
*
|
|
16
|
-
* So there is no second rate table. The published
|
|
17
|
-
* Increase figures are
|
|
17
|
+
* So there is no second rate table. The published applied rates
|
|
18
|
+
* and Pensions Increase figures are GOLDEN TESTS, not production
|
|
19
|
+
* data.
|
|
18
20
|
*
|
|
19
21
|
* Note the direction: CPI is sourced independently from each
|
|
20
22
|
* Order's operative words and the rates derive forward from it.
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
* make the test of the +1.5 rule agree with itself.
|
|
23
25
|
*/
|
|
24
26
|
import type { CpiEntry, CpiSource, Prices } from './prices.js';
|
|
25
|
-
import type {
|
|
27
|
+
import type { SchemeYearEnd } from './scheme-year.js';
|
|
26
28
|
/**
|
|
27
29
|
* The three phases. Ordered by date and DERIVED from the member's
|
|
28
30
|
* own dates: a phase is never "entered", so there are no
|
|
@@ -63,14 +65,14 @@ export interface AppliedUplift {
|
|
|
63
65
|
* field, `LedgerYear.uplift`; nullability there is about the
|
|
64
66
|
* walk's first step, not about this rule, and putting it here
|
|
65
67
|
* would make every caller narrow a value it always gets. */
|
|
66
|
-
export type UpliftSource = (schemeYearEnd:
|
|
68
|
+
export type UpliftSource = (schemeYearEnd: SchemeYearEnd) => AppliedUplift;
|
|
67
69
|
/** Active until the member leaves, deferred until they draw, in
|
|
68
70
|
* payment after. Derived from dates; never entered.
|
|
69
71
|
*
|
|
70
72
|
* Lives beside the rule it selects, because the rule is a
|
|
71
73
|
* function of phase alone and this is the only way a phase is
|
|
72
74
|
* ever obtained. */
|
|
73
|
-
export declare function phaseAt(year:
|
|
75
|
+
export declare function phaseAt(year: SchemeYearEnd, exitYear: SchemeYearEnd, retireYear: SchemeYearEnd): MemberPhase;
|
|
74
76
|
/** CPI + 1.5 points. A negative CPI is carried through, not
|
|
75
77
|
* floored: September 2015's −0.1 gave a 1.4% uplift, not 1.5%. */
|
|
76
78
|
export declare function activeRatePct(cpi: number): number;
|
|
@@ -107,10 +109,10 @@ export declare function deferredRatePct(cpi: number): number;
|
|
|
107
109
|
*
|
|
108
110
|
* That the published rates ARE `CPI + 1.5` is not asserted here,
|
|
109
111
|
* because nothing here reads them: the rule is checked against
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
112
|
+
* every applied rate at once, by `tests/prices.test.ts` —
|
|
113
|
+
* "reproduces every applied rate". That check owns it, and it
|
|
114
|
+
* fires whether or not any caller ever asks for a published
|
|
115
|
+
* year.
|
|
114
116
|
*/
|
|
115
117
|
export declare function upliftsFor(phase: MemberPhase, cpiFor: CpiSource): UpliftSource;
|
|
116
118
|
/**
|
|
@@ -157,26 +159,4 @@ export declare function upliftsFor(phase: MemberPhase, cpiFor: CpiSource): Uplif
|
|
|
157
159
|
* deferred or in-payment rate: the months the pension has run by
|
|
158
160
|
* that April, over twelve. See `firstIncreaseShare`.
|
|
159
161
|
*/
|
|
160
|
-
export declare function openingUpliftFor(seedSchemeYearEnd:
|
|
161
|
-
/**
|
|
162
|
-
* A member's stated balance, on whatever date it is stated —
|
|
163
|
-
* the day they read it, or the day their statement prints. That
|
|
164
|
-
* is a position mid-scheme-year, and a seed is a year-end
|
|
165
|
-
* closing balance, so it has to be carried back to one.
|
|
166
|
-
*
|
|
167
|
-
* In November the April uplift has already been applied to the
|
|
168
|
-
* figure being read, so dividing it out lands on the last
|
|
169
|
-
* year-end closing balance and the walk re-applies it — no
|
|
170
|
-
* double count, and no year of accrual thrown away. On a date
|
|
171
|
-
* before that April the figure already IS the year-end balance
|
|
172
|
-
* and nothing is divided, which is why a statement printed on
|
|
173
|
-
* 31 March passes through untouched.
|
|
174
|
-
*
|
|
175
|
-
* ONE route for both the dated and the undated case, because
|
|
176
|
-
* there is only one question: what was the closing balance at
|
|
177
|
-
* the year end before this date? `seedFromStatement` stays
|
|
178
|
-
* strict about wanting a year end; this is what finds it.
|
|
179
|
-
* Statements print on arbitrary days — 7 November is a real
|
|
180
|
-
* one — so the strict form alone could not serve them.
|
|
181
|
-
*/
|
|
182
|
-
export declare function seedFromBalanceAt(balance: number, asOf: Date, exitDate: Date, retirementDate: Date, prices: Prices): LedgerSeed;
|
|
162
|
+
export declare function openingUpliftFor(seedSchemeYearEnd: SchemeYearEnd, exitDate: Date, retirementDate: Date, prices: Prices): AppliedUplift;
|
package/dist/pension/uplift.js
CHANGED
|
@@ -7,14 +7,16 @@
|
|
|
7
7
|
* active CPI + 1.5, a negative CPI carried through
|
|
8
8
|
* deferred/paid max(0, CPI), floored
|
|
9
9
|
*
|
|
10
|
-
* `rate = CPI + 1.5` holds on
|
|
10
|
+
* `rate = CPI + 1.5` holds on every applied rate held, 2016–2025,
|
|
11
|
+
* in `tests/fixtures/revaluation-applied.csv`. The
|
|
11
12
|
* Pensions Increase column of the 2020 Valuation Report App. E
|
|
12
13
|
* equals `max(0, CPI)` on 8 of 8 published years, 2016–2023 —
|
|
13
14
|
* including 2016, where −0.1 CPI gives 1.4 active and 0.0
|
|
14
15
|
* deferred, and 2023's 10.1 spike.
|
|
15
16
|
*
|
|
16
|
-
* So there is no second rate table. The published
|
|
17
|
-
* Increase figures are
|
|
17
|
+
* So there is no second rate table. The published applied rates
|
|
18
|
+
* and Pensions Increase figures are GOLDEN TESTS, not production
|
|
19
|
+
* data.
|
|
18
20
|
*
|
|
19
21
|
* Note the direction: CPI is sourced independently from each
|
|
20
22
|
* Order's operative words and the rates derive forward from it.
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
import { ACTIVE_REVAL_BONUS_PCT, appliedOnFor, } from '../revaluation.js';
|
|
25
27
|
import { invariant } from '../errors.js';
|
|
26
28
|
import { dayAfter, monthsCountingPart, MONTHS_PER_YEAR } from '../dates.js';
|
|
27
|
-
import {
|
|
29
|
+
import { schemeYearAfter, schemeYearEndFor } from './scheme-year.js';
|
|
28
30
|
/** Active until the member leaves, deferred until they draw, in
|
|
29
31
|
* payment after. Derived from dates; never entered.
|
|
30
32
|
*
|
|
@@ -76,10 +78,10 @@ export function deferredRatePct(cpi) {
|
|
|
76
78
|
*
|
|
77
79
|
* That the published rates ARE `CPI + 1.5` is not asserted here,
|
|
78
80
|
* because nothing here reads them: the rule is checked against
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
81
|
+
* every applied rate at once, by `tests/prices.test.ts` —
|
|
82
|
+
* "reproduces every applied rate". That check owns it, and it
|
|
83
|
+
* fires whether or not any caller ever asks for a published
|
|
84
|
+
* year.
|
|
83
85
|
*/
|
|
84
86
|
export function upliftsFor(phase, cpiFor) {
|
|
85
87
|
const ratePct = phase === 'active'
|
|
@@ -139,60 +141,13 @@ export function upliftsFor(phase, cpiFor) {
|
|
|
139
141
|
* that April, over twelve. See `firstIncreaseShare`.
|
|
140
142
|
*/
|
|
141
143
|
export function openingUpliftFor(seedSchemeYearEnd, exitDate, retirementDate, prices) {
|
|
142
|
-
const phase = phaseAt(seedSchemeYearEnd
|
|
144
|
+
const phase = phaseAt(schemeYearAfter(seedSchemeYearEnd), schemeYearEndFor(exitDate), schemeYearEndFor(retirementDate));
|
|
143
145
|
const uplift = upliftsFor(phase, prices.cpiFor)(seedSchemeYearEnd);
|
|
144
146
|
const firstAfterLeaving = seedSchemeYearEnd === schemeYearEndFor(exitDate);
|
|
145
147
|
if (!firstAfterLeaving)
|
|
146
148
|
return uplift;
|
|
147
149
|
return { ...uplift, percent: uplift.percent * firstIncreaseShare(exitDate, uplift.appliedOn) };
|
|
148
150
|
}
|
|
149
|
-
/**
|
|
150
|
-
* A member's stated balance, on whatever date it is stated —
|
|
151
|
-
* the day they read it, or the day their statement prints. That
|
|
152
|
-
* is a position mid-scheme-year, and a seed is a year-end
|
|
153
|
-
* closing balance, so it has to be carried back to one.
|
|
154
|
-
*
|
|
155
|
-
* In November the April uplift has already been applied to the
|
|
156
|
-
* figure being read, so dividing it out lands on the last
|
|
157
|
-
* year-end closing balance and the walk re-applies it — no
|
|
158
|
-
* double count, and no year of accrual thrown away. On a date
|
|
159
|
-
* before that April the figure already IS the year-end balance
|
|
160
|
-
* and nothing is divided, which is why a statement printed on
|
|
161
|
-
* 31 March passes through untouched.
|
|
162
|
-
*
|
|
163
|
-
* ONE route for both the dated and the undated case, because
|
|
164
|
-
* there is only one question: what was the closing balance at
|
|
165
|
-
* the year end before this date? `seedFromStatement` stays
|
|
166
|
-
* strict about wanting a year end; this is what finds it.
|
|
167
|
-
* Statements print on arbitrary days — 7 November is a real
|
|
168
|
-
* one — so the strict form alone could not serve them.
|
|
169
|
-
*/
|
|
170
|
-
export function seedFromBalanceAt(balance, asOf, exitDate, retirementDate, prices) {
|
|
171
|
-
const lastYearEnd = schemeYearClosedBy(asOf);
|
|
172
|
-
/* A figure read after leaving, before the leaving year has closed,
|
|
173
|
-
already holds that year's part slice and its leaver adjustment,
|
|
174
|
-
and the walk would re-walk that year and add both again. Refused
|
|
175
|
-
rather than guessed at. With no month served there is neither,
|
|
176
|
-
and once the year has closed the seed is its closing and the walk
|
|
177
|
-
starts after it: both round-trip. */
|
|
178
|
-
const exitYear = schemeYearEndFor(exitDate);
|
|
179
|
-
const monthsServedBeforeLeaving = monthsCountingPart(schemeYearStartDate(exitYear), dayAfter(exitDate));
|
|
180
|
-
const leavingYearStillOpen = lastYearEnd < exitYear;
|
|
181
|
-
const readAfterServingPartOfLeavingYear = asOf > exitDate
|
|
182
|
-
&& leavingYearStillOpen
|
|
183
|
-
&& monthsServedBeforeLeaving > 0;
|
|
184
|
-
invariant(!readAfterServingPartOfLeavingYear, `a balance stated on ${asOf.toDateString()}, after leaving on `
|
|
185
|
-
+ `${exitDate.toDateString()} in the same scheme year`);
|
|
186
|
-
/* The uplift undone here is the one OPENING year
|
|
187
|
-
`lastYearEnd + 1`, and it is the very object `buildLedger`
|
|
188
|
-
re-applies to that year: inverting the walk exactly is this
|
|
189
|
-
function's only job, so both sides ask `openingUpliftFor`
|
|
190
|
-
rather than each naming the phase, the year and the CPI
|
|
191
|
-
series for themselves. */
|
|
192
|
-
const applied = openingUpliftFor(lastYearEnd, exitDate, retirementDate, prices);
|
|
193
|
-
const already = applied.appliedOn <= asOf;
|
|
194
|
-
return seedFromStatement(already ? balance / (1 + applied.percent / 100) : balance, schemeYearEndDate(lastYearEnd));
|
|
195
|
-
}
|
|
196
151
|
/**
|
|
197
152
|
* A pension's first increase after it begins is proportionate to the
|
|
198
153
|
* months it has run: HM Treasury's 2026 Pensions Increase tables
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uplift.js","sourceRoot":"","sources":["../../src/pension/uplift.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"uplift.js","sourceRoot":"","sources":["../../src/pension/uplift.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EACL,sBAAsB,EACtB,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,QAAQ,EAAE,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