@fintekkers/ledger-models 1.1.6 → 1.1.8
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/node/wrappers/models/security/BondSecurity.d.ts +13 -0
- package/node/wrappers/models/security/BondSecurity.js +33 -0
- package/node/wrappers/models/security/BondSecurity.js.map +1 -1
- package/node/wrappers/models/security/BondSecurity.test.js +21 -0
- package/node/wrappers/models/security/BondSecurity.test.js.map +1 -1
- package/node/wrappers/models/security/BondSecurity.test.ts +24 -1
- package/node/wrappers/models/security/BondSecurity.ts +35 -1
- package/node/wrappers/models/security/Issuance.d.ts +9 -2
- package/node/wrappers/models/security/Issuance.js +15 -2
- package/node/wrappers/models/security/Issuance.js.map +1 -1
- package/node/wrappers/models/security/Issuance.ts +16 -2
- package/node/wrappers/models/security/TreasuryFrnFixings.d.ts +21 -0
- package/node/wrappers/models/security/TreasuryFrnFixings.js +85 -0
- package/node/wrappers/models/security/TreasuryFrnFixings.js.map +1 -0
- package/node/wrappers/models/security/TreasuryFrnFixings.test.d.ts +1 -0
- package/node/wrappers/models/security/TreasuryFrnFixings.test.js +207 -0
- package/node/wrappers/models/security/TreasuryFrnFixings.test.js.map +1 -0
- package/node/wrappers/models/security/TreasuryFrnFixings.test.ts +197 -0
- package/node/wrappers/models/security/TreasuryFrnFixings.ts +79 -0
- package/node/wrappers/models/utils/date.d.ts +16 -1
- package/node/wrappers/models/utils/date.js +29 -1
- package/node/wrappers/models/utils/date.js.map +1 -1
- package/node/wrappers/models/utils/date.ts +29 -1
- package/node/wrappers/util/object-types.test.js +1 -1
- package/node/wrappers/util/object-types.test.js.map +1 -1
- package/node/wrappers/util/object-types.test.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
// Treasury FRN 13-week fixing helpers (LM-386, part 3 of LM-382): the
|
|
30
|
+
// per-issuance tenor, standardBillTerm and select, against the shared fixture
|
|
31
|
+
// test-fixtures/treasury-frn-fixings.json that Java and Python also pass,
|
|
32
|
+
// plus the skip and tie-break rules.
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
|
+
const path = __importStar(require("path"));
|
|
35
|
+
const BondSecurity_1 = __importDefault(require("./BondSecurity"));
|
|
36
|
+
const TreasuryFrnFixings_1 = require("./TreasuryFrnFixings");
|
|
37
|
+
const term_1 = require("./term");
|
|
38
|
+
const security_pb_1 = require("../../../fintekkers/models/security/security_pb");
|
|
39
|
+
const product_type_pb_1 = require("../../../fintekkers/models/security/product_type_pb");
|
|
40
|
+
const issuance_pb_1 = require("../../../fintekkers/models/security/bond/issuance_pb");
|
|
41
|
+
const index_type_pb_1 = require("../../../fintekkers/models/security/index/index_type_pb");
|
|
42
|
+
const tenor_type_pb_1 = require("../../../fintekkers/models/security/tenor_type_pb");
|
|
43
|
+
const local_date_pb_1 = require("../../../fintekkers/models/util/local_date_pb");
|
|
44
|
+
const decimal_value_pb_1 = require("../../../fintekkers/models/util/decimal_value_pb");
|
|
45
|
+
const product_inputs_pb_1 = require("../../../fintekkers/requests/valuation/product_inputs_pb");
|
|
46
|
+
const decimal_1 = require("../utils/decimal");
|
|
47
|
+
const date_1 = require("../utils/date");
|
|
48
|
+
const fixturePath = path.resolve(__dirname, '../../../../../test-fixtures/treasury-frn-fixings.json');
|
|
49
|
+
const fixture = JSON.parse(fs.readFileSync(fixturePath, 'utf8'));
|
|
50
|
+
function dateProto(s) {
|
|
51
|
+
const [y, m, d] = s.split('-').map(Number);
|
|
52
|
+
return new local_date_pb_1.LocalDateProto().setYear(y).setMonth(m).setDay(d);
|
|
53
|
+
}
|
|
54
|
+
/** A local-midnight Date, as localDateProtoToDate builds one. */
|
|
55
|
+
function localDate(s) {
|
|
56
|
+
const [y, m, d] = s.split('-').map(Number);
|
|
57
|
+
return new Date(y, m - 1, d);
|
|
58
|
+
}
|
|
59
|
+
function decimal(s) {
|
|
60
|
+
return (0, decimal_1.encodeDecimal)((0, decimal_1.parseDecimalString)(s));
|
|
61
|
+
}
|
|
62
|
+
function canonical(p) {
|
|
63
|
+
if (!p)
|
|
64
|
+
throw new Error('no decimal');
|
|
65
|
+
return (0, decimal_1.toCanonicalString)((0, decimal_1.decodeDecimal)(p));
|
|
66
|
+
}
|
|
67
|
+
/** `P<y>Y<m>M<d>D`, any part optional, as the fixture writes periods. */
|
|
68
|
+
function parsePeriod(s) {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
const m = /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?$/.exec(s);
|
|
71
|
+
if (!m)
|
|
72
|
+
throw new Error(`bad period ${s}`);
|
|
73
|
+
return { years: Number((_a = m[1]) !== null && _a !== void 0 ? _a : 0), months: Number((_b = m[2]) !== null && _b !== void 0 ? _b : 0), days: Number((_c = m[3]) !== null && _c !== void 0 ? _c : 0) };
|
|
74
|
+
}
|
|
75
|
+
function issuance(auctionDate, issueDate, rate) {
|
|
76
|
+
const p = new issuance_pb_1.IssuanceProto();
|
|
77
|
+
if (auctionDate)
|
|
78
|
+
p.setAuctionDate(dateProto(auctionDate));
|
|
79
|
+
if (issueDate)
|
|
80
|
+
p.setAuctionIssueDate(dateProto(issueDate));
|
|
81
|
+
if (rate)
|
|
82
|
+
p.setHighDiscountRate(rate);
|
|
83
|
+
return p;
|
|
84
|
+
}
|
|
85
|
+
function bill(maturity, issuances) {
|
|
86
|
+
const bond = new security_pb_1.BondDetailsProto().setMaturityDate(dateProto(maturity)).setIssuanceInfoList(issuances);
|
|
87
|
+
return new BondSecurity_1.default(new security_pb_1.SecurityProto().setProductType(product_type_pb_1.ProductTypeProto.TBILL).setBondDetails(bond));
|
|
88
|
+
}
|
|
89
|
+
function fixtureBills(block) {
|
|
90
|
+
return block.bills.map(b => bill(b.maturity_date, b.issuances.map(i => {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
return issuance((_a = i.auction_date) !== null && _a !== void 0 ? _a : null, (_b = i.auction_issue_date) !== null && _b !== void 0 ? _b : null, i.high_discount_rate ? decimal(i.high_discount_rate) : null);
|
|
93
|
+
})));
|
|
94
|
+
}
|
|
95
|
+
function checkIssuanceTenors() {
|
|
96
|
+
for (const row of fixture.issuance_tenors) {
|
|
97
|
+
const b = bill(row.maturity_date, [issuance(null, row.auction_issue_date, null)]);
|
|
98
|
+
const tenor = b.getIssuanceTenor(b.getIssuances()[0]);
|
|
99
|
+
const period = tenor.getTenor();
|
|
100
|
+
expect([row.case, period]).toEqual([row.case, parsePeriod(row.period)]);
|
|
101
|
+
const anchor = localDate(row.auction_issue_date);
|
|
102
|
+
const end = (0, date_1.plusDays)((0, date_1.plusMonthsClamped)(anchor, 12 * period.years + period.months), period.days);
|
|
103
|
+
expect([row.case, (0, date_1.daysBetween)(anchor, end)]).toEqual([row.case, row.days]);
|
|
104
|
+
expect([row.case, (0, TreasuryFrnFixings_1.standardBillTerm)(tenor, anchor)]).toEqual([row.case, row.standard_bill_term_weeks]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function checkSelectBlock(block) {
|
|
108
|
+
const bills = fixtureBills(block);
|
|
109
|
+
for (const c of block.cases) {
|
|
110
|
+
const got = (0, TreasuryFrnFixings_1.select)(bills, localDate(c.date));
|
|
111
|
+
if (c.fixing === null) {
|
|
112
|
+
expect([c.case, got]).toEqual([c.case, null]);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
expect(c.fixing.index).toBe('T_BILL_13_WEEK');
|
|
116
|
+
const want = new product_inputs_pb_1.ReferenceRateFixingProto()
|
|
117
|
+
.setIndex(index_type_pb_1.IndexTypeProto.T_BILL_13_WEEK)
|
|
118
|
+
.setFixingDate(dateProto(c.fixing.fixing_date))
|
|
119
|
+
.setRate(decimal(c.fixing.rate))
|
|
120
|
+
.setBillMaturityDate(dateProto(c.fixing.bill_maturity_date));
|
|
121
|
+
expect([c.case, got === null || got === void 0 ? void 0 : got.toObject()]).toEqual([c.case, want.toObject()]);
|
|
122
|
+
// The published rate comes back unchanged, scale included.
|
|
123
|
+
expect([c.case, canonical(got === null || got === void 0 ? void 0 : got.getRate())]).toEqual([c.case, c.fixing.rate]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// ---------- metric line 1 ----------
|
|
127
|
+
test('fixture issuance_tenors: period, days and standard bill term', () => {
|
|
128
|
+
checkIssuanceTenors();
|
|
129
|
+
});
|
|
130
|
+
test('reopened bill: per-issuance tenors are 26W (original) and 13W (reopening)', () => {
|
|
131
|
+
const b = bill('2026-10-22', [
|
|
132
|
+
issuance('2026-04-20', '2026-04-23', null),
|
|
133
|
+
issuance('2026-07-20', '2026-07-23', null),
|
|
134
|
+
]);
|
|
135
|
+
const [original, reopening] = b.getIssuances();
|
|
136
|
+
const originalTenor = b.getIssuanceTenor(original);
|
|
137
|
+
const reopeningTenor = b.getIssuanceTenor(reopening);
|
|
138
|
+
expect(originalTenor.getTenor()).toEqual(parsePeriod('P5M29D'));
|
|
139
|
+
expect(reopeningTenor.getTenor()).toEqual(parsePeriod('P2M29D'));
|
|
140
|
+
expect((0, TreasuryFrnFixings_1.standardBillTerm)(originalTenor, original.getIssueDate())).toBe(26);
|
|
141
|
+
expect((0, TreasuryFrnFixings_1.standardBillTerm)(reopeningTenor, reopening.getIssueDate())).toBe(13);
|
|
142
|
+
});
|
|
143
|
+
// ---------- metric line 2 ----------
|
|
144
|
+
test('fixture standard_bill_terms on both anchors', () => {
|
|
145
|
+
for (const row of fixture.standard_bill_terms) {
|
|
146
|
+
const tenor = new term_1.Tenor(tenor_type_pb_1.TenorTypeProto.TERM, parsePeriod(row.period));
|
|
147
|
+
for (const anchor of row.anchors) {
|
|
148
|
+
expect([row.case, anchor, (0, TreasuryFrnFixings_1.standardBillTerm)(tenor, localDate(anchor))])
|
|
149
|
+
.toEqual([row.case, anchor, row.standard_bill_term_weeks]);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
// ---------- metric line 3 ----------
|
|
154
|
+
test('fixture select', () => {
|
|
155
|
+
checkSelectBlock(fixture.select);
|
|
156
|
+
});
|
|
157
|
+
test('fixture select_skips', () => {
|
|
158
|
+
checkSelectBlock(fixture.select_skips);
|
|
159
|
+
});
|
|
160
|
+
describe('fixture cases off UTC', () => {
|
|
161
|
+
const originalTz = process.env.TZ;
|
|
162
|
+
afterEach(() => {
|
|
163
|
+
if (originalTz === undefined)
|
|
164
|
+
delete process.env.TZ;
|
|
165
|
+
else
|
|
166
|
+
process.env.TZ = originalTz;
|
|
167
|
+
});
|
|
168
|
+
for (const tz of ['America/New_York', 'Pacific/Auckland']) {
|
|
169
|
+
test(`issuance_tenors and select give the same results in ${tz}`, () => {
|
|
170
|
+
process.env.TZ = tz;
|
|
171
|
+
checkIssuanceTenors();
|
|
172
|
+
checkSelectBlock(fixture.select);
|
|
173
|
+
checkSelectBlock(fixture.select_skips);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
// ---------- metric line 4 ----------
|
|
178
|
+
test('select skips an issuance missing a field or with an empty rate', () => {
|
|
179
|
+
var _a, _b;
|
|
180
|
+
const onDate = '2026-07-20';
|
|
181
|
+
const bills = [
|
|
182
|
+
bill('2026-10-22', [issuance(null, '2026-07-23', decimal('4.900'))]),
|
|
183
|
+
bill('2026-10-22', [issuance(onDate, null, decimal('4.800'))]),
|
|
184
|
+
bill('2026-10-22', [issuance(onDate, '2026-07-23', null)]),
|
|
185
|
+
bill('2026-10-22', [issuance(onDate, '2026-07-23', new decimal_value_pb_1.DecimalValueProto())]),
|
|
186
|
+
bill('2026-10-15', [issuance('2026-07-13', '2026-07-16', decimal('4.190'))]),
|
|
187
|
+
];
|
|
188
|
+
const got = (0, TreasuryFrnFixings_1.select)(bills, localDate(onDate));
|
|
189
|
+
expect(canonical(got === null || got === void 0 ? void 0 : got.getRate())).toBe('4.190');
|
|
190
|
+
expect((_a = got === null || got === void 0 ? void 0 : got.getFixingDate()) === null || _a === void 0 ? void 0 : _a.toObject()).toEqual(dateProto('2026-07-13').toObject());
|
|
191
|
+
expect((_b = got === null || got === void 0 ? void 0 : got.getBillMaturityDate()) === null || _b === void 0 ? void 0 : _b.toObject()).toEqual(dateProto('2026-10-15').toObject());
|
|
192
|
+
});
|
|
193
|
+
test('select: a tie on auction date goes to the first in input order', () => {
|
|
194
|
+
var _a, _b;
|
|
195
|
+
// Same auction date; the first has the smaller rate and earlier maturity,
|
|
196
|
+
// so a "max rate" or "max maturity" rule would pick the other one.
|
|
197
|
+
const first = () => bill('2026-10-21', [issuance('2026-07-20', '2026-07-22', decimal('4.100'))]);
|
|
198
|
+
const second = () => bill('2026-10-22', [issuance('2026-07-20', '2026-07-23', decimal('4.215'))]);
|
|
199
|
+
const date = localDate('2026-07-20');
|
|
200
|
+
let got = (0, TreasuryFrnFixings_1.select)([first(), second()], date);
|
|
201
|
+
expect(canonical(got === null || got === void 0 ? void 0 : got.getRate())).toBe('4.100');
|
|
202
|
+
expect((_a = got === null || got === void 0 ? void 0 : got.getBillMaturityDate()) === null || _a === void 0 ? void 0 : _a.toObject()).toEqual(dateProto('2026-10-21').toObject());
|
|
203
|
+
got = (0, TreasuryFrnFixings_1.select)([second(), first()], date);
|
|
204
|
+
expect(canonical(got === null || got === void 0 ? void 0 : got.getRate())).toBe('4.215');
|
|
205
|
+
expect((_b = got === null || got === void 0 ? void 0 : got.getBillMaturityDate()) === null || _b === void 0 ? void 0 : _b.toObject()).toEqual(dateProto('2026-10-22').toObject());
|
|
206
|
+
});
|
|
207
|
+
//# sourceMappingURL=TreasuryFrnFixings.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreasuryFrnFixings.test.js","sourceRoot":"","sources":["TreasuryFrnFixings.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAAsE;AACtE,8EAA8E;AAC9E,0EAA0E;AAC1E,qCAAqC;AACrC,uCAAyB;AACzB,2CAA6B;AAC7B,kEAA0C;AAC1C,6DAAgE;AAChE,iCAAuC;AACvC,iFAAkG;AAClG,yFAAuF;AACvF,sFAAqF;AACrF,2FAAyF;AACzF,qFAAmF;AACnF,iFAA+E;AAC/E,uFAAqF;AACrF,gGAAoG;AACpG,8CAAuG;AACvG,wCAAyE;AAEzE,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,wDAAwD,CAAC,CAAC;AACtG,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC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E,IAAI,CAAC,CAAC;IACxC,MAAM,CAAC,SAAS,CAAC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,CAAC,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,mBAAmB,EAAE,0CAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC7F,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Treasury FRN 13-week fixing helpers (LM-386, part 3 of LM-382): the
|
|
2
|
+
// per-issuance tenor, standardBillTerm and select, against the shared fixture
|
|
3
|
+
// test-fixtures/treasury-frn-fixings.json that Java and Python also pass,
|
|
4
|
+
// plus the skip and tie-break rules.
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import BondSecurity from './BondSecurity';
|
|
8
|
+
import { standardBillTerm, select } from './TreasuryFrnFixings';
|
|
9
|
+
import { Tenor, Period } from './term';
|
|
10
|
+
import { SecurityProto, BondDetailsProto } from '../../../fintekkers/models/security/security_pb';
|
|
11
|
+
import { ProductTypeProto } from '../../../fintekkers/models/security/product_type_pb';
|
|
12
|
+
import { IssuanceProto } from '../../../fintekkers/models/security/bond/issuance_pb';
|
|
13
|
+
import { IndexTypeProto } from '../../../fintekkers/models/security/index/index_type_pb';
|
|
14
|
+
import { TenorTypeProto } from '../../../fintekkers/models/security/tenor_type_pb';
|
|
15
|
+
import { LocalDateProto } from '../../../fintekkers/models/util/local_date_pb';
|
|
16
|
+
import { DecimalValueProto } from '../../../fintekkers/models/util/decimal_value_pb';
|
|
17
|
+
import { ReferenceRateFixingProto } from '../../../fintekkers/requests/valuation/product_inputs_pb';
|
|
18
|
+
import { decodeDecimal, encodeDecimal, parseDecimalString, toCanonicalString } from '../utils/decimal';
|
|
19
|
+
import { daysBetween, plusDays, plusMonthsClamped } from '../utils/date';
|
|
20
|
+
|
|
21
|
+
const fixturePath = path.resolve(__dirname, '../../../../../test-fixtures/treasury-frn-fixings.json');
|
|
22
|
+
const fixture = JSON.parse(fs.readFileSync(fixturePath, 'utf8'));
|
|
23
|
+
|
|
24
|
+
interface FixtureIssuance { auction_date?: string; auction_issue_date?: string; high_discount_rate?: string }
|
|
25
|
+
interface FixtureBill { maturity_date: string; issuances: FixtureIssuance[] }
|
|
26
|
+
interface FixtureFixing { index: string; rate: string; fixing_date: string; bill_maturity_date: string }
|
|
27
|
+
interface FixtureSelectBlock { bills: FixtureBill[]; cases: { case: string; date: string; fixing: FixtureFixing | null }[] }
|
|
28
|
+
|
|
29
|
+
function dateProto(s: string): LocalDateProto {
|
|
30
|
+
const [y, m, d] = s.split('-').map(Number);
|
|
31
|
+
return new LocalDateProto().setYear(y).setMonth(m).setDay(d);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A local-midnight Date, as localDateProtoToDate builds one. */
|
|
35
|
+
function localDate(s: string): Date {
|
|
36
|
+
const [y, m, d] = s.split('-').map(Number);
|
|
37
|
+
return new Date(y, m - 1, d);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function decimal(s: string): DecimalValueProto {
|
|
41
|
+
return encodeDecimal(parseDecimalString(s));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function canonical(p: DecimalValueProto | undefined): string {
|
|
45
|
+
if (!p) throw new Error('no decimal');
|
|
46
|
+
return toCanonicalString(decodeDecimal(p));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** `P<y>Y<m>M<d>D`, any part optional, as the fixture writes periods. */
|
|
50
|
+
function parsePeriod(s: string): Period {
|
|
51
|
+
const m = /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?$/.exec(s);
|
|
52
|
+
if (!m) throw new Error(`bad period ${s}`);
|
|
53
|
+
return { years: Number(m[1] ?? 0), months: Number(m[2] ?? 0), days: Number(m[3] ?? 0) };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function issuance(auctionDate: string | null, issueDate: string | null, rate: DecimalValueProto | null): IssuanceProto {
|
|
57
|
+
const p = new IssuanceProto();
|
|
58
|
+
if (auctionDate) p.setAuctionDate(dateProto(auctionDate));
|
|
59
|
+
if (issueDate) p.setAuctionIssueDate(dateProto(issueDate));
|
|
60
|
+
if (rate) p.setHighDiscountRate(rate);
|
|
61
|
+
return p;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function bill(maturity: string, issuances: IssuanceProto[]): BondSecurity {
|
|
65
|
+
const bond = new BondDetailsProto().setMaturityDate(dateProto(maturity)).setIssuanceInfoList(issuances);
|
|
66
|
+
return new BondSecurity(new SecurityProto().setProductType(ProductTypeProto.TBILL).setBondDetails(bond));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function fixtureBills(block: FixtureSelectBlock): BondSecurity[] {
|
|
70
|
+
return block.bills.map(b => bill(b.maturity_date, b.issuances.map(i => issuance(
|
|
71
|
+
i.auction_date ?? null, i.auction_issue_date ?? null, i.high_discount_rate ? decimal(i.high_discount_rate) : null))));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function checkIssuanceTenors(): void {
|
|
75
|
+
for (const row of fixture.issuance_tenors) {
|
|
76
|
+
const b = bill(row.maturity_date, [issuance(null, row.auction_issue_date, null)]);
|
|
77
|
+
const tenor = b.getIssuanceTenor(b.getIssuances()[0]);
|
|
78
|
+
const period = tenor.getTenor();
|
|
79
|
+
expect([row.case, period]).toEqual([row.case, parsePeriod(row.period)]);
|
|
80
|
+
const anchor = localDate(row.auction_issue_date);
|
|
81
|
+
const end = plusDays(plusMonthsClamped(anchor, 12 * period!.years + period!.months), period!.days);
|
|
82
|
+
expect([row.case, daysBetween(anchor, end)]).toEqual([row.case, row.days]);
|
|
83
|
+
expect([row.case, standardBillTerm(tenor, anchor)]).toEqual([row.case, row.standard_bill_term_weeks]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function checkSelectBlock(block: FixtureSelectBlock): void {
|
|
88
|
+
const bills = fixtureBills(block);
|
|
89
|
+
for (const c of block.cases) {
|
|
90
|
+
const got = select(bills, localDate(c.date));
|
|
91
|
+
if (c.fixing === null) {
|
|
92
|
+
expect([c.case, got]).toEqual([c.case, null]);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
expect(c.fixing.index).toBe('T_BILL_13_WEEK');
|
|
96
|
+
const want = new ReferenceRateFixingProto()
|
|
97
|
+
.setIndex(IndexTypeProto.T_BILL_13_WEEK)
|
|
98
|
+
.setFixingDate(dateProto(c.fixing.fixing_date))
|
|
99
|
+
.setRate(decimal(c.fixing.rate))
|
|
100
|
+
.setBillMaturityDate(dateProto(c.fixing.bill_maturity_date));
|
|
101
|
+
expect([c.case, got?.toObject()]).toEqual([c.case, want.toObject()]);
|
|
102
|
+
// The published rate comes back unchanged, scale included.
|
|
103
|
+
expect([c.case, canonical(got?.getRate())]).toEqual([c.case, c.fixing.rate]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ---------- metric line 1 ----------
|
|
108
|
+
|
|
109
|
+
test('fixture issuance_tenors: period, days and standard bill term', () => {
|
|
110
|
+
checkIssuanceTenors();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('reopened bill: per-issuance tenors are 26W (original) and 13W (reopening)', () => {
|
|
114
|
+
const b = bill('2026-10-22', [
|
|
115
|
+
issuance('2026-04-20', '2026-04-23', null),
|
|
116
|
+
issuance('2026-07-20', '2026-07-23', null),
|
|
117
|
+
]);
|
|
118
|
+
const [original, reopening] = b.getIssuances();
|
|
119
|
+
const originalTenor = b.getIssuanceTenor(original);
|
|
120
|
+
const reopeningTenor = b.getIssuanceTenor(reopening);
|
|
121
|
+
expect(originalTenor.getTenor()).toEqual(parsePeriod('P5M29D'));
|
|
122
|
+
expect(reopeningTenor.getTenor()).toEqual(parsePeriod('P2M29D'));
|
|
123
|
+
expect(standardBillTerm(originalTenor, original.getIssueDate())).toBe(26);
|
|
124
|
+
expect(standardBillTerm(reopeningTenor, reopening.getIssueDate())).toBe(13);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// ---------- metric line 2 ----------
|
|
128
|
+
|
|
129
|
+
test('fixture standard_bill_terms on both anchors', () => {
|
|
130
|
+
for (const row of fixture.standard_bill_terms) {
|
|
131
|
+
const tenor = new Tenor(TenorTypeProto.TERM, parsePeriod(row.period));
|
|
132
|
+
for (const anchor of row.anchors) {
|
|
133
|
+
expect([row.case, anchor, standardBillTerm(tenor, localDate(anchor))])
|
|
134
|
+
.toEqual([row.case, anchor, row.standard_bill_term_weeks]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// ---------- metric line 3 ----------
|
|
140
|
+
|
|
141
|
+
test('fixture select', () => {
|
|
142
|
+
checkSelectBlock(fixture.select);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('fixture select_skips', () => {
|
|
146
|
+
checkSelectBlock(fixture.select_skips);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('fixture cases off UTC', () => {
|
|
150
|
+
const originalTz = process.env.TZ;
|
|
151
|
+
afterEach(() => {
|
|
152
|
+
if (originalTz === undefined) delete process.env.TZ;
|
|
153
|
+
else process.env.TZ = originalTz;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
for (const tz of ['America/New_York', 'Pacific/Auckland']) {
|
|
157
|
+
test(`issuance_tenors and select give the same results in ${tz}`, () => {
|
|
158
|
+
process.env.TZ = tz;
|
|
159
|
+
checkIssuanceTenors();
|
|
160
|
+
checkSelectBlock(fixture.select);
|
|
161
|
+
checkSelectBlock(fixture.select_skips);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// ---------- metric line 4 ----------
|
|
167
|
+
|
|
168
|
+
test('select skips an issuance missing a field or with an empty rate', () => {
|
|
169
|
+
const onDate = '2026-07-20';
|
|
170
|
+
const bills = [
|
|
171
|
+
bill('2026-10-22', [issuance(null, '2026-07-23', decimal('4.900'))]),
|
|
172
|
+
bill('2026-10-22', [issuance(onDate, null, decimal('4.800'))]),
|
|
173
|
+
bill('2026-10-22', [issuance(onDate, '2026-07-23', null)]),
|
|
174
|
+
bill('2026-10-22', [issuance(onDate, '2026-07-23', new DecimalValueProto())]),
|
|
175
|
+
bill('2026-10-15', [issuance('2026-07-13', '2026-07-16', decimal('4.190'))]),
|
|
176
|
+
];
|
|
177
|
+
const got = select(bills, localDate(onDate));
|
|
178
|
+
expect(canonical(got?.getRate())).toBe('4.190');
|
|
179
|
+
expect(got?.getFixingDate()?.toObject()).toEqual(dateProto('2026-07-13').toObject());
|
|
180
|
+
expect(got?.getBillMaturityDate()?.toObject()).toEqual(dateProto('2026-10-15').toObject());
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('select: a tie on auction date goes to the first in input order', () => {
|
|
184
|
+
// Same auction date; the first has the smaller rate and earlier maturity,
|
|
185
|
+
// so a "max rate" or "max maturity" rule would pick the other one.
|
|
186
|
+
const first = () => bill('2026-10-21', [issuance('2026-07-20', '2026-07-22', decimal('4.100'))]);
|
|
187
|
+
const second = () => bill('2026-10-22', [issuance('2026-07-20', '2026-07-23', decimal('4.215'))]);
|
|
188
|
+
const date = localDate('2026-07-20');
|
|
189
|
+
|
|
190
|
+
let got = select([first(), second()], date);
|
|
191
|
+
expect(canonical(got?.getRate())).toBe('4.100');
|
|
192
|
+
expect(got?.getBillMaturityDate()?.toObject()).toEqual(dateProto('2026-10-21').toObject());
|
|
193
|
+
|
|
194
|
+
got = select([second(), first()], date);
|
|
195
|
+
expect(canonical(got?.getRate())).toBe('4.215');
|
|
196
|
+
expect(got?.getBillMaturityDate()?.toObject()).toEqual(dateProto('2026-10-22').toObject());
|
|
197
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import BondSecurity from './BondSecurity';
|
|
2
|
+
import Issuance from './Issuance';
|
|
3
|
+
import { Tenor } from './term';
|
|
4
|
+
import { TenorTypeProto } from '../../../fintekkers/models/security/tenor_type_pb';
|
|
5
|
+
import { IndexTypeProto } from '../../../fintekkers/models/security/index/index_type_pb';
|
|
6
|
+
import { ReferenceRateFixingProto } from '../../../fintekkers/requests/valuation/product_inputs_pb';
|
|
7
|
+
import { dateToLocalDateProto, daysBetween, plusDays, plusMonthsClamped } from '../utils/date';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Picks a Treasury FRN's 13-week bill fixing from Treasury bill auctions.
|
|
11
|
+
* The same helpers as Java's `TreasuryFrnFixings`, Python's
|
|
12
|
+
* `treasury_frn_fixings` and Rust's `treasury_frn_fixings`; all are tested
|
|
13
|
+
* against `test-fixtures/treasury-frn-fixings.json`.
|
|
14
|
+
* See `docs/adr/frn_reference_rate_fixings.md` (LM-382, LM-385, LM-386).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Treasury's standard bill terms, in weeks. */
|
|
18
|
+
const STANDARD_BILL_WEEKS = [4, 6, 8, 13, 17, 26, 52];
|
|
19
|
+
|
|
20
|
+
/** A tenor snaps to a standard term when its day count is within this many days of it. */
|
|
21
|
+
const TOLERANCE_DAYS = 3;
|
|
22
|
+
|
|
23
|
+
const THIRTEEN_WEEKS = 13;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The standard bill term, in weeks, that `tenor` is within 3 days of: 4, 6,
|
|
27
|
+
* 8, 13, 17, 26 or 52. Days are counted from `anchor` to `anchor + tenor`.
|
|
28
|
+
* Null when no term is that close, or when the tenor is null, not a TERM, or
|
|
29
|
+
* the anchor is null.
|
|
30
|
+
*/
|
|
31
|
+
export function standardBillTerm(tenor: Tenor | null, anchor: Date | null): number | null {
|
|
32
|
+
if (!tenor || !anchor || tenor.getType() !== TenorTypeProto.TERM) return null;
|
|
33
|
+
const period = tenor.getTenor();
|
|
34
|
+
if (!period) return null;
|
|
35
|
+
const end = plusDays(plusMonthsClamped(anchor, 12 * period.years + period.months), period.days);
|
|
36
|
+
const days = daysBetween(anchor, end);
|
|
37
|
+
for (const weeks of STANDARD_BILL_WEEKS) {
|
|
38
|
+
if (Math.abs(days - 7 * weeks) <= TOLERANCE_DAYS) return weeks;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The 13-week bill fixing on `date`: of every issuance of every bill that
|
|
45
|
+
* has an auction date, an issue date and a high discount rate, was auctioned
|
|
46
|
+
* on or before `date` and snaps to 13 weeks, the one with the latest auction
|
|
47
|
+
* date. On a tie the first in input order wins.
|
|
48
|
+
*
|
|
49
|
+
* The fixing's `rate` is the issuance's `high_discount_rate` proto
|
|
50
|
+
* unchanged, `fixing_date` its `auction_date` and `bill_maturity_date` the
|
|
51
|
+
* bill's maturity. Null when nothing qualifies.
|
|
52
|
+
*/
|
|
53
|
+
export function select(bills: BondSecurity[], date: Date): ReferenceRateFixingProto | null {
|
|
54
|
+
let bestBill: BondSecurity | null = null;
|
|
55
|
+
let best: Issuance | null = null;
|
|
56
|
+
let bestAuctionDate: Date | null = null;
|
|
57
|
+
for (const bill of bills) {
|
|
58
|
+
if (!bill || !bill.getMaturityDate()) continue;
|
|
59
|
+
for (const issuance of bill.getIssuances()) {
|
|
60
|
+
const auctionDate = issuance.getAuctionDate();
|
|
61
|
+
const issueDate = issuance.getIssueDate();
|
|
62
|
+
if (!auctionDate || !issueDate || issuance.getHighDiscountRate() === null) continue;
|
|
63
|
+
if (daysBetween(date, auctionDate) > 0) continue;
|
|
64
|
+
if (standardBillTerm(bill.getIssuanceTenor(issuance), issueDate) !== THIRTEEN_WEEKS) continue;
|
|
65
|
+
if (!bestAuctionDate || daysBetween(bestAuctionDate, auctionDate) > 0) {
|
|
66
|
+
bestBill = bill;
|
|
67
|
+
best = issuance;
|
|
68
|
+
bestAuctionDate = auctionDate;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!bestBill || !best) return null;
|
|
73
|
+
const maturity = bestBill.getMaturityDate() as Date;
|
|
74
|
+
return new ReferenceRateFixingProto()
|
|
75
|
+
.setIndex(IndexTypeProto.T_BILL_13_WEEK)
|
|
76
|
+
.setFixingDate(best.proto.getAuctionDate()?.cloneMessage())
|
|
77
|
+
.setRate(best.proto.getHighDiscountRate()?.cloneMessage())
|
|
78
|
+
.setBillMaturityDate(dateToLocalDateProto(maturity));
|
|
79
|
+
}
|
|
@@ -20,4 +20,19 @@ declare function localDateProtoToDate(proto: LocalDateProto | undefined | null):
|
|
|
20
20
|
* to the proto's 1-based convention; year/day pass through.
|
|
21
21
|
*/
|
|
22
22
|
declare function dateToLocalDateProto(d: Date): LocalDateProto;
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* `d` plus `months` calendar months at local midnight, clamped to the end of
|
|
25
|
+
* the target month as Java's `LocalDate.plusMonths` does: Jan 31 + 1 month is
|
|
26
|
+
* Feb 28 (Feb 29 in a leap year), not Mar 3 as `setMonth` gives. Reads and
|
|
27
|
+
* writes local date parts, like `localDateProtoToDate`.
|
|
28
|
+
*/
|
|
29
|
+
declare function plusMonthsClamped(d: Date, months: number): Date;
|
|
30
|
+
/** `d` plus `days` calendar days at local midnight, from local date parts. */
|
|
31
|
+
declare function plusDays(d: Date, days: number): Date;
|
|
32
|
+
/**
|
|
33
|
+
* Calendar days from `start` to `end`, negative when `end` is earlier.
|
|
34
|
+
* Counts from the local date parts through `Date.UTC`, so a DST change
|
|
35
|
+
* between the two dates cannot shift the count.
|
|
36
|
+
*/
|
|
37
|
+
declare function daysBetween(start: Date, end: Date): number;
|
|
38
|
+
export { LocalDate, localDateProtoToDate, dateToLocalDateProto, plusMonthsClamped, plusDays, daysBetween };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dateToLocalDateProto = exports.localDateProtoToDate = exports.LocalDate = void 0;
|
|
3
|
+
exports.daysBetween = exports.plusDays = exports.plusMonthsClamped = exports.dateToLocalDateProto = exports.localDateProtoToDate = exports.LocalDate = void 0;
|
|
4
4
|
const local_date_pb_1 = require("../../../fintekkers/models/util/local_date_pb");
|
|
5
5
|
const serialization_1 = require("./serialization");
|
|
6
6
|
class LocalDate {
|
|
@@ -53,4 +53,32 @@ function dateToLocalDateProto(d) {
|
|
|
53
53
|
.setDay(d.getDate());
|
|
54
54
|
}
|
|
55
55
|
exports.dateToLocalDateProto = dateToLocalDateProto;
|
|
56
|
+
/**
|
|
57
|
+
* `d` plus `months` calendar months at local midnight, clamped to the end of
|
|
58
|
+
* the target month as Java's `LocalDate.plusMonths` does: Jan 31 + 1 month is
|
|
59
|
+
* Feb 28 (Feb 29 in a leap year), not Mar 3 as `setMonth` gives. Reads and
|
|
60
|
+
* writes local date parts, like `localDateProtoToDate`.
|
|
61
|
+
*/
|
|
62
|
+
function plusMonthsClamped(d, months) {
|
|
63
|
+
const target = new Date(d.getFullYear(), d.getMonth() + months, 1);
|
|
64
|
+
const lastDay = new Date(target.getFullYear(), target.getMonth() + 1, 0).getDate();
|
|
65
|
+
return new Date(target.getFullYear(), target.getMonth(), Math.min(d.getDate(), lastDay));
|
|
66
|
+
}
|
|
67
|
+
exports.plusMonthsClamped = plusMonthsClamped;
|
|
68
|
+
/** `d` plus `days` calendar days at local midnight, from local date parts. */
|
|
69
|
+
function plusDays(d, days) {
|
|
70
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate() + days);
|
|
71
|
+
}
|
|
72
|
+
exports.plusDays = plusDays;
|
|
73
|
+
/**
|
|
74
|
+
* Calendar days from `start` to `end`, negative when `end` is earlier.
|
|
75
|
+
* Counts from the local date parts through `Date.UTC`, so a DST change
|
|
76
|
+
* between the two dates cannot shift the count.
|
|
77
|
+
*/
|
|
78
|
+
function daysBetween(start, end) {
|
|
79
|
+
const startUtc = Date.UTC(start.getFullYear(), start.getMonth(), start.getDate());
|
|
80
|
+
const endUtc = Date.UTC(end.getFullYear(), end.getMonth(), end.getDate());
|
|
81
|
+
return Math.round((endUtc - startUtc) / 86400000);
|
|
82
|
+
}
|
|
83
|
+
exports.daysBetween = daysBetween;
|
|
56
84
|
//# sourceMappingURL=date.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["date.ts"],"names":[],"mappings":";;;AACA,iFAA+E;AAC/E,mDAAyD;AAEzD,MAAM,SAAS;IAGb,YAAY,KAAqB;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,MAAM;QACJ,sEAAsE;QACtE,gFAAgF;QAChF,4EAA4E;QAC5E,OAAO,sCAAsB,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAS,CAAC;IAChE,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IACxF,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,MAAM,CAAC,KAAK;QACV,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,IAAU;QACpB,OAAO,IAAI,SAAS,CAClB,IAAI,8BAAc,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CACtG,CAAC;IACJ,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H,SAAS,WAAW,CAAC,KAAW,EAAE,GAAS;IACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC;AACpD,CAAC;AAE4F,kCAAW"}
|
|
@@ -60,4 +60,32 @@ function dateToLocalDateProto(d: Date): LocalDateProto {
|
|
|
60
60
|
.setDay(d.getDate());
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
/**
|
|
64
|
+
* `d` plus `months` calendar months at local midnight, clamped to the end of
|
|
65
|
+
* the target month as Java's `LocalDate.plusMonths` does: Jan 31 + 1 month is
|
|
66
|
+
* Feb 28 (Feb 29 in a leap year), not Mar 3 as `setMonth` gives. Reads and
|
|
67
|
+
* writes local date parts, like `localDateProtoToDate`.
|
|
68
|
+
*/
|
|
69
|
+
function plusMonthsClamped(d: Date, months: number): Date {
|
|
70
|
+
const target = new Date(d.getFullYear(), d.getMonth() + months, 1);
|
|
71
|
+
const lastDay = new Date(target.getFullYear(), target.getMonth() + 1, 0).getDate();
|
|
72
|
+
return new Date(target.getFullYear(), target.getMonth(), Math.min(d.getDate(), lastDay));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** `d` plus `days` calendar days at local midnight, from local date parts. */
|
|
76
|
+
function plusDays(d: Date, days: number): Date {
|
|
77
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate() + days);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Calendar days from `start` to `end`, negative when `end` is earlier.
|
|
82
|
+
* Counts from the local date parts through `Date.UTC`, so a DST change
|
|
83
|
+
* between the two dates cannot shift the count.
|
|
84
|
+
*/
|
|
85
|
+
function daysBetween(start: Date, end: Date): number {
|
|
86
|
+
const startUtc = Date.UTC(start.getFullYear(), start.getMonth(), start.getDate());
|
|
87
|
+
const endUtc = Date.UTC(end.getFullYear(), end.getMonth(), end.getDate());
|
|
88
|
+
return Math.round((endUtc - startUtc) / 86400000);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { LocalDate, localDateProtoToDate, dateToLocalDateProto, plusMonthsClamped, plusDays, daysBetween };
|
|
@@ -531,7 +531,7 @@ const WRAPS_CALLER = "wraps the caller's proto (pass-through ruling)";
|
|
|
531
531
|
const SERIALIZES = "converts values to untyped messages (dates, UUIDs, decimals) or returns the caller's Identifier proto as is";
|
|
532
532
|
const DESERIALIZES = 'decodes protos the caller or server sent into wrappers; builds no message';
|
|
533
533
|
/** Public callables the scan flags that build no message to stamp, each with its reason. */
|
|
534
|
-
const EXCLUSIONS = Object.assign(Object.assign({ 'object-types.stamp': 'the stamping helper itself (tested above)', 'object-types.stampOwn': 'the stamping helper itself (tested above)', 'price_rules.validate': 'local stand-in for null input; never returned or sent', 'price_rules.requireValid': 'local stand-in for null input; never returned or sent', 'Security.create': "picks the wrapper class for the caller's proto (pass-through ruling)", 'Position.fromJSON': DESERIALIZES, 'ProtoSerializationUtil.deserialize': DESERIALIZES, 'serialization.util.unpack': DESERIALIZES, 'LocalDate.toDate': DESERIALIZES, 'ProtoSerializationUtil.serialize': SERIALIZES, 'serialization.util.pack': SERIALIZES, 'PositionFilter.addFilter': SERIALIZES, 'PositionFilter.addEqualsFilter': SERIALIZES, 'PositionFilter.addEqualsStringFilter': SERIALIZES, 'PositionFilter.addObjectFilter': SERIALIZES, 'Security.hydrate': 'swaps in the proto LinkResolver.getSecurity fetched (that request is tested)', 'Portfolio.hydrate': 'swaps in the proto LinkResolver.getPortfolio fetched (that request is tested)', 'Transaction.hydrate': 'swaps in the proto LinkResolver.getTransaction fetched (that request is tested)' }, Object.fromEntries([
|
|
534
|
+
const EXCLUSIONS = Object.assign(Object.assign({ 'object-types.stamp': 'the stamping helper itself (tested above)', 'object-types.stampOwn': 'the stamping helper itself (tested above)', 'price_rules.validate': 'local stand-in for null input; never returned or sent', 'price_rules.requireValid': 'local stand-in for null input; never returned or sent', 'Security.create': "picks the wrapper class for the caller's proto (pass-through ruling)", 'Position.fromJSON': DESERIALIZES, 'ProtoSerializationUtil.deserialize': DESERIALIZES, 'serialization.util.unpack': DESERIALIZES, 'LocalDate.toDate': DESERIALIZES, 'ProtoSerializationUtil.serialize': SERIALIZES, 'serialization.util.pack': SERIALIZES, 'PositionFilter.addFilter': SERIALIZES, 'PositionFilter.addEqualsFilter': SERIALIZES, 'PositionFilter.addEqualsStringFilter': SERIALIZES, 'PositionFilter.addObjectFilter': SERIALIZES, 'Security.hydrate': 'swaps in the proto LinkResolver.getSecurity fetched (that request is tested)', 'Portfolio.hydrate': 'swaps in the proto LinkResolver.getPortfolio fetched (that request is tested)', 'Transaction.hydrate': 'swaps in the proto LinkResolver.getTransaction fetched (that request is tested)', 'TreasuryFrnFixings.select': "builds a ReferenceRateFixingProto, which has no object_type; flagged only for reading the caller's issuances" }, Object.fromEntries([
|
|
535
535
|
'BondSecurity.constructor', 'FloatingRateNote.constructor', 'Identifier.constructor', 'IndexSecurity.constructor',
|
|
536
536
|
'Issuance.constructor', 'MortgageBackedSecurity.constructor', 'Portfolio.constructor', 'Position.constructor',
|
|
537
537
|
'Price.constructor', 'Security.constructor', 'TIPSBond.constructor',
|