@fintekkers/ledger-models 1.1.29 → 1.1.30
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/hierarchy.json +11 -11
- package/node/fintekkers/requests/valuation/product_inputs.test.js +3 -3
- package/node/fintekkers/requests/valuation/product_inputs.test.js.map +1 -1
- package/node/fintekkers/requests/valuation/product_inputs.test.ts +3 -3
- package/node/wrappers/models/errors.d.ts +14 -11
- package/node/wrappers/models/errors.js +18 -13
- package/node/wrappers/models/errors.js.map +1 -1
- package/node/wrappers/models/errors.ts +20 -14
- package/node/wrappers/models/security/product_input_builders.test.js +17 -17
- package/node/wrappers/models/security/product_input_builders.test.js.map +1 -1
- package/node/wrappers/models/security/product_input_builders.test.ts +20 -20
- package/node/wrappers/models/security/product_inputs.d.ts +69 -39
- package/node/wrappers/models/security/product_inputs.deprecated.test.d.ts +1 -0
- package/node/wrappers/models/security/product_inputs.deprecated.test.js +136 -0
- package/node/wrappers/models/security/product_inputs.deprecated.test.js.map +1 -0
- package/node/wrappers/models/security/product_inputs.deprecated.test.ts +130 -0
- package/node/wrappers/models/security/product_inputs.js +143 -75
- package/node/wrappers/models/security/product_inputs.js.map +1 -1
- package/node/wrappers/models/security/product_inputs.test.js +43 -43
- package/node/wrappers/models/security/product_inputs.test.js.map +1 -1
- package/node/wrappers/models/security/product_inputs.test.ts +47 -46
- package/node/wrappers/models/security/product_inputs.ts +152 -79
- 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 -1
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ import * as path from 'path';
|
|
|
11
11
|
import * as jspb from 'google-protobuf';
|
|
12
12
|
|
|
13
13
|
import hierarchy from '../../../../hierarchy.json';
|
|
14
|
-
import {
|
|
14
|
+
import { inputTypeFor, checkProductInput, forSecurity, MarketData } from './product_inputs';
|
|
15
15
|
import { ValuationRequests } from '../../requests/valuation/ValuationRequests';
|
|
16
16
|
import { MissingMarketDataError, ModelValidationError, UnmappedProductTypeError } from '../errors';
|
|
17
17
|
import { MeasureProto } from '../../../fintekkers/models/position/measure_pb';
|
|
@@ -26,13 +26,13 @@ import {
|
|
|
26
26
|
|
|
27
27
|
const FIXTURES = path.resolve(__dirname, '../../../../../test-fixtures/product-inputs');
|
|
28
28
|
|
|
29
|
-
interface ErrorSpec { type: string;
|
|
29
|
+
interface ErrorSpec { type: string; input_type?: string; kind?: string; field?: string }
|
|
30
30
|
interface Fixture {
|
|
31
31
|
name: string;
|
|
32
32
|
security_hex: string;
|
|
33
33
|
price_hex: string;
|
|
34
34
|
market_data?: { cpi_hex?: string; fixings_hex?: string[]; curve_hex?: string };
|
|
35
|
-
|
|
35
|
+
input_type?: string;
|
|
36
36
|
expected_hex?: string;
|
|
37
37
|
error?: ErrorSpec;
|
|
38
38
|
typed: { asof_hex: string; position_hex: string; measures: string[]; expected_hex?: string; product_input_hex?: string };
|
|
@@ -42,7 +42,7 @@ const cases: Fixture[] = fs.readdirSync(FIXTURES)
|
|
|
42
42
|
.filter((f) => f.endsWith('.json'))
|
|
43
43
|
.sort()
|
|
44
44
|
.map((f) => ({ ...JSON.parse(fs.readFileSync(path.join(FIXTURES, f), 'utf-8')), name: f.replace(/\.json$/, '') }));
|
|
45
|
-
const success = cases.filter((c) => c.
|
|
45
|
+
const success = cases.filter((c) => c.input_type !== undefined);
|
|
46
46
|
const errors = cases.filter((c) => c.error !== undefined);
|
|
47
47
|
const fixture = (name: string): Fixture => cases.find((c) => c.name === name)!;
|
|
48
48
|
|
|
@@ -81,8 +81,8 @@ function expectError(e: Error, spec: ErrorSpec): void {
|
|
|
81
81
|
if (spec.type === 'MissingMarketDataError') {
|
|
82
82
|
const m = e as MissingMarketDataError;
|
|
83
83
|
expect(m).toBeInstanceOf(MissingMarketDataError);
|
|
84
|
-
expect([m.
|
|
85
|
-
expect(m.message).toContain(spec.
|
|
84
|
+
expect([m.inputType, m.kind, m.field]).toEqual([spec.input_type, spec.kind, spec.field]);
|
|
85
|
+
expect(m.message).toContain(spec.input_type);
|
|
86
86
|
expect(m.message).toContain(spec.kind);
|
|
87
87
|
} else {
|
|
88
88
|
expect(e).toBeInstanceOf(UnmappedProductTypeError);
|
|
@@ -91,29 +91,29 @@ function expectError(e: Error, spec: ErrorSpec): void {
|
|
|
91
91
|
|
|
92
92
|
// ---- forSecurity
|
|
93
93
|
|
|
94
|
-
test('fixtures cover every
|
|
95
|
-
const entries = (hierarchy as unknown as {
|
|
96
|
-
const
|
|
97
|
-
expect(new Set(success.map((c) => c.
|
|
98
|
-
expect(success).toHaveLength(
|
|
94
|
+
test('fixtures cover every input type in valuation_input_types', () => {
|
|
95
|
+
const entries = (hierarchy as unknown as { valuation_input_types: { entries: { input_type: string }[] } }).valuation_input_types.entries;
|
|
96
|
+
const inputTypes = new Set(entries.map((e) => e.input_type));
|
|
97
|
+
expect(new Set(success.map((c) => c.input_type))).toEqual(inputTypes);
|
|
98
|
+
expect(success).toHaveLength(inputTypes.size);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
test.each(success.map((c) => [c.name, c] as const))('%s: forSecurity matches the fixture bytes', (_name, c) => {
|
|
102
102
|
expect(hexOf(forSecurity(security(c), price(c), marketData(c)))).toBe(c.expected_hex);
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
// R1: the
|
|
105
|
+
// R1: the input type is inputTypeFor's, and each field is the input it came from.
|
|
106
106
|
test.each(success.map((c) => [c.name, c] as const))('%s: forSecurity fields', (_name, c) => {
|
|
107
107
|
const [s, p, md] = [security(c), price(c), marketData(c)];
|
|
108
108
|
const out = forSecurity(s, p, md);
|
|
109
|
-
expect(
|
|
109
|
+
expect(inputTypeFor(s)).toBe(c.input_type);
|
|
110
110
|
const body = {
|
|
111
111
|
bond: out.getBond(), tips: out.getTips(), frn: out.getFrn(), mbs: out.getMbs(), equity: out.getEquity(), cash: out.getCash(),
|
|
112
|
-
}[c.
|
|
112
|
+
}[c.input_type!]!;
|
|
113
113
|
expect(body).toBeDefined();
|
|
114
114
|
expect(hexOf(body.getSecurity()!)).toBe(hexOf(s));
|
|
115
115
|
const fields = body as unknown as Record<string, unknown>;
|
|
116
|
-
if (c.
|
|
116
|
+
if (c.input_type === 'equity' || c.input_type === 'cash') {
|
|
117
117
|
expect(hexOf((fields.getUnitPrice as () => jspb.Message).call(body))).toBe(hexOf(p.getPrice()!));
|
|
118
118
|
expect(fields.getCleanPrice).toBeUndefined();
|
|
119
119
|
} else {
|
|
@@ -121,8 +121,8 @@ test.each(success.map((c) => [c.name, c] as const))('%s: forSecurity fields', (_
|
|
|
121
121
|
expect(fields.getUnitPrice).toBeUndefined();
|
|
122
122
|
expect((fields.hasCostBasis as () => boolean).call(body)).toBe(false);
|
|
123
123
|
}
|
|
124
|
-
if (c.
|
|
125
|
-
if (c.
|
|
124
|
+
if (c.input_type === 'tips') expect(hexOf(out.getTips()!.getCpi()!)).toBe(hexOf(md.cpi!));
|
|
125
|
+
if (c.input_type === 'frn') {
|
|
126
126
|
expect(out.getFrn()!.getFixingsList().map(hexOf)).toEqual(md.fixings!.map(hexOf));
|
|
127
127
|
expect(hexOf(out.getFrn()!.getCurve()!)).toBe(hexOf(md.curve!));
|
|
128
128
|
}
|
|
@@ -137,7 +137,7 @@ test('forSecurity with no market data throws MissingMarketDataError(tips, CPI_U)
|
|
|
137
137
|
for (const md of [undefined, null]) {
|
|
138
138
|
const e = caught(() => forSecurity(security(c), price(c), md)) as MissingMarketDataError;
|
|
139
139
|
expect(e).toBeInstanceOf(MissingMarketDataError);
|
|
140
|
-
expect([e.
|
|
140
|
+
expect([e.inputType, e.kind]).toEqual(['tips', 'CPI_U']);
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
|
|
@@ -172,7 +172,7 @@ test('typed requires a position', () => {
|
|
|
172
172
|
expect((e as ModelValidationError).field).toBe('position_input');
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
-
test('typed rejects an
|
|
175
|
+
test('typed rejects an input type inputTypeFor did not pick', () => {
|
|
176
176
|
const c = fixture('tips');
|
|
177
177
|
const wrong = new ProductInput().setBond(new BondInput().setSecurity(security(c)).setCleanPrice(price(c).getPrice()));
|
|
178
178
|
const [asof, position, measures] = typedArgs(c);
|
|
@@ -182,7 +182,7 @@ test('typed rejects an arm armFor did not pick', () => {
|
|
|
182
182
|
expect((e as ModelValidationError).field).toBe('product_input.bond');
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
-
test('typed rejects an input with no
|
|
185
|
+
test('typed rejects an input with no input type', () => {
|
|
186
186
|
const [asof, position, measures] = typedArgs(fixture('bond'));
|
|
187
187
|
const e = caught(() => ValuationRequests.typed(asof, new ProductInput(), position, measures));
|
|
188
188
|
expect((e as ModelValidationError).field).toBe('product_input');
|
|
@@ -1,78 +1,108 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Which ProductInput
|
|
3
|
-
* needs. Backed by the
|
|
2
|
+
* Which ProductInput input type values a security, and which market data that
|
|
3
|
+
* input type needs. Backed by the valuation_input_types section of
|
|
4
4
|
* ledger-models-protos/hierarchy.json; there is no mapping table in code.
|
|
5
|
-
* Same rule in Java / Rust / Python / JS-TS. See docs/adr/
|
|
5
|
+
* Same rule in Java / Rust / Python / JS-TS. See docs/adr/valuation_input_types.md.
|
|
6
6
|
*
|
|
7
7
|
* Resolution walks from the security's product_type up its parent chain. At
|
|
8
8
|
* each node a coupon_types entry matching bond_details.coupon_type wins, then
|
|
9
9
|
* the node's plain entry, then an unpriced listing. The first node with any
|
|
10
10
|
* match decides. No match, or an unpriced match, throws
|
|
11
|
-
* UnmappedProductTypeError: there is no default
|
|
11
|
+
* UnmappedProductTypeError: there is no default input type. A broken section throws
|
|
12
12
|
* a plain Error at load, like product_hierarchy.
|
|
13
13
|
*
|
|
14
|
-
* forSecurity builds the ProductInput for that
|
|
15
|
-
* and its market data; checkProductInput checks a ProductInput against the
|
|
14
|
+
* forSecurity builds the ProductInput for that input type from a security, its
|
|
15
|
+
* price and its market data; checkProductInput checks a ProductInput against the
|
|
16
16
|
* same rule (LM-410). See docs/adr/product_input_builders.md.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
* read from the bundled catalog/measures.json through the same
|
|
20
|
-
* (LM-427). There is no measure list in code.
|
|
18
|
+
* measuresForInputType lists the measures valuation-service computes for an
|
|
19
|
+
* input type, read from the bundled catalog/measures.json through the same
|
|
20
|
+
* lookup (LM-427). There is no measure list in code.
|
|
21
|
+
*
|
|
22
|
+
* LM-418 renamed "arm" to "input type". The arm-named exports stay one release
|
|
23
|
+
* as deprecated aliases, and hierarchy.json still loads with the legacy
|
|
24
|
+
* valuation_arms / arm keys.
|
|
21
25
|
*/
|
|
22
26
|
import { MeasureProto } from '../../../fintekkers/models/position/measure_pb';
|
|
23
27
|
import { PriceProto } from '../../../fintekkers/models/price/price_pb';
|
|
24
28
|
import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
25
29
|
import { InflationIndexInput, ProductInput, ReferenceRateFixingProto, YieldCurveInput } from '../../../fintekkers/requests/valuation/product_inputs_pb';
|
|
26
|
-
/** The closed requires vocabulary: market data an
|
|
30
|
+
/** The closed requires vocabulary: market data an input type needs beyond the price. */
|
|
27
31
|
export type MarketDataKind = 'CPI_U' | 'FRN_FIXINGS' | 'FRN_CURVE';
|
|
28
|
-
interface
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
interface InputTypeEntry {
|
|
33
|
+
readonly inputType: string;
|
|
34
|
+
/** @deprecated Use inputType. Removed in a later release (LM-418). */
|
|
35
|
+
readonly arm: string;
|
|
36
|
+
readonly requires: ReadonlyArray<MarketDataKind>;
|
|
31
37
|
}
|
|
32
|
-
/** A parsed, checked
|
|
33
|
-
export declare class
|
|
38
|
+
/** A parsed, checked valuation_input_types section. */
|
|
39
|
+
export declare class ValuationInputTypes {
|
|
34
40
|
private readonly entries;
|
|
35
41
|
private readonly unpriced;
|
|
36
|
-
/** @param entries node -> coupon type name (or '' for the plain entry) ->
|
|
37
|
-
constructor(entries: Map<string, Map<string,
|
|
38
|
-
/** The deepest matching node's
|
|
39
|
-
resolve(productType: string, couponType: string):
|
|
40
|
-
require(productType: string, couponType: string):
|
|
42
|
+
/** @param entries node -> coupon type name (or '' for the plain entry) -> input type */
|
|
43
|
+
constructor(entries: Map<string, Map<string, InputTypeEntry>>, unpriced: ReadonlySet<string>);
|
|
44
|
+
/** The deepest matching node's input type, or null when unmapped or unpriced. */
|
|
45
|
+
resolve(productType: string, couponType: string): InputTypeEntry | null;
|
|
46
|
+
require(productType: string, couponType: string): InputTypeEntry;
|
|
41
47
|
/** Leaf product types (active and planned) with neither an entry nor an unpriced listing. */
|
|
42
48
|
uncoveredLeaves(): string[];
|
|
43
49
|
private covers;
|
|
44
50
|
}
|
|
45
51
|
/**
|
|
46
|
-
* Parses and checks a
|
|
52
|
+
* Parses and checks a valuation_input_types section against the shipped
|
|
47
53
|
* product_types tree, the ProductInput oneof and the CouponTypeProto /
|
|
48
54
|
* MarketDataKind vocabularies. Throws on any failure. Exported for tests.
|
|
49
55
|
*/
|
|
50
|
-
export declare function
|
|
51
|
-
/**
|
|
52
|
-
|
|
56
|
+
export declare function parseValuationInputTypes(section: unknown): ValuationInputTypes;
|
|
57
|
+
/**
|
|
58
|
+
* Parses and checks the valuation_input_types section of a whole
|
|
59
|
+
* hierarchy.json `root`. For one release a root with the legacy
|
|
60
|
+
* valuation_arms key instead loads the same way (LM-418); a root with both
|
|
61
|
+
* keys, or neither, throws. Exported for tests.
|
|
62
|
+
*/
|
|
63
|
+
export declare function valuationInputTypesFromHierarchy(root: unknown): ValuationInputTypes;
|
|
64
|
+
/** The shipped valuation_input_types section, parsed and checked on first use. Exported for tests. */
|
|
65
|
+
export declare function shippedValuationInputTypes(): ValuationInputTypes;
|
|
53
66
|
/** Name of the ProductInput.input oneof field that values `security`, e.g. 'tips'. */
|
|
67
|
+
export declare function inputTypeFor(security: SecurityProto): string;
|
|
68
|
+
/** @deprecated Use inputTypeFor. Removed in a later release (LM-418). */
|
|
54
69
|
export declare function armFor(security: SecurityProto): string;
|
|
55
|
-
/** Market data the security's
|
|
70
|
+
/** Market data the security's input type needs, in file order. A fresh array; empty when none. */
|
|
56
71
|
export declare function requiredMarketData(security: SecurityProto): MarketDataKind[];
|
|
57
72
|
/**
|
|
58
|
-
* The measures valuation-service computes for `
|
|
73
|
+
* The measures valuation-service computes for `inputType` (e.g. 'frn'), in catalog
|
|
59
74
|
* order: entries of the bundled catalog/measures.json with computed_by
|
|
60
75
|
* valuation-service and implemented true whose applies_to names a leaf product
|
|
61
|
-
* type the
|
|
62
|
-
* UnmappedProductTypeError(
|
|
63
|
-
* `
|
|
76
|
+
* type the input type values, or an ancestor of one. Throws
|
|
77
|
+
* UnmappedProductTypeError(inputType, 'UNKNOWN_COUPON_TYPE') when no leaf maps
|
|
78
|
+
* to `inputType`. A fresh array.
|
|
64
79
|
*/
|
|
80
|
+
export declare function measuresForInputType(inputType: string): MeasureProto[];
|
|
81
|
+
/** @deprecated Use measuresForInputType. Removed in a later release (LM-418). */
|
|
65
82
|
export declare function measuresForArm(arm: string): MeasureProto[];
|
|
66
83
|
/**
|
|
67
|
-
*
|
|
84
|
+
* measuresForInputType over a given `measures` list. Exported for tests.
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
export declare function measuresForInputTypeIn(measures: ReadonlyArray<unknown>, inputType: string): MeasureProto[];
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use measuresForInputTypeIn. Removed in a later release (LM-418).
|
|
68
90
|
* @internal
|
|
69
91
|
*/
|
|
70
92
|
export declare function measuresForArmIn(measures: ReadonlyArray<unknown>, arm: string): MeasureProto[];
|
|
93
|
+
/** @deprecated Use ValuationInputTypes. Removed in a later release (LM-418). */
|
|
94
|
+
export declare const ValuationArms: typeof ValuationInputTypes;
|
|
95
|
+
/** @deprecated Use ValuationInputTypes. Removed in a later release (LM-418). */
|
|
96
|
+
export type ValuationArms = ValuationInputTypes;
|
|
97
|
+
/** @deprecated Use parseValuationInputTypes. Removed in a later release (LM-418). */
|
|
98
|
+
export declare function parseValuationArms(section: unknown): ValuationInputTypes;
|
|
99
|
+
/** @deprecated Use shippedValuationInputTypes. Removed in a later release (LM-418). */
|
|
100
|
+
export declare function shippedValuationArms(): ValuationInputTypes;
|
|
71
101
|
/**
|
|
72
102
|
* Market data for forSecurity, one field per MarketDataKind: CPI_U is `cpi`,
|
|
73
|
-
* FRN_FIXINGS is `fixings`, FRN_CURVE is `curve`. Each is copied to the
|
|
103
|
+
* FRN_FIXINGS is `fixings`, FRN_CURVE is `curve`. Each is copied to the input type
|
|
74
104
|
* field of the same name (TipsInput.cpi, FrnInput.fixings, FrnInput.curve)
|
|
75
|
-
* when the
|
|
105
|
+
* when the input type has one; the others are ignored.
|
|
76
106
|
*/
|
|
77
107
|
export interface MarketData {
|
|
78
108
|
cpi?: InflationIndexInput;
|
|
@@ -80,19 +110,19 @@ export interface MarketData {
|
|
|
80
110
|
curve?: YieldCurveInput;
|
|
81
111
|
}
|
|
82
112
|
/**
|
|
83
|
-
* The ProductInput for `security`, in the
|
|
113
|
+
* The ProductInput for `security`, in the input type inputTypeFor picks.
|
|
84
114
|
*
|
|
85
|
-
* Sets the
|
|
115
|
+
* Sets the input type's security and copies price.price as is into clean_price
|
|
86
116
|
* (bond, tips, frn, mbs) or unit_price (equity, cash). Never sets
|
|
87
|
-
* cost_basis. Throws UnmappedProductTypeError when the type has no
|
|
88
|
-
* MissingMarketDataError when `marketData` lacks a kind the
|
|
117
|
+
* cost_basis. Throws UnmappedProductTypeError when the type has no input type and
|
|
118
|
+
* MissingMarketDataError when `marketData` lacks a kind the input type requires.
|
|
89
119
|
* The caller's protos are set as they are, not copied or stamped (LM-322).
|
|
90
120
|
*/
|
|
91
121
|
export declare function forSecurity(security: SecurityProto, price: PriceProto, marketData?: MarketData | null): ProductInput;
|
|
92
122
|
/**
|
|
93
|
-
* Checks `productInput` is the
|
|
94
|
-
* every market-data kind that
|
|
95
|
-
*
|
|
123
|
+
* Checks `productInput` is the input type inputTypeFor picks for its security, and holds
|
|
124
|
+
* every market-data kind that input type requires. Throws ModelValidationError (no
|
|
125
|
+
* input type, or the wrong input type), UnmappedProductTypeError or MissingMarketDataError.
|
|
96
126
|
*/
|
|
97
127
|
export declare function checkProductInput(productInput: ProductInput): void;
|
|
98
128
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
/**
|
|
27
|
+
* LM-418: the deprecated arm-named exports give the same results as the
|
|
28
|
+
* input-type names they call, and hierarchy.json still loads with the legacy
|
|
29
|
+
* valuation_arms / arm keys for one release.
|
|
30
|
+
*/
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const product_inputs_1 = require("./product_inputs");
|
|
34
|
+
const errors_1 = require("../errors");
|
|
35
|
+
const price_pb_1 = require("../../../fintekkers/models/price/price_pb");
|
|
36
|
+
const coupon_type_pb_1 = require("../../../fintekkers/models/security/coupon_type_pb");
|
|
37
|
+
const product_type_pb_1 = require("../../../fintekkers/models/security/product_type_pb");
|
|
38
|
+
const security_pb_1 = require("../../../fintekkers/models/security/security_pb");
|
|
39
|
+
const REPO = path.resolve(__dirname, '../../../../..');
|
|
40
|
+
function readJson(...parts) {
|
|
41
|
+
return JSON.parse(fs.readFileSync(path.join(REPO, ...parts), 'utf-8'));
|
|
42
|
+
}
|
|
43
|
+
/** The value, or the thrown error's class and message. */
|
|
44
|
+
function outcome(call) {
|
|
45
|
+
try {
|
|
46
|
+
return call();
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
return [e.constructor.name, e.message];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** `root` with the section and entry keys renamed to the legacy names. */
|
|
53
|
+
function legacy(root) {
|
|
54
|
+
const out = JSON.parse(JSON.stringify(root));
|
|
55
|
+
const section = out.valuation_input_types;
|
|
56
|
+
delete out.valuation_input_types;
|
|
57
|
+
for (const entry of section.entries) {
|
|
58
|
+
entry.arm = entry.input_type;
|
|
59
|
+
delete entry.input_type;
|
|
60
|
+
}
|
|
61
|
+
out.valuation_arms = section;
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
// ---------- metric 2: the aliases match the new names ----------
|
|
65
|
+
describe('armFor matches inputTypeFor on every fixture case', () => {
|
|
66
|
+
const cases = readJson('ledger-models-protos', 'fixtures', 'valuation_input_types_cases.json').cases;
|
|
67
|
+
const priced = cases.filter(c => Object.prototype.hasOwnProperty.call(product_type_pb_1.ProductTypeProto, c.product_type));
|
|
68
|
+
test('there are enough cases', () => expect(priced.length).toBeGreaterThanOrEqual(5));
|
|
69
|
+
test.each(priced)('$product_type/$coupon_type', c => {
|
|
70
|
+
const s = new security_pb_1.SecurityProto()
|
|
71
|
+
.setProductType(product_type_pb_1.ProductTypeProto[c.product_type])
|
|
72
|
+
.setBondDetails(new security_pb_1.BondDetailsProto()
|
|
73
|
+
.setCouponType(coupon_type_pb_1.CouponTypeProto[c.coupon_type]));
|
|
74
|
+
const expected = outcome(() => (0, product_inputs_1.inputTypeFor)(s));
|
|
75
|
+
expect(outcome(() => (0, product_inputs_1.armFor)(s))).toEqual(expected);
|
|
76
|
+
if (c.input_type !== undefined)
|
|
77
|
+
expect(expected).toBe(c.input_type);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe('measuresForArm matches measuresForInputType', () => {
|
|
81
|
+
const fixture = readJson('test-fixtures', 'catalog', 'measures-for-input-type.json');
|
|
82
|
+
const inputTypes = [...Object.keys(fixture.input_types), fixture.unknown_input_type];
|
|
83
|
+
const catalog = readJson('ledger-models-protos', 'catalog', 'measures.json').measures;
|
|
84
|
+
test.each(inputTypes)('%s', inputType => {
|
|
85
|
+
expect(outcome(() => (0, product_inputs_1.measuresForArm)(inputType))).toEqual(outcome(() => (0, product_inputs_1.measuresForInputType)(inputType)));
|
|
86
|
+
expect(outcome(() => (0, product_inputs_1.measuresForArmIn)(catalog, inputType)))
|
|
87
|
+
.toEqual(outcome(() => (0, product_inputs_1.measuresForInputTypeIn)(catalog, inputType)));
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
test('the ValuationArms aliases are the ValuationInputTypes ones', () => {
|
|
91
|
+
const section = readJson('ledger-models-protos', 'hierarchy.json').valuation_input_types;
|
|
92
|
+
expect(product_inputs_1.ValuationArms).toBe(product_inputs_1.ValuationInputTypes);
|
|
93
|
+
const parsed = (0, product_inputs_1.parseValuationArms)(section);
|
|
94
|
+
expect(parsed).toBeInstanceOf(product_inputs_1.ValuationInputTypes);
|
|
95
|
+
expect(parsed).toEqual((0, product_inputs_1.parseValuationInputTypes)(section));
|
|
96
|
+
expect((0, product_inputs_1.shippedValuationArms)()).toBe((0, product_inputs_1.shippedValuationInputTypes)());
|
|
97
|
+
const entry = (0, product_inputs_1.shippedValuationInputTypes)().require('TIPS', 'FIXED');
|
|
98
|
+
expect(entry.arm).toBe(entry.inputType);
|
|
99
|
+
expect(entry.inputType).toBe('tips');
|
|
100
|
+
});
|
|
101
|
+
test('MissingMarketDataError.arm matches inputType', () => {
|
|
102
|
+
const tips = new security_pb_1.SecurityProto().setProductType(product_type_pb_1.ProductTypeProto.TIPS);
|
|
103
|
+
let e;
|
|
104
|
+
try {
|
|
105
|
+
(0, product_inputs_1.forSecurity)(tips, new price_pb_1.PriceProto());
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
e = err;
|
|
109
|
+
}
|
|
110
|
+
expect(e).toBeInstanceOf(errors_1.MissingMarketDataError);
|
|
111
|
+
const m = e;
|
|
112
|
+
expect(m.inputType).toBe('tips');
|
|
113
|
+
expect(m.arm).toBe(m.inputType);
|
|
114
|
+
expect(m.message).toContain('for input type tips');
|
|
115
|
+
});
|
|
116
|
+
// ---------- metric 3: the legacy keys load the same mapping ----------
|
|
117
|
+
test('the legacy keys load the same mapping', () => {
|
|
118
|
+
const root = readJson('ledger-models-protos', 'hierarchy.json');
|
|
119
|
+
expect(root.valuation_input_types.entries).toHaveLength(8);
|
|
120
|
+
const current = (0, product_inputs_1.valuationInputTypesFromHierarchy)(root);
|
|
121
|
+
const old = (0, product_inputs_1.valuationInputTypesFromHierarchy)(legacy(root));
|
|
122
|
+
expect(old).toEqual(current);
|
|
123
|
+
expect(current).toEqual((0, product_inputs_1.shippedValuationInputTypes)());
|
|
124
|
+
expect(old.uncoveredLeaves()).toEqual(current.uncoveredLeaves());
|
|
125
|
+
});
|
|
126
|
+
const breaks = [
|
|
127
|
+
['both root keys', r => { r.valuation_arms = JSON.parse(JSON.stringify(r.valuation_input_types)); }],
|
|
128
|
+
['neither root key', r => { delete r.valuation_input_types; }],
|
|
129
|
+
['an entry with both fields', r => { r.valuation_input_types.entries[0].arm = 'bond'; }],
|
|
130
|
+
];
|
|
131
|
+
test.each(breaks)('%s is rejected', (_name, brk) => {
|
|
132
|
+
const root = readJson('ledger-models-protos', 'hierarchy.json');
|
|
133
|
+
brk(root);
|
|
134
|
+
expect(() => (0, product_inputs_1.valuationInputTypesFromHierarchy)(root)).toThrow(/valuation_input_types/);
|
|
135
|
+
});
|
|
136
|
+
//# sourceMappingURL=product_inputs.deprecated.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product_inputs.deprecated.test.js","sourceRoot":"","sources":["product_inputs.deprecated.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,uCAAyB;AACzB,2CAA6B;AAE7B,qDAI0B;AAC1B,sCAAmD;AACnD,wEAAuE;AACvE,uFAAqF;AACrF,yFAAuF;AACvF,iFAAkG;AAElG,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAEvD,SAAS,QAAQ,CAAC,GAAG,KAAe;IAClC,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,0DAA0D;AAC1D,SAAS,OAAO,CAAC,IAAmB;IAClC,IAAI;QACF,OAAO,IAAI,EAAE,CAAC;KACf;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAE,CAAW,CAAC,WAAW,CAAC,IAAI,EAAG,CAAW,CAAC,OAAO,CAAC,CAAC;KAC9D;AACH,CAAC;AAED,0EAA0E;AAC1E,SAAS,MAAM,CAAC,IAAS;I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C,EAAE,GAAG,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;CACzF,CAAC;AAEF,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACjD,MAAM,IAAI,GAAG,QAAQ,CAAC,sBAAsB,EAAE,gBAAgB,CAAC,CAAC;IAChE,GAAG,CAAC,IAAI,CAAC,CAAC;IACV,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,iDAAgC,EAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACxF,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LM-418: the deprecated arm-named exports give the same results as the
|
|
3
|
+
* input-type names they call, and hierarchy.json still loads with the legacy
|
|
4
|
+
* valuation_arms / arm keys for one release.
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
armFor, forSecurity, inputTypeFor, measuresForArm, measuresForArmIn, measuresForInputType,
|
|
11
|
+
measuresForInputTypeIn, parseValuationArms, parseValuationInputTypes, shippedValuationArms,
|
|
12
|
+
shippedValuationInputTypes, valuationInputTypesFromHierarchy, ValuationArms, ValuationInputTypes,
|
|
13
|
+
} from './product_inputs';
|
|
14
|
+
import { MissingMarketDataError } from '../errors';
|
|
15
|
+
import { PriceProto } from '../../../fintekkers/models/price/price_pb';
|
|
16
|
+
import { CouponTypeProto } from '../../../fintekkers/models/security/coupon_type_pb';
|
|
17
|
+
import { ProductTypeProto } from '../../../fintekkers/models/security/product_type_pb';
|
|
18
|
+
import { BondDetailsProto, SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
19
|
+
|
|
20
|
+
const REPO = path.resolve(__dirname, '../../../../..');
|
|
21
|
+
|
|
22
|
+
function readJson(...parts: string[]): any {
|
|
23
|
+
return JSON.parse(fs.readFileSync(path.join(REPO, ...parts), 'utf-8'));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The value, or the thrown error's class and message. */
|
|
27
|
+
function outcome(call: () => unknown): unknown {
|
|
28
|
+
try {
|
|
29
|
+
return call();
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return [(e as Error).constructor.name, (e as Error).message];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** `root` with the section and entry keys renamed to the legacy names. */
|
|
36
|
+
function legacy(root: any): any {
|
|
37
|
+
const out = JSON.parse(JSON.stringify(root));
|
|
38
|
+
const section = out.valuation_input_types;
|
|
39
|
+
delete out.valuation_input_types;
|
|
40
|
+
for (const entry of section.entries) {
|
|
41
|
+
entry.arm = entry.input_type;
|
|
42
|
+
delete entry.input_type;
|
|
43
|
+
}
|
|
44
|
+
out.valuation_arms = section;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ---------- metric 2: the aliases match the new names ----------
|
|
49
|
+
|
|
50
|
+
describe('armFor matches inputTypeFor on every fixture case', () => {
|
|
51
|
+
const cases: { product_type: string; coupon_type: string; input_type?: string }[] =
|
|
52
|
+
readJson('ledger-models-protos', 'fixtures', 'valuation_input_types_cases.json').cases;
|
|
53
|
+
const priced = cases.filter(c => Object.prototype.hasOwnProperty.call(ProductTypeProto, c.product_type));
|
|
54
|
+
|
|
55
|
+
test('there are enough cases', () => expect(priced.length).toBeGreaterThanOrEqual(5));
|
|
56
|
+
|
|
57
|
+
test.each(priced)('$product_type/$coupon_type', c => {
|
|
58
|
+
const s = new SecurityProto()
|
|
59
|
+
.setProductType((ProductTypeProto as unknown as Record<string, number>)[c.product_type])
|
|
60
|
+
.setBondDetails(new BondDetailsProto()
|
|
61
|
+
.setCouponType((CouponTypeProto as unknown as Record<string, number>)[c.coupon_type]));
|
|
62
|
+
const expected = outcome(() => inputTypeFor(s));
|
|
63
|
+
expect(outcome(() => armFor(s))).toEqual(expected);
|
|
64
|
+
if (c.input_type !== undefined) expect(expected).toBe(c.input_type);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('measuresForArm matches measuresForInputType', () => {
|
|
69
|
+
const fixture: { input_types: Record<string, string[]>; unknown_input_type: string } =
|
|
70
|
+
readJson('test-fixtures', 'catalog', 'measures-for-input-type.json');
|
|
71
|
+
const inputTypes = [...Object.keys(fixture.input_types), fixture.unknown_input_type];
|
|
72
|
+
const catalog = readJson('ledger-models-protos', 'catalog', 'measures.json').measures;
|
|
73
|
+
|
|
74
|
+
test.each(inputTypes)('%s', inputType => {
|
|
75
|
+
expect(outcome(() => measuresForArm(inputType))).toEqual(outcome(() => measuresForInputType(inputType)));
|
|
76
|
+
expect(outcome(() => measuresForArmIn(catalog, inputType)))
|
|
77
|
+
.toEqual(outcome(() => measuresForInputTypeIn(catalog, inputType)));
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('the ValuationArms aliases are the ValuationInputTypes ones', () => {
|
|
82
|
+
const section = readJson('ledger-models-protos', 'hierarchy.json').valuation_input_types;
|
|
83
|
+
expect(ValuationArms).toBe(ValuationInputTypes);
|
|
84
|
+
const parsed: ValuationArms = parseValuationArms(section);
|
|
85
|
+
expect(parsed).toBeInstanceOf(ValuationInputTypes);
|
|
86
|
+
expect(parsed).toEqual(parseValuationInputTypes(section));
|
|
87
|
+
expect(shippedValuationArms()).toBe(shippedValuationInputTypes());
|
|
88
|
+
const entry = shippedValuationInputTypes().require('TIPS', 'FIXED');
|
|
89
|
+
expect(entry.arm).toBe(entry.inputType);
|
|
90
|
+
expect(entry.inputType).toBe('tips');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('MissingMarketDataError.arm matches inputType', () => {
|
|
94
|
+
const tips = new SecurityProto().setProductType(ProductTypeProto.TIPS);
|
|
95
|
+
let e: unknown;
|
|
96
|
+
try {
|
|
97
|
+
forSecurity(tips, new PriceProto());
|
|
98
|
+
} catch (err) {
|
|
99
|
+
e = err;
|
|
100
|
+
}
|
|
101
|
+
expect(e).toBeInstanceOf(MissingMarketDataError);
|
|
102
|
+
const m = e as MissingMarketDataError;
|
|
103
|
+
expect(m.inputType).toBe('tips');
|
|
104
|
+
expect(m.arm).toBe(m.inputType);
|
|
105
|
+
expect(m.message).toContain('for input type tips');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// ---------- metric 3: the legacy keys load the same mapping ----------
|
|
109
|
+
|
|
110
|
+
test('the legacy keys load the same mapping', () => {
|
|
111
|
+
const root = readJson('ledger-models-protos', 'hierarchy.json');
|
|
112
|
+
expect(root.valuation_input_types.entries).toHaveLength(8);
|
|
113
|
+
const current = valuationInputTypesFromHierarchy(root);
|
|
114
|
+
const old = valuationInputTypesFromHierarchy(legacy(root));
|
|
115
|
+
expect(old).toEqual(current);
|
|
116
|
+
expect(current).toEqual(shippedValuationInputTypes());
|
|
117
|
+
expect(old.uncoveredLeaves()).toEqual(current.uncoveredLeaves());
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const breaks: [string, (root: any) => void][] = [
|
|
121
|
+
['both root keys', r => { r.valuation_arms = JSON.parse(JSON.stringify(r.valuation_input_types)); }],
|
|
122
|
+
['neither root key', r => { delete r.valuation_input_types; }],
|
|
123
|
+
['an entry with both fields', r => { r.valuation_input_types.entries[0].arm = 'bond'; }],
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
test.each(breaks)('%s is rejected', (_name, brk) => {
|
|
127
|
+
const root = readJson('ledger-models-protos', 'hierarchy.json');
|
|
128
|
+
brk(root);
|
|
129
|
+
expect(() => valuationInputTypesFromHierarchy(root)).toThrow(/valuation_input_types/);
|
|
130
|
+
});
|