@casomoltd/nhs-pay 0.30.0 → 0.32.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 +71 -252
- 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 +32 -7
- package/dist/document-source.js +32 -8
- package/dist/document-source.js.map +1 -1
- package/dist/errors.d.ts +57 -11
- package/dist/errors.js +85 -28
- package/dist/errors.js.map +1 -1
- package/dist/factor-basis.d.ts +23 -3
- package/dist/factor-basis.js +40 -28
- package/dist/factor-basis.js.map +1 -1
- package/dist/index.d.ts +16 -14
- package/dist/index.js +9 -8
- package/dist/index.js.map +1 -1
- package/dist/member/benefits.js +25 -13
- 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 +14 -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 +95 -59
- package/dist/pension/ledger.js.map +1 -1
- package/dist/pension/money.d.ts +2 -0
- package/dist/pension/money.js +4 -0
- package/dist/pension/money.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 +38 -54
- package/dist/pension/uplift.js +38 -68
- 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 +56 -41
- package/dist/revaluation.js +76 -62
- 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 +6 -10
- package/dist/sections/final-salary.js.map +1 -1
- package/dist/sections/section-2015.d.ts +3 -4
- package/dist/sections/section-2015.js +1 -1
- package/dist/sections/section-2015.js.map +1 -1
- package/dist/sources.d.ts +14 -0
- package/dist/sources.js +24 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curve.js","sourceRoot":"","sources":["../../src/pension/curve.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAC,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"curve.js","sourceRoot":"","sources":["../../src/pension/curve.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAC,aAAa,EAAE,iBAAiB,EA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would be arguing in a circle.
|
|
34
34
|
*
|
|
35
|
+
* It is **the one estimate of the years before a statement**.
|
|
36
|
+
* The statement's own walk refuses every read before its 31 March
|
|
37
|
+
* (`BeforeStatement`); this walks a ledger of its own from the join
|
|
38
|
+
* date, so the chart's built-up arm is drawn from here and nowhere
|
|
39
|
+
* else.
|
|
40
|
+
*
|
|
35
41
|
* ── Why it is calibrated by a walk, not a formula ───
|
|
36
42
|
*
|
|
37
43
|
* Closed form exists. With flat pay, a constant rate `r` and
|
|
@@ -71,6 +77,7 @@
|
|
|
71
77
|
*/
|
|
72
78
|
import type { MemberLedger } from './ledger.js';
|
|
73
79
|
import type { Prices } from './prices.js';
|
|
80
|
+
import type { SchemeYearEnd } from './scheme-year.js';
|
|
74
81
|
/** An illustrative run-up to a stated balance. */
|
|
75
82
|
export interface EstimatedHistory {
|
|
76
83
|
/**
|
|
@@ -86,12 +93,20 @@ export interface EstimatedHistory {
|
|
|
86
93
|
/** The walked years, ending exactly on the stated balance. */
|
|
87
94
|
readonly ledger: MemberLedger;
|
|
88
95
|
/** First and last scheme year covered, inclusive. */
|
|
89
|
-
readonly from:
|
|
90
|
-
readonly to:
|
|
96
|
+
readonly from: SchemeYearEnd;
|
|
97
|
+
readonly to: SchemeYearEnd;
|
|
91
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Estimate the years from `joinDate` up to a stated balance.
|
|
101
|
+
*
|
|
102
|
+
* Null when there is nothing to draw — a member who joined in
|
|
103
|
+
* or after the statement's own scheme year has no run-up, and
|
|
104
|
+
* inventing one would put pension on the chart before they had
|
|
105
|
+
* any.
|
|
106
|
+
*/
|
|
92
107
|
export declare function estimateHistory({ joinDate, statedBalance, statementSchemeYearEnd, prices, }: {
|
|
93
108
|
joinDate: Date;
|
|
94
109
|
statedBalance: number;
|
|
95
|
-
statementSchemeYearEnd:
|
|
110
|
+
statementSchemeYearEnd: SchemeYearEnd;
|
|
96
111
|
prices: Prices;
|
|
97
112
|
}): EstimatedHistory | null;
|
package/dist/pension/history.js
CHANGED
|
@@ -32,6 +32,12 @@
|
|
|
32
32
|
* member actually gave. A pension projected from a pay derived
|
|
33
33
|
* from that same pension would be arguing in a circle.
|
|
34
34
|
*
|
|
35
|
+
* It is **the one estimate of the years before a statement**.
|
|
36
|
+
* The statement's own walk refuses every read before its 31 March
|
|
37
|
+
* (`BeforeStatement`); this walks a ledger of its own from the join
|
|
38
|
+
* date, so the chart's built-up arm is drawn from here and nowhere
|
|
39
|
+
* else.
|
|
40
|
+
*
|
|
35
41
|
* ── Why it is calibrated by a walk, not a formula ───
|
|
36
42
|
*
|
|
37
43
|
* Closed form exists. With flat pay, a constant rate `r` and
|
|
@@ -70,7 +76,11 @@
|
|
|
70
76
|
* 2021 pounds with 2025 pounds and reads low by a tenth.
|
|
71
77
|
*/
|
|
72
78
|
import { buildLedger, flatPay } from './ledger.js';
|
|
73
|
-
import {
|
|
79
|
+
import { schemeYearEnd, schemeYearEndDate } from './scheme-year.js';
|
|
80
|
+
import { firstWalkedYear, seedFromJoinDate } from './seed.js';
|
|
81
|
+
/** Far enough past the statement that no leaving or drawing date
|
|
82
|
+
* falls inside the estimated window. */
|
|
83
|
+
const YEARS_BEYOND_THE_WINDOW = 60;
|
|
74
84
|
/**
|
|
75
85
|
* Estimate the years from `joinDate` up to a stated balance.
|
|
76
86
|
*
|
|
@@ -79,16 +89,13 @@ import { firstWalkedYear, schemeYearEndDate, seedFromJoinDate, } from './seed.js
|
|
|
79
89
|
* inventing one would put pension on the chart before they had
|
|
80
90
|
* any.
|
|
81
91
|
*/
|
|
82
|
-
/** Far enough past the statement that no leaving or drawing date
|
|
83
|
-
* falls inside the estimated window. */
|
|
84
|
-
const YEARS_BEYOND_THE_WINDOW = 60;
|
|
85
92
|
export function estimateHistory({ joinDate, statedBalance, statementSchemeYearEnd, prices, }) {
|
|
86
93
|
const seed = seedFromJoinDate(joinDate);
|
|
87
94
|
const first = firstWalkedYear(seed);
|
|
88
95
|
if (first > statementSchemeYearEnd || statedBalance <= 0) {
|
|
89
96
|
return null;
|
|
90
97
|
}
|
|
91
|
-
const beyondTheWindow = schemeYearEndDate(statementSchemeYearEnd + YEARS_BEYOND_THE_WINDOW);
|
|
98
|
+
const beyondTheWindow = schemeYearEndDate(schemeYearEnd(statementSchemeYearEnd + YEARS_BEYOND_THE_WINDOW));
|
|
92
99
|
const walk = (pay) => buildLedger({
|
|
93
100
|
seed,
|
|
94
101
|
payIn: flatPay(pay),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/pension/history.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/pension/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH,OAAO,EAAC,WAAW,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAGjD,OAAO,EAAC,aAAa,EAAE,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAC,eAAe,EAAE,gBAAgB,EAAC,MAAM,WAAW,CAAC;AAsB5D;yCACyC;AACzC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,QAAQ,EACR,aAAa,EACb,sBAAsB,EACtB,MAAM,GAMP;IACC,MAAM,IAAI,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,KAAK,GAAG,sBAAsB,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,eAAe,GAAG,iBAAiB,CACvC,aAAa,CAAC,sBAAsB,GAAG,uBAAuB,CAAC,CAChE,CAAC;IACF,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,WAAW,CAAC;QACxC,IAAI;QACJ,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC;QACnB,4DAA4D;QAC5D,gEAAgE;QAChE,iEAAiE;QACjE,sCAAsC;QACtC,QAAQ,EAAE,eAAe;QACzB,cAAc,EAAE,eAAe;QAC/B,MAAM;QACN,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI;QACtB,OAAO,EAAE,sBAAsB;KAChC,CAAC,CAAC;IAEH,4DAA4D;IAC5D,kDAAkD;IAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;IAC3D,wDAAwD;IACxD,6DAA6D;IAC7D,2DAA2D;IAC3D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAE7D,MAAM,UAAU,GAAG,aAAa,GAAG,QAAQ,CAAC;IAC5C,OAAO;QACL,UAAU;QACV,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC;QACxB,IAAI,EAAE,KAAK;QACX,EAAE,EAAE,sBAAsB;KAC3B,CAAC;AACJ,CAAC"}
|
package/dist/pension/ledger.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { FactorProvenance, FactorTableKind } from '../gad/factor-table.js';
|
|
|
23
23
|
import type { PayBasis, YearPay } from '../pay-path.js';
|
|
24
24
|
import type { CpiEntry, Prices } from './prices.js';
|
|
25
25
|
import type { AppliedUplift, MemberPhase } from './uplift.js';
|
|
26
|
+
import type { SchemeYearEnd } from './scheme-year.js';
|
|
26
27
|
import type { LedgerSeed } from './seed.js';
|
|
27
28
|
/** The retirement event, recorded on the year it falls in. */
|
|
28
29
|
export interface AppliedDrawing {
|
|
@@ -64,7 +65,7 @@ export interface AppliedLeaverAdjustment {
|
|
|
64
65
|
export interface LedgerYear {
|
|
65
66
|
/** Scheme year END — 2026 for 2025/26. The same key the
|
|
66
67
|
* revaluation table uses, so a row joins by value. */
|
|
67
|
-
readonly schemeYearEnd:
|
|
68
|
+
readonly schemeYearEnd: SchemeYearEnd;
|
|
68
69
|
readonly phase: MemberPhase;
|
|
69
70
|
/** Nominal pensionable pay for this year, or null when not
|
|
70
71
|
* accruing. In a partial year this is the PAY scaled by months
|
|
@@ -122,13 +123,18 @@ export interface MemberLedger {
|
|
|
122
123
|
* or the today's-money one, and it reports in the money it
|
|
123
124
|
* was built in. Pairing the two is the orchestrator's job —
|
|
124
125
|
* see `pension-projection.ts` — because neither walk can see
|
|
125
|
-
* the other.
|
|
126
|
+
* the other.
|
|
127
|
+
*
|
|
128
|
+
* Before a statement's 31 March this and `accruedAt` throw
|
|
129
|
+
* `BeforeStatement`: the statement gives no balance there. */
|
|
126
130
|
atDate(date: Date): number;
|
|
127
|
-
/** Closing balance at the end of a scheme year.
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
|
|
131
|
+
/** Closing balance at the end of a scheme year. The seed's own
|
|
132
|
+
* year returns the seed balance: the walk starts after it, so
|
|
133
|
+
* there is no row, but there is still an answer. A year before
|
|
134
|
+
* it does the same for a walk that opens the membership, and
|
|
135
|
+
* for a statement's walk throws `BeforeStatement`, as every
|
|
136
|
+
* read before a statement does. */
|
|
137
|
+
closingAt(schemeYearEnd: SchemeYearEnd): number;
|
|
132
138
|
/** The ACCRUED entitlement at `date`, before any retirement
|
|
133
139
|
* factor. Distinct from `atDate`, which reports the pension
|
|
134
140
|
* actually in force: on the row carrying the drawing those
|
|
@@ -147,7 +153,7 @@ export interface MemberLedger {
|
|
|
147
153
|
* revalued at the in-service rate, but their accrual belongs to
|
|
148
154
|
* another ledger.
|
|
149
155
|
*/
|
|
150
|
-
export type PayIn = (schemeYearEnd:
|
|
156
|
+
export type PayIn = (schemeYearEnd: SchemeYearEnd) => YearPay | {
|
|
151
157
|
readonly pay: number;
|
|
152
158
|
readonly basis: typeof LEDGER_BASES.assumed;
|
|
153
159
|
} | null;
|
|
@@ -187,7 +193,7 @@ export interface LedgerRequest {
|
|
|
187
193
|
/** The retirement event, built once for the year it falls in. */
|
|
188
194
|
readonly drawingFor: () => AppliedDrawing | null;
|
|
189
195
|
/** Last scheme year to walk. */
|
|
190
|
-
readonly through:
|
|
196
|
+
readonly through: SchemeYearEnd;
|
|
191
197
|
}
|
|
192
198
|
/**
|
|
193
199
|
* 1/54 of pensionable pay, the 2015 CARE accrual rate — NHSBSA
|
package/dist/pension/ledger.js
CHANGED
|
@@ -19,10 +19,16 @@
|
|
|
19
19
|
* source on every call, never stored, and every row is frozen at
|
|
20
20
|
* construction.
|
|
21
21
|
*/
|
|
22
|
-
import {
|
|
22
|
+
import { uplift } from '@casomoltd/paye-calc';
|
|
23
|
+
import { BeforeStatement, invariant, isBeforeStatement, STATEMENT_READS, } from '../errors.js';
|
|
23
24
|
import { dayAfter, monthsCountingPart, MONTHS_PER_YEAR } from '../dates.js';
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
25
|
+
import { pointsToDecimal } from './prices.js';
|
|
26
|
+
import { MEMBER_PHASES, openingUpliftFor, phaseAt, upliftsFor, } from './uplift.js';
|
|
27
|
+
import { schemeYearAfter, schemeYearBefore, schemeYearEndDate, schemeYearEndFor, schemeYearStartDate, } from './scheme-year.js';
|
|
28
|
+
import { answersFrom, firstWalkedYear } from './seed.js';
|
|
29
|
+
/** The 2015 Section's accrual denominator: a year's pension is its
|
|
30
|
+
* pensionable pay over 54. */
|
|
31
|
+
const ACCRUAL_DENOMINATOR = 54;
|
|
26
32
|
/**
|
|
27
33
|
* 1/54 of pensionable pay, the 2015 CARE accrual rate — NHSBSA
|
|
28
34
|
* 2015 Members' Guide (V13) p.6.
|
|
@@ -31,7 +37,7 @@ import { firstWalkedYear, schemeYearEndDate, schemeYearEndFor, schemeYearStartDa
|
|
|
31
37
|
* slice and every figure a consumer reads come from one constant
|
|
32
38
|
* rather than a literal here and a name somewhere else.
|
|
33
39
|
*/
|
|
34
|
-
export const ACCRUAL_RATE = 1 /
|
|
40
|
+
export const ACCRUAL_RATE = 1 / ACCRUAL_DENOMINATOR;
|
|
35
41
|
/** What a ledger row's earnings rest on beyond a pay path's own bases:
|
|
36
42
|
* one flat figure the caller assumed, or nothing earned. */
|
|
37
43
|
const LEDGER_BASES = {
|
|
@@ -47,12 +53,15 @@ export function flatPay(pay) {
|
|
|
47
53
|
}
|
|
48
54
|
export function buildLedger(req) {
|
|
49
55
|
const { seed, exitDate, retirementDate, through } = req;
|
|
56
|
+
// Refused here, where every walk is built, rather than by each caller:
|
|
57
|
+
// a leaving before the seed's close is never walked.
|
|
58
|
+
refuseBeforeStatement(seed, exitDate, STATEMENT_READS.leaving);
|
|
50
59
|
const exitYear = schemeYearEndFor(exitDate);
|
|
51
60
|
const retireYear = schemeYearEndFor(retirementDate);
|
|
52
61
|
const first = firstWalkedYear(seed);
|
|
53
62
|
const years = [];
|
|
54
63
|
let opening = seed.opening;
|
|
55
|
-
for (let year = first; year <= through; year
|
|
64
|
+
for (let year = first; year <= through; year = schemeYearAfter(year)) {
|
|
56
65
|
const row = rowFor({
|
|
57
66
|
year,
|
|
58
67
|
opening,
|
|
@@ -62,7 +71,7 @@ export function buildLedger(req) {
|
|
|
62
71
|
begins inside the first walked year — never off which
|
|
63
72
|
route produced it, which the seed's own doc forbids
|
|
64
73
|
anything downstream from asking. */
|
|
65
|
-
|
|
74
|
+
opensMembership: years.length === 0 && seed.accruingFrom !== null,
|
|
66
75
|
req, first, exitYear, retireYear,
|
|
67
76
|
});
|
|
68
77
|
years.push(row);
|
|
@@ -109,7 +118,7 @@ function monthsServedIn(year, req, first) {
|
|
|
109
118
|
return monthsCountingPart(from, dayAfter(req.exitDate));
|
|
110
119
|
}
|
|
111
120
|
if (joinedThisYear !== null) {
|
|
112
|
-
return monthsCountingPart(joinedThisYear, schemeYearStartDate(year
|
|
121
|
+
return monthsCountingPart(joinedThisYear, schemeYearStartDate(schemeYearAfter(year)));
|
|
113
122
|
}
|
|
114
123
|
return MONTHS_PER_YEAR;
|
|
115
124
|
}
|
|
@@ -125,65 +134,81 @@ function payFor({ year, prices, annualPay, months, }) {
|
|
|
125
134
|
const whole = prices.payAt(annualPay, schemeYearEndDate(year));
|
|
126
135
|
return (whole * months) / MONTHS_PER_YEAR;
|
|
127
136
|
}
|
|
137
|
+
/** `amount` grown by a rate in percentage points. */
|
|
138
|
+
function grownBy(amount, points) {
|
|
139
|
+
return uplift(amount, pointsToDecimal(points));
|
|
140
|
+
}
|
|
128
141
|
/** One row: revalue the pot, add the year's slice, then apply
|
|
129
142
|
* the retirement transform if this is the year it falls in. */
|
|
130
143
|
function rowFor(ctx) {
|
|
131
|
-
const { year, opening, req
|
|
132
|
-
const
|
|
133
|
-
const
|
|
144
|
+
const { year, opening, req } = ctx;
|
|
145
|
+
const phase = phaseAt(year, ctx.exitYear, ctx.retireYear);
|
|
146
|
+
const uplift = upliftOpening(ctx);
|
|
147
|
+
const revalued = grownBy(opening, uplift?.percent ?? 0);
|
|
148
|
+
const monthsServed = monthsServedIn(year, req, ctx.first);
|
|
149
|
+
const earnings = earningsIn(ctx, phase, monthsServed);
|
|
150
|
+
const leaverAdjustment = leaverAdjustmentIn(ctx, monthsServed);
|
|
151
|
+
const accrued = grownBy(revalued + earnings.earned, leaverAdjustment?.percent ?? 0);
|
|
152
|
+
const drawing = year === ctx.retireYear ? req.drawingFor() : null;
|
|
153
|
+
return Object.freeze({
|
|
154
|
+
schemeYearEnd: year,
|
|
155
|
+
phase,
|
|
156
|
+
pensionableEarnings: earnings.pensionableEarnings,
|
|
157
|
+
earned: earnings.earned,
|
|
158
|
+
earningsBasis: basisOf(earnings),
|
|
159
|
+
opening,
|
|
160
|
+
uplift: frozenOrNull(uplift),
|
|
161
|
+
revalued,
|
|
162
|
+
leaverAdjustment: frozenOrNull(leaverAdjustment),
|
|
163
|
+
accrued,
|
|
164
|
+
drawing: frozenOrNull(drawing),
|
|
165
|
+
closing: accrued * (drawing?.factor ?? 1),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/** The uplift opening a row's year; null on the first row of a walk
|
|
169
|
+
* that opens the membership. */
|
|
170
|
+
function upliftOpening({ opensMembership, year, req }) {
|
|
134
171
|
/* The rate is `openingUpliftFor`'s answer, never assembled
|
|
135
172
|
here: the seed inverts this exact step, and the two must ask
|
|
136
173
|
one function rather than each name the phase, the year and
|
|
137
174
|
the series for themselves. */
|
|
138
|
-
|
|
175
|
+
return opensMembership
|
|
139
176
|
? null
|
|
140
|
-
: openingUpliftFor(year
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
? req.
|
|
177
|
+
: openingUpliftFor(schemeYearBefore(year), req.exitDate, req.retirementDate, req.prices);
|
|
178
|
+
}
|
|
179
|
+
/** The leaver index adjustment on the row the member leaves in; null on
|
|
180
|
+
* every other. */
|
|
181
|
+
function leaverAdjustmentIn({ year, exitYear, req }, monthsServed) {
|
|
182
|
+
return year === exitYear
|
|
183
|
+
? leaverAdjustmentFor(year, req.prices, req.exitDate, monthsServed)
|
|
147
184
|
: null;
|
|
185
|
+
}
|
|
186
|
+
/** A row's part, frozen, so it cannot be rewritten through the row. */
|
|
187
|
+
function frozenOrNull(part) {
|
|
188
|
+
return part === null ? null : Object.freeze(part);
|
|
189
|
+
}
|
|
190
|
+
/** A year's pensionable pay and its slice: pay only while active. */
|
|
191
|
+
function earningsIn({ year, req }, phase, months) {
|
|
192
|
+
const given = phase === MEMBER_PHASES.active ? req.payIn(year) : null;
|
|
148
193
|
const pensionableEarnings = given === null
|
|
149
194
|
? null
|
|
150
|
-
: payFor({ year, prices, annualPay: given.pay, months
|
|
151
|
-
const earned = pensionableEarnings === null
|
|
152
|
-
? 0
|
|
153
|
-
: pensionableEarnings * ACCRUAL_RATE;
|
|
154
|
-
const leftThisYear = year === exitYear;
|
|
155
|
-
const leaverAdjustment = leftThisYear
|
|
156
|
-
? leaverAdjustmentFor(year, prices, req.exitDate, monthsServed)
|
|
157
|
-
: null;
|
|
158
|
-
const accrued = (revalued + earned)
|
|
159
|
-
* (1 + (leaverAdjustment?.percent ?? 0) / 100);
|
|
160
|
-
const drawing = year === retireYear
|
|
161
|
-
? req.drawingFor()
|
|
162
|
-
: null;
|
|
163
|
-
const factor = drawing?.factor ?? 1;
|
|
195
|
+
: payFor({ year, prices: req.prices, annualPay: given.pay, months });
|
|
164
196
|
// The one nonsense the shape still permits. An invariant
|
|
165
197
|
// rather than three row subtypes: nothing about a row's
|
|
166
198
|
// BEHAVIOUR differs by phase, so there is nothing to dispatch
|
|
167
199
|
// and subtypes would override nothing.
|
|
168
|
-
invariant(phase ===
|
|
169
|
-
return
|
|
170
|
-
|
|
171
|
-
phase,
|
|
200
|
+
invariant(phase === MEMBER_PHASES.active || pensionableEarnings === null, `${phase} year ${year} carries pensionable earnings`);
|
|
201
|
+
return {
|
|
202
|
+
given,
|
|
172
203
|
pensionableEarnings,
|
|
173
|
-
earned
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
? null
|
|
182
|
-
: Object.freeze(leaverAdjustment),
|
|
183
|
-
accrued,
|
|
184
|
-
drawing: drawing === null ? null : Object.freeze(drawing),
|
|
185
|
-
closing: accrued * factor,
|
|
186
|
-
});
|
|
204
|
+
earned: pensionableEarnings === null
|
|
205
|
+
? 0
|
|
206
|
+
: pensionableEarnings * ACCRUAL_RATE,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** What a row's earnings rest on: nothing, where nothing was earned. */
|
|
210
|
+
function basisOf({ given, earned }) {
|
|
211
|
+
return earned === 0 || given === null ? LEDGER_BASES.none : given.basis;
|
|
187
212
|
}
|
|
188
213
|
/**
|
|
189
214
|
* The leaver index adjustment for the year the member leaves in
|
|
@@ -194,7 +219,7 @@ function rowFor(ctx) {
|
|
|
194
219
|
* and 28(2)).
|
|
195
220
|
*/
|
|
196
221
|
function leaverAdjustmentFor(year, prices, exitDate, months) {
|
|
197
|
-
const inService = upliftsFor(
|
|
222
|
+
const inService = upliftsFor(MEMBER_PHASES.active, prices.cpiFor)(year);
|
|
198
223
|
return {
|
|
199
224
|
on: exitDate,
|
|
200
225
|
percent: Math.max(0, inService.percent * months / MONTHS_PER_YEAR),
|
|
@@ -215,6 +240,17 @@ function settlementOf(row) {
|
|
|
215
240
|
const upliftOn = row.uplift?.appliedOn;
|
|
216
241
|
return upliftOn !== undefined && upliftOn > leftOn ? upliftOn : leftOn;
|
|
217
242
|
}
|
|
243
|
+
/** Refuse `read` on `date` where it falls before a statement's 31 March,
|
|
244
|
+
* which gives no balance there: the one estimate of those years is
|
|
245
|
+
* `estimateHistory`'s, never this walk's. A seed that answers before
|
|
246
|
+
* itself refuses nothing. */
|
|
247
|
+
function refuseBeforeStatement(seed, date, read) {
|
|
248
|
+
const from = answersFrom(seed);
|
|
249
|
+
if (from === null)
|
|
250
|
+
return;
|
|
251
|
+
if (isBeforeStatement(date, from))
|
|
252
|
+
throw new BeforeStatement(read, date, from);
|
|
253
|
+
}
|
|
218
254
|
/**
|
|
219
255
|
* The read side, over rows already walked.
|
|
220
256
|
*
|
|
@@ -227,15 +263,14 @@ function readerOver(frozen, seed) {
|
|
|
227
263
|
* the year its seed sits at. */
|
|
228
264
|
const startsAt = schemeYearEndDate(seed.atSchemeYearEnd);
|
|
229
265
|
/**
|
|
230
|
-
* Asked about a date BEFORE the ledger begins,
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* So a date before the seed reads the seed's own year end, and
|
|
235
|
-
* an earlier leaving date cannot read higher off the same
|
|
236
|
-
* statement than a later one.
|
|
266
|
+
* Asked about a date BEFORE the ledger begins, a walk that
|
|
267
|
+
* opens the membership answers at its beginning, where it held
|
|
268
|
+
* nothing; a statement's walk refuses, per the seed.
|
|
237
269
|
*/
|
|
238
|
-
const answerableAt = (date) =>
|
|
270
|
+
const answerableAt = (date) => {
|
|
271
|
+
refuseBeforeStatement(seed, date, STATEMENT_READS.balance);
|
|
272
|
+
return date < startsAt ? startsAt : date;
|
|
273
|
+
};
|
|
239
274
|
/** Replay the steps up to `date`. `preDrawing` reads the row
|
|
240
275
|
* carrying the retirement event at its pre-factor value. A row
|
|
241
276
|
* the member leaves in settles on the last day of service, not
|
|
@@ -259,6 +294,7 @@ function readerOver(frozen, seed) {
|
|
|
259
294
|
accruedAt: (date) => walkTo(answerableAt(date), true),
|
|
260
295
|
closingAt(schemeYearEnd) {
|
|
261
296
|
if (schemeYearEnd <= seed.atSchemeYearEnd) {
|
|
297
|
+
refuseBeforeStatement(seed, schemeYearEndDate(schemeYearEnd), STATEMENT_READS.yearClose);
|
|
262
298
|
return seed.opening;
|
|
263
299
|
}
|
|
264
300
|
const row = frozen.find((r) => r.schemeYearEnd === schemeYearEnd);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/pension/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/pension/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EACL,eAAe,EAAE,SAAS,EAAE,iBAAiB,EAAE,eAAe,GAC/D,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAC,QAAQ,EAAE,kBAAkB,EAAE,eAAe,EAAC,MAAM,aAAa,CAAC;AAO1E,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAE5C,OAAO,EACL,aAAa,EAAE,gBAAgB,EAAE,OAAO,EAAE,UAAU,GACrD,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EA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YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;QACzD,SAAS,EAAE,CAAC,IAAU,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;QAC3D,SAAS,CAAC,aAA4B;YACpC,IAAI,aAAa,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;gBAC1C,qBAAqB,CACnB,IAAI,EAAE,iBAAiB,CAAC,aAAa,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;gBACrE,OAAO,IAAI,CAAC,OAAO,CAAC;YACtB,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CACrB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,aAAa,CACzC,CAAC;YACF,SAAS,CACP,GAAG,KAAK,SAAS,EACjB,eAAe,aAAa,qBAAqB,CAClD,CAAC;YACF,OAAO,GAAG,CAAC,OAAO,CAAC;QACrB,CAAC;QACD,YAAY,EAAE,GAAG,EAAE,CACjB,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,mBAAmB,KAAK,IAAI,CAAC;KAC3D,CAAC,CAAC;AACL,CAAC"}
|
package/dist/pension/money.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export declare function moneyAt(readings: Readings, asAt: Date): ProjectionMoney
|
|
|
46
46
|
export declare function sumMoney(xs: readonly Readings[], asAt: Date): ProjectionMoney;
|
|
47
47
|
/** `a` less `b`, each ruler on its own, at `a`'s date. */
|
|
48
48
|
export declare function minusMoney(a: ProjectionMoney, b: Readings): ProjectionMoney;
|
|
49
|
+
/** A figure multiplied by a scalar, both rulers, at its own date. */
|
|
50
|
+
export declare function timesMoney(m: ProjectionMoney, by: number): ProjectionMoney;
|
|
49
51
|
/** A figure divided by a scalar, both rulers, at its own date. */
|
|
50
52
|
export declare function divideMoney(m: ProjectionMoney, by: number): ProjectionMoney;
|
|
51
53
|
export {};
|
package/dist/pension/money.js
CHANGED
|
@@ -17,6 +17,10 @@ export function sumMoney(xs, asAt) {
|
|
|
17
17
|
export function minusMoney(a, b) {
|
|
18
18
|
return moneyAt({ nominal: a.nominal - b.nominal, real: a.real - b.real }, a.asAt);
|
|
19
19
|
}
|
|
20
|
+
/** A figure multiplied by a scalar, both rulers, at its own date. */
|
|
21
|
+
export function timesMoney(m, by) {
|
|
22
|
+
return moneyAt({ nominal: m.nominal * by, real: m.real * by }, m.asAt);
|
|
23
|
+
}
|
|
20
24
|
/** A figure divided by a scalar, both rulers, at its own date. */
|
|
21
25
|
export function divideMoney(m, by) {
|
|
22
26
|
return moneyAt({ nominal: m.nominal / by, real: m.real / by }, m.asAt);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"money.js","sourceRoot":"","sources":["../../src/pension/money.ts"],"names":[],"mappings":"AAwCA;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,QAAkB,EAAE,IAAU;IACpD,OAAO,EAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAC,CAAC;AAChE,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,QAAQ,CACtB,EAAuB,EAAE,IAAU;IAEnC,OAAO,OAAO,CAAC;QACb,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9C,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;KACzC,EAAE,IAAI,CAAC,CAAC;AACX,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CACxB,CAAkB,EAAE,CAAW;IAE/B,OAAO,OAAO,CAAC,EAAC,OAAO,EAAE,CA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AI,GAAG,CAAC,CAAC,IAAI,EAAC,EACpE,CAAC,CAAC,IAAI,CAAC,CAAC;AACZ,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,UAAU,CACxB,CAAkB,EAAE,EAAU;IAE9B,OAAO,OAAO,CAAC,EAAC,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,GAAG,EAAE,EAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AACvE,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,WAAW,CACzB,CAAkB,EAAE,EAAU;IAE9B,OAAO,OAAO,CAAC,EAAC,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,GAAG,EAAE,EAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AACvE,CAAC"}
|
package/dist/pension/prices.d.ts
CHANGED
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
* in the money it was written for. Beyond the published record
|
|
37
37
|
* it is the assumption, as above.
|
|
38
38
|
*/
|
|
39
|
+
import type { SchemeYearEnd } from './scheme-year.js';
|
|
39
40
|
/** One year of the September CPI series, and where it came from. */
|
|
40
41
|
export interface CpiEntry {
|
|
41
42
|
/** Scheme year END, e.g. 2016 for the 2015/16 year. */
|
|
42
|
-
readonly schemeYearEnd:
|
|
43
|
+
readonly schemeYearEnd: SchemeYearEnd;
|
|
43
44
|
/** Percentage points. Negative is legal: September 2015 was
|
|
44
45
|
* -0.1, which is the scheme's very first uplift. */
|
|
45
46
|
readonly cpi: number;
|
|
@@ -57,7 +58,7 @@ export interface CpiEntry {
|
|
|
57
58
|
* CHOICE rather than a table and a condition — WHICH series
|
|
58
59
|
* stays the caller's question and never the rule's. A projection
|
|
59
60
|
* makes that choice exactly once, in `openingUpliftFor`. */
|
|
60
|
-
export type CpiSource = (schemeYearEnd:
|
|
61
|
+
export type CpiSource = (schemeYearEnd: SchemeYearEnd) => CpiEntry;
|
|
61
62
|
/** The CPI a projection revalues at, and the money readings
|
|
62
63
|
* that follow from it. The published record itself is
|
|
63
64
|
* `revaluation.ts`'s: a series here reads it through
|
|
@@ -110,6 +111,14 @@ export interface Prices {
|
|
|
110
111
|
/** The CPI a today's-money run assumes, as a decimal: none, so every
|
|
111
112
|
* figure is read in the money of the run date. */
|
|
112
113
|
export declare const TODAYS_MONEY_CPI = 0;
|
|
114
|
+
/**
|
|
115
|
+
* A CPI or revaluation rate in percentage points as a decimal: 3.8 points
|
|
116
|
+
* is 0.038. A `CpiEntry`, an Order and every rate a ledger row carries are
|
|
117
|
+
* in points, as the Orders print them; an assumption, a growth factor and
|
|
118
|
+
* paye-calc's `cpi` are decimals. Every crossing of a CPI-derived rate
|
|
119
|
+
* between the two goes through here or {@link decimalToPoints}.
|
|
120
|
+
*/
|
|
121
|
+
export declare function pointsToDecimal(points: number): number;
|
|
113
122
|
/**
|
|
114
123
|
* How much more a pound of `asAt` money is than a pound of
|
|
115
124
|
* `from` money, under the caller's assumption.
|
package/dist/pension/prices.js
CHANGED
|
@@ -38,9 +38,27 @@
|
|
|
38
38
|
*/
|
|
39
39
|
import { invariant } from '../errors.js';
|
|
40
40
|
import { appliedOnFor, IN_SERVICE_REVALUATION, revaluationFor, } from '../revaluation.js';
|
|
41
|
+
import { schemeYearEnd } from './scheme-year.js';
|
|
41
42
|
/** The CPI a today's-money run assumes, as a decimal: none, so every
|
|
42
43
|
* figure is read in the money of the run date. */
|
|
43
44
|
export const TODAYS_MONEY_CPI = 0;
|
|
45
|
+
/** Percentage points in one unit of a decimal rate. */
|
|
46
|
+
const POINTS_PER_UNIT = 100;
|
|
47
|
+
/**
|
|
48
|
+
* A CPI or revaluation rate in percentage points as a decimal: 3.8 points
|
|
49
|
+
* is 0.038. A `CpiEntry`, an Order and every rate a ledger row carries are
|
|
50
|
+
* in points, as the Orders print them; an assumption, a growth factor and
|
|
51
|
+
* paye-calc's `cpi` are decimals. Every crossing of a CPI-derived rate
|
|
52
|
+
* between the two goes through here or {@link decimalToPoints}.
|
|
53
|
+
*/
|
|
54
|
+
export function pointsToDecimal(points) {
|
|
55
|
+
return points / POINTS_PER_UNIT;
|
|
56
|
+
}
|
|
57
|
+
/** A decimal rate in percentage points: 0.02 is 2 points. The inverse of
|
|
58
|
+
* {@link pointsToDecimal}. */
|
|
59
|
+
function decimalToPoints(decimal) {
|
|
60
|
+
return decimal * POINTS_PER_UNIT;
|
|
61
|
+
}
|
|
44
62
|
/**
|
|
45
63
|
* How much more a pound of `asAt` money is than a pound of
|
|
46
64
|
* `from` money, under the caller's assumption.
|
|
@@ -74,7 +92,9 @@ export function inflationFactor(asAt, from, assumedCpi) {
|
|
|
74
92
|
function aprilsBetween(from, to) {
|
|
75
93
|
let count = 0;
|
|
76
94
|
for (let year = from.getFullYear(); year <= to.getFullYear(); year++) {
|
|
77
|
-
|
|
95
|
+
// The Order labelled by the scheme year ending in `year` is applied
|
|
96
|
+
// in that year's April.
|
|
97
|
+
const applied = appliedOnFor(schemeYearEnd(year));
|
|
78
98
|
if (applied > from && applied <= to)
|
|
79
99
|
count += 1;
|
|
80
100
|
}
|
|
@@ -91,7 +111,7 @@ function aprilsBetween(from, to) {
|
|
|
91
111
|
* date the module needs.
|
|
92
112
|
*/
|
|
93
113
|
export function createPrices(assumedCpi, asOf) {
|
|
94
|
-
const assumedPct = assumedCpi
|
|
114
|
+
const assumedPct = decimalToPoints(assumedCpi);
|
|
95
115
|
const valueAt = (amount, from, to) => amount * inflationFactor(to, from, assumedCpi);
|
|
96
116
|
return {
|
|
97
117
|
/* Frozen at the mint. A `CpiEntry` is the provenance a
|
|
@@ -133,7 +153,7 @@ export function createPrices(assumedCpi, asOf) {
|
|
|
133
153
|
*/
|
|
134
154
|
export function createPublishedPrices(assumedCpi, asOf) {
|
|
135
155
|
const assumed = createPrices(assumedCpi, asOf);
|
|
136
|
-
const cpiFor = (
|
|
156
|
+
const cpiFor = (year) => publishedCpiFor(year, decimalToPoints(assumedCpi));
|
|
137
157
|
return {
|
|
138
158
|
...assumed,
|
|
139
159
|
cpiFor,
|
|
@@ -146,25 +166,25 @@ export function createPublishedPrices(assumedCpi, asOf) {
|
|
|
146
166
|
* record ends. A year before the scheme's first Order, or a gap
|
|
147
167
|
* inside the record, has no honest answer and is refused.
|
|
148
168
|
*/
|
|
149
|
-
function publishedCpiFor(
|
|
150
|
-
const order = revaluationFor(
|
|
169
|
+
function publishedCpiFor(year, assumedPct) {
|
|
170
|
+
const order = revaluationFor(year);
|
|
151
171
|
if (order !== null) {
|
|
152
172
|
return Object.freeze({
|
|
153
|
-
schemeYearEnd, cpi: order.septemberCpiPct, si: order.si,
|
|
173
|
+
schemeYearEnd: year, cpi: order.septemberCpiPct, si: order.si,
|
|
154
174
|
});
|
|
155
175
|
}
|
|
156
|
-
const first = IN_SERVICE_REVALUATION
|
|
176
|
+
const first = IN_SERVICE_REVALUATION.at(0);
|
|
157
177
|
const last = IN_SERVICE_REVALUATION.at(-1);
|
|
158
178
|
invariant(first !== undefined && last !== undefined, 'the Revaluation Order table is empty');
|
|
159
|
-
if (
|
|
160
|
-
throw new Error(`No Revaluation Order for ${
|
|
179
|
+
if (year < first.yearEnd) {
|
|
180
|
+
throw new Error(`No Revaluation Order for ${year}: `
|
|
161
181
|
+ `the scheme's first is ${first.si}, for ${first.yearEnd}`);
|
|
162
182
|
}
|
|
163
|
-
if (
|
|
183
|
+
if (year <= last.yearEnd) {
|
|
164
184
|
throw new Error(`No Revaluation Order recorded for `
|
|
165
|
-
+ `${
|
|
185
|
+
+ `${year}, inside the published record`);
|
|
166
186
|
}
|
|
167
|
-
return Object.freeze({ schemeYearEnd, cpi: assumedPct, si: null });
|
|
187
|
+
return Object.freeze({ schemeYearEnd: year, cpi: assumedPct, si: null });
|
|
168
188
|
}
|
|
169
189
|
/**
|
|
170
190
|
* How much more a pound of `to` money is than a pound of `from`
|
|
@@ -176,9 +196,10 @@ function pricesBetween(from, to, cpiFor) {
|
|
|
176
196
|
const [lo, hi] = ahead ? [from, to] : [to, from];
|
|
177
197
|
let factor = 1;
|
|
178
198
|
for (let year = lo.getFullYear(); year <= hi.getFullYear(); year++) {
|
|
179
|
-
const
|
|
199
|
+
const labelled = schemeYearEnd(year);
|
|
200
|
+
const applied = appliedOnFor(labelled);
|
|
180
201
|
if (applied > lo && applied <= hi) {
|
|
181
|
-
factor *= 1 + cpiFor(
|
|
202
|
+
factor *= 1 + pointsToDecimal(cpiFor(labelled).cpi);
|
|
182
203
|
}
|
|
183
204
|
}
|
|
184
205
|
return ahead ? factor : 1 / factor;
|