@fintekkers/ledger-models 1.1.4 → 1.1.5
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/catalog/measures.json +6 -1
- package/node/fintekkers/requests/valuation/cost_basis_input.test.d.ts +3 -0
- package/node/fintekkers/requests/valuation/cost_basis_input.test.js +55 -0
- package/node/fintekkers/requests/valuation/cost_basis_input.test.js.map +1 -1
- package/node/fintekkers/requests/valuation/cost_basis_input.test.ts +63 -1
- package/package.json +1 -1
package/catalog/measures.json
CHANGED
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"enum_value": 4,
|
|
60
60
|
"display_name": "Adjusted Cost Basis",
|
|
61
61
|
"description": "Tax amortised cost, per 100 face, quantity-weighted over the open lots. Tax basis only; book (GAAP/IFRS) cost is out of scope. Inputs: cost_basis (CostBasisInput) on BondInput, TipsInput or FrnInput.",
|
|
62
|
-
"formula": "AdjustedCostBasis = sum(open_quantity_i * acb_i) / sum(open_quantity_i) over CostBasisInput.lots, where acb_i is lot i's amortised cost per 100 face at the valuation date. OID: always accreted (mandatory, whatever the elections) at constant yield from the issue price (IssuanceProto.price_for_single_price_auction, MDI-82), reduced by any acquisition premium. Premium (IRC §171): amortised at constant yield if elected. Market discount: accreted only with INCLUDE_CURRENTLY, ratably or at constant yield per market_discount_accrual; otherwise left until disposition. De minimis: OID and market discount below 0.25% × complete years to maturity are treated as zero.",
|
|
62
|
+
"formula": "AdjustedCostBasis = sum(open_quantity_i * acb_i) / sum(open_quantity_i) over CostBasisInput.lots, where acb_i is lot i's amortised cost per 100 face at the valuation date. OID: always accreted (mandatory, whatever the elections) at constant yield from the issue price (IssuanceProto.price_for_single_price_auction, MDI-82), reduced by any acquisition premium. Premium (IRC §171): amortised at constant yield if elected. Market discount: accreted only with INCLUDE_CURRENTLY, ratably or at constant yield per market_discount_accrual; otherwise left until disposition. De minimis: OID and market discount below 0.25% × complete years to maturity are treated as zero. TIPS: AdjustedCostBasis = sum(open_quantity_i * real_acb_i) / sum(open_quantity_i) * IndexRatio(valuation date), where real_acb_i is lot i's amortised cost per 100 real face: it starts from the lot's real purchase price (TaxLotProto.price) and accrues at constant yield on real principal; open_quantity_i is the lot's original (unadjusted) face; and IndexRatio(valuation date) is INDEX_RATIO for the UTC date of ValuationRequestProto.asof_datetime. Example: lots of 10000 at real_acb 99.00 and 5000 at 101.50, index ratio 1.2 -> (10000*99.00 + 5000*101.50) / 15000 * 1.2 = 119.80.",
|
|
63
63
|
"units": "Price per 100 face (% of par). TIPS: per 100 original face, in nominal dollars",
|
|
64
64
|
"category": "cost",
|
|
65
65
|
"applies_to": ["TREASURY_NOTE", "TREASURY_BOND", "SOVEREIGN_BOND", "CORP_BOND", "MUNI_BOND", "TIPS", "TREASURY_FRN"],
|
|
@@ -67,6 +67,11 @@
|
|
|
67
67
|
"Accrual start: from each lot's open_date plus the product's settlement lag (e.g. T+1 for Treasuries)",
|
|
68
68
|
"Elections: CostBasisInput.elections, copied from PortfolioProto.amortisation_elections; unset fields use the defaults (PREMIUM_ELECTED, AT_DISPOSITION, RATABLE)",
|
|
69
69
|
"TIPS: amortise in real terms, then multiply by the index ratio at the valuation date, giving a figure per 100 original face in nominal dollars",
|
|
70
|
+
"TIPS accrual start: from each lot's open_date plus the product's settlement lag, on real principal; valuation-service owns the settlement lag and lots carry no settlement field",
|
|
71
|
+
"TIPS elections: premium and market discount accrue or not per the elections, as in the fixed-rate rules",
|
|
72
|
+
"TIPS CPI: only the m-3 and m-2 readings for the valuation date in TipsInput.cpi; lot dates need no CPI readings",
|
|
73
|
+
"TIPS rounding: none. real_acb_i, the weighted average, the index ratio and the result are all unrounded, as for INDEX_RATIO and MARKET_VALUE",
|
|
74
|
+
"TIPS deflation floor: not applied. It applies only to final principal (INFLATION_ADJUSTED_PRINCIPAL), never to the basis",
|
|
70
75
|
"FRN: use the equivalent fixed rate from the fixing at settlement",
|
|
71
76
|
"No lots: the measure is absent, with a \"no open lots\" warning, never 0"
|
|
72
77
|
],
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* LM-364 — a TipsInput with cost_basis (20): non-default elections and two
|
|
3
3
|
* TaxLotProto lots round-trip unchanged.
|
|
4
4
|
*
|
|
5
|
+
* LM-378 — a TIPS ADJUSTED_COST_BASIS request: two lots plus the valuation
|
|
6
|
+
* date's m-3 and m-2 CPI readings round-trip unchanged.
|
|
7
|
+
*
|
|
5
8
|
* The enum values are all non-zero: value 0 is not written on the wire.
|
|
6
9
|
*/
|
|
7
10
|
export {};
|
|
@@ -3,14 +3,19 @@
|
|
|
3
3
|
* LM-364 — a TipsInput with cost_basis (20): non-default elections and two
|
|
4
4
|
* TaxLotProto lots round-trip unchanged.
|
|
5
5
|
*
|
|
6
|
+
* LM-378 — a TIPS ADJUSTED_COST_BASIS request: two lots plus the valuation
|
|
7
|
+
* date's m-3 and m-2 CPI readings round-trip unchanged.
|
|
8
|
+
*
|
|
6
9
|
* The enum values are all non-zero: value 0 is not written on the wire.
|
|
7
10
|
*/
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const timestamp_pb_1 = require("google-protobuf/google/protobuf/timestamp_pb");
|
|
9
13
|
const product_inputs_pb_1 = require("./product_inputs_pb");
|
|
10
14
|
const valuation_request_pb_1 = require("./valuation_request_pb");
|
|
11
15
|
const amortisation_elections_pb_1 = require("../../../fintekkers/models/portfolio/amortisation_elections_pb");
|
|
12
16
|
const tax_lot_pb_1 = require("../../../fintekkers/models/position/tax_lot_pb");
|
|
13
17
|
const local_date_pb_1 = require("../../../fintekkers/models/util/local_date_pb");
|
|
18
|
+
const local_timestamp_pb_1 = require("../../../fintekkers/models/util/local_timestamp_pb");
|
|
14
19
|
const decimal_1 = require("../../../wrappers/models/utils/decimal");
|
|
15
20
|
function decimal(value) {
|
|
16
21
|
return (0, decimal_1.encodeDecimal)((0, decimal_1.parseDecimalString)(value));
|
|
@@ -29,6 +34,13 @@ function lot(openDate, openQuantity, price) {
|
|
|
29
34
|
l.setPrice(decimal(price));
|
|
30
35
|
return l;
|
|
31
36
|
}
|
|
37
|
+
function reading(year, month, value) {
|
|
38
|
+
const r = new product_inputs_pb_1.MonthlyIndexReading();
|
|
39
|
+
r.setYear(year);
|
|
40
|
+
r.setMonth(month);
|
|
41
|
+
r.setValue(decimal(value));
|
|
42
|
+
return r;
|
|
43
|
+
}
|
|
32
44
|
describe('TipsInput cost_basis (20)', () => {
|
|
33
45
|
test('non-default elections and two lots round-trip unchanged', () => {
|
|
34
46
|
const elections = new amortisation_elections_pb_1.AmortisationElectionsProto();
|
|
@@ -65,5 +77,48 @@ describe('TipsInput cost_basis (20)', () => {
|
|
|
65
77
|
[{ year: 2025, month: 6, day: 2 }, '5000', '101.50'],
|
|
66
78
|
]);
|
|
67
79
|
});
|
|
80
|
+
test('TIPS ADJUSTED_COST_BASIS request with two lots and the m-3 and m-2 CPI readings round-trips unchanged', () => {
|
|
81
|
+
// 2026-10-23T14:30:00Z: settlement month 2026-10, so m-3 and m-2 are 2026-07 and 2026-08.
|
|
82
|
+
const timestamp = new timestamp_pb_1.Timestamp();
|
|
83
|
+
timestamp.setSeconds(1792765800);
|
|
84
|
+
const asof = new local_timestamp_pb_1.LocalTimestampProto();
|
|
85
|
+
asof.setTimestamp(timestamp);
|
|
86
|
+
const readings = new product_inputs_pb_1.MonthlyIndexReadings();
|
|
87
|
+
readings.addReadings(reading(2026, 7, '322.100'));
|
|
88
|
+
readings.addReadings(reading(2026, 8, '322.900'));
|
|
89
|
+
const cpi = new product_inputs_pb_1.InflationIndexInput();
|
|
90
|
+
cpi.setReadings(readings);
|
|
91
|
+
const costBasis = new product_inputs_pb_1.CostBasisInput();
|
|
92
|
+
costBasis.addLots(lot(date(2024, 1, 15), '10000', '98.25'));
|
|
93
|
+
costBasis.addLots(lot(date(2025, 6, 2), '5000', '101.50'));
|
|
94
|
+
const tips = new product_inputs_pb_1.TipsInput();
|
|
95
|
+
tips.setCleanPrice(decimal('97.50'));
|
|
96
|
+
tips.setCpi(cpi);
|
|
97
|
+
tips.setCostBasis(costBasis);
|
|
98
|
+
const productInput = new product_inputs_pb_1.ProductInput();
|
|
99
|
+
productInput.setTips(tips);
|
|
100
|
+
const request = new valuation_request_pb_1.ValuationRequestProto();
|
|
101
|
+
request.setAsofDatetime(asof);
|
|
102
|
+
request.setProductInput(productInput);
|
|
103
|
+
const parsed = valuation_request_pb_1.ValuationRequestProto.deserializeBinary(request.serializeBinary());
|
|
104
|
+
expect(parsed.getAsofDatetime().toObject()).toEqual(asof.toObject());
|
|
105
|
+
expect(parsed.getAsofDatetime().getTimestamp().toDate().toISOString()).toBe('2026-10-23T14:30:00.000Z');
|
|
106
|
+
const decoded = parsed.getProductInput().getTips();
|
|
107
|
+
expect(decoded.toObject()).toEqual(tips.toObject());
|
|
108
|
+
expect(decoded.getCpi().hasReadings()).toBe(true);
|
|
109
|
+
const got = decoded.getCpi().getReadings().getReadingsList().map(r => [
|
|
110
|
+
r.getYear(), r.getMonth(), (0, decimal_1.toCanonicalString)((0, decimal_1.decodeDecimal)(r.getValue())),
|
|
111
|
+
]);
|
|
112
|
+
expect(got).toEqual([[2026, 7, '322.100'], [2026, 8, '322.900']]);
|
|
113
|
+
const lots = decoded.getCostBasis().getLotsList().map(l => [
|
|
114
|
+
l.getOpenDate().toObject(),
|
|
115
|
+
(0, decimal_1.toCanonicalString)((0, decimal_1.decodeDecimal)(l.getOpenQuantity())),
|
|
116
|
+
(0, decimal_1.toCanonicalString)((0, decimal_1.decodeDecimal)(l.getPrice())),
|
|
117
|
+
]);
|
|
118
|
+
expect(lots).toEqual([
|
|
119
|
+
[{ year: 2024, month: 1, day: 15 }, '10000', '98.25'],
|
|
120
|
+
[{ year: 2025, month: 6, day: 2 }, '5000', '101.50'],
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
68
123
|
});
|
|
69
124
|
//# sourceMappingURL=cost_basis_input.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost_basis_input.test.js","sourceRoot":"","sources":["cost_basis_input.test.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"cost_basis_input.test.js","sourceRoot":"","sources":["cost_basis_input.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAEH,+EAAyE;AACzE,2DAE6B;AAC7B,iEAA+D;AAC/D,8GAGwE;AACxE,+EAA6E;AAE7E,iFAA+E;AAC/E,2FAAyF;AACzF,oEAA6H;AAE7H,SAAS,OAAO,CAAC,KAAa;IAC1B,OAAO,IAAA,uBAAa,EAAC,IAAA,4BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW;IAClD,MAAM,CAAC,GAAG,IAAI,8BAAc,EAAE,CAAC;IAC/B,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACd,OAAO,CAAC,CAAC;AACb,CAAC;AAED,SAAS,GAAG,CAAC,QAAwB,EAAE,YAAoB,EAAE,KAAa;IACtE,MAAM,CAAC,GAAG,IAAI,wBAAW,EAAE,CAAC;IAC5B,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACxB,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IACzC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3B,OAAO,CAAC,CAAC;AACb,CAAC;AAED,SAAS,OAAO,CAAC,IAAY,EAAE,KAAa,EAAE,KAAa;IACvD,MAAM,CAAC,GAAG,IAAI,uCAAmB,EAAE,CAAC;IACpC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC,QA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MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;QAElE,MAAM,IAAI,GAAG,OAAO,CAAC,YAAY,EAAG,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACxD,CAAC,CAAC,WAAW,EAAG,CAAC,QAAQ,EAAE;YAC3B,IAAA,2BAAiB,EAAC,IAAA,uBAAa,EAAC,CAAC,CAAC,eAAe,EAAG,CAAC,CAAC;YACtD,IAAA,2BAAiB,EAAC,IAAA,uBAAa,EAAC,CAAC,CAAC,QAAQ,EAAG,CAAC,CAAC;SAClD,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;YACjB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC;YACrD,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC;SACvD,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
* LM-364 — a TipsInput with cost_basis (20): non-default elections and two
|
|
3
3
|
* TaxLotProto lots round-trip unchanged.
|
|
4
4
|
*
|
|
5
|
+
* LM-378 — a TIPS ADJUSTED_COST_BASIS request: two lots plus the valuation
|
|
6
|
+
* date's m-3 and m-2 CPI readings round-trip unchanged.
|
|
7
|
+
*
|
|
5
8
|
* The enum values are all non-zero: value 0 is not written on the wire.
|
|
6
9
|
*/
|
|
7
10
|
|
|
8
|
-
import {
|
|
11
|
+
import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
|
|
12
|
+
import {
|
|
13
|
+
CostBasisInput, InflationIndexInput, MonthlyIndexReading, MonthlyIndexReadings, ProductInput, TipsInput,
|
|
14
|
+
} from './product_inputs_pb';
|
|
9
15
|
import { ValuationRequestProto } from './valuation_request_pb';
|
|
10
16
|
import {
|
|
11
17
|
AmortisationElectionsProto, MarketDiscountAccrualMethodProto, MarketDiscountInclusionProto,
|
|
@@ -14,6 +20,7 @@ import {
|
|
|
14
20
|
import { TaxLotProto } from '../../../fintekkers/models/position/tax_lot_pb';
|
|
15
21
|
import { DecimalValueProto } from '../../../fintekkers/models/util/decimal_value_pb';
|
|
16
22
|
import { LocalDateProto } from '../../../fintekkers/models/util/local_date_pb';
|
|
23
|
+
import { LocalTimestampProto } from '../../../fintekkers/models/util/local_timestamp_pb';
|
|
17
24
|
import { decodeDecimal, encodeDecimal, parseDecimalString, toCanonicalString } from '../../../wrappers/models/utils/decimal';
|
|
18
25
|
|
|
19
26
|
function decimal(value: string): DecimalValueProto {
|
|
@@ -36,6 +43,14 @@ function lot(openDate: LocalDateProto, openQuantity: string, price: string): Tax
|
|
|
36
43
|
return l;
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
function reading(year: number, month: number, value: string): MonthlyIndexReading {
|
|
47
|
+
const r = new MonthlyIndexReading();
|
|
48
|
+
r.setYear(year);
|
|
49
|
+
r.setMonth(month);
|
|
50
|
+
r.setValue(decimal(value));
|
|
51
|
+
return r;
|
|
52
|
+
}
|
|
53
|
+
|
|
39
54
|
describe('TipsInput cost_basis (20)', () => {
|
|
40
55
|
test('non-default elections and two lots round-trip unchanged', () => {
|
|
41
56
|
const elections = new AmortisationElectionsProto();
|
|
@@ -75,4 +90,51 @@ describe('TipsInput cost_basis (20)', () => {
|
|
|
75
90
|
[{ year: 2025, month: 6, day: 2 }, '5000', '101.50'],
|
|
76
91
|
]);
|
|
77
92
|
});
|
|
93
|
+
|
|
94
|
+
test('TIPS ADJUSTED_COST_BASIS request with two lots and the m-3 and m-2 CPI readings round-trips unchanged', () => {
|
|
95
|
+
// 2026-10-23T14:30:00Z: settlement month 2026-10, so m-3 and m-2 are 2026-07 and 2026-08.
|
|
96
|
+
const timestamp = new Timestamp();
|
|
97
|
+
timestamp.setSeconds(1792765800);
|
|
98
|
+
const asof = new LocalTimestampProto();
|
|
99
|
+
asof.setTimestamp(timestamp);
|
|
100
|
+
const readings = new MonthlyIndexReadings();
|
|
101
|
+
readings.addReadings(reading(2026, 7, '322.100'));
|
|
102
|
+
readings.addReadings(reading(2026, 8, '322.900'));
|
|
103
|
+
const cpi = new InflationIndexInput();
|
|
104
|
+
cpi.setReadings(readings);
|
|
105
|
+
const costBasis = new CostBasisInput();
|
|
106
|
+
costBasis.addLots(lot(date(2024, 1, 15), '10000', '98.25'));
|
|
107
|
+
costBasis.addLots(lot(date(2025, 6, 2), '5000', '101.50'));
|
|
108
|
+
const tips = new TipsInput();
|
|
109
|
+
tips.setCleanPrice(decimal('97.50'));
|
|
110
|
+
tips.setCpi(cpi);
|
|
111
|
+
tips.setCostBasis(costBasis);
|
|
112
|
+
const productInput = new ProductInput();
|
|
113
|
+
productInput.setTips(tips);
|
|
114
|
+
const request = new ValuationRequestProto();
|
|
115
|
+
request.setAsofDatetime(asof);
|
|
116
|
+
request.setProductInput(productInput);
|
|
117
|
+
|
|
118
|
+
const parsed = ValuationRequestProto.deserializeBinary(request.serializeBinary());
|
|
119
|
+
expect(parsed.getAsofDatetime()!.toObject()).toEqual(asof.toObject());
|
|
120
|
+
expect(parsed.getAsofDatetime()!.getTimestamp()!.toDate().toISOString()).toBe('2026-10-23T14:30:00.000Z');
|
|
121
|
+
const decoded = parsed.getProductInput()!.getTips()!;
|
|
122
|
+
expect(decoded.toObject()).toEqual(tips.toObject());
|
|
123
|
+
|
|
124
|
+
expect(decoded.getCpi()!.hasReadings()).toBe(true);
|
|
125
|
+
const got = decoded.getCpi()!.getReadings()!.getReadingsList().map(r => [
|
|
126
|
+
r.getYear(), r.getMonth(), toCanonicalString(decodeDecimal(r.getValue()!)),
|
|
127
|
+
]);
|
|
128
|
+
expect(got).toEqual([[2026, 7, '322.100'], [2026, 8, '322.900']]);
|
|
129
|
+
|
|
130
|
+
const lots = decoded.getCostBasis()!.getLotsList().map(l => [
|
|
131
|
+
l.getOpenDate()!.toObject(),
|
|
132
|
+
toCanonicalString(decodeDecimal(l.getOpenQuantity()!)),
|
|
133
|
+
toCanonicalString(decodeDecimal(l.getPrice()!)),
|
|
134
|
+
]);
|
|
135
|
+
expect(lots).toEqual([
|
|
136
|
+
[{ year: 2024, month: 1, day: 15 }, '10000', '98.25'],
|
|
137
|
+
[{ year: 2025, month: 6, day: 2 }, '5000', '101.50'],
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
78
140
|
});
|