@fintekkers/ledger-models 1.1.20 → 1.1.21
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 +19 -2
- package/node/wrappers/models/errors.d.ts +12 -0
- package/node/wrappers/models/errors.js +17 -1
- package/node/wrappers/models/errors.js.map +1 -1
- package/node/wrappers/models/errors.ts +19 -0
- package/node/wrappers/models/security/product_inputs.d.ts +46 -0
- package/node/wrappers/models/security/product_inputs.js +189 -0
- package/node/wrappers/models/security/product_inputs.js.map +1 -0
- package/node/wrappers/models/security/product_inputs.test.d.ts +1 -0
- package/node/wrappers/models/security/product_inputs.test.js +144 -0
- package/node/wrappers/models/security/product_inputs.test.js.map +1 -0
- package/node/wrappers/models/security/product_inputs.test.ts +141 -0
- package/node/wrappers/models/security/product_inputs.ts +193 -0
- package/package.json +1 -1
package/hierarchy.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"schema_version": "1.
|
|
3
|
-
"_doc": "Single source of truth for the FinTekkers product hierarchy. See ../docs/product-hierarchy.md for narrative description, hierarchy-examples.md for worked examples, and registry-versioning.md for compatibility rules. Each leaf product_type carries (asset_class, instrument_type). Abstract nodes carry only hierarchy. status=active entries must have a matching ProductTypeProto enum value (CI-enforced). status=planned entries are aspirational and not yet wired into the proto enum. NOTE: M1 ships a 3-dimensional registry (productType + asset_class + instrument_type). The 4th dimension (index_type — single_name vs index) is intentionally deferred and will be added in a future milestone. Option strategy leaves (butterfly, vertical spread, calendar spread, condor, straddle, ...) are also intentionally absent — strategies are derived from the legs field on SecurityProto, not from a productType enum value. asset_classes is the one canonical asset-class vocabulary (codes and tree); an entry's optional aliases list names legacy values that resolve to it. instrument_types maps each instrument-type code to {label}, in display order; every code must have a matching INSTRUMENT_TYPE_<CODE> InstrumentTypeProto value (checked at load), and that enum value takes its label from here. enum_labels holds display labels (and identifier-type input placeholders) for proto enum values with no entry elsewhere, keyed by proto enum name then value name. See ../docs/adr/asset_class_vocabulary.md.",
|
|
2
|
+
"schema_version": "1.3",
|
|
3
|
+
"_doc": "Single source of truth for the FinTekkers product hierarchy. See ../docs/product-hierarchy.md for narrative description, hierarchy-examples.md for worked examples, and registry-versioning.md for compatibility rules. Each leaf product_type carries (asset_class, instrument_type). Abstract nodes carry only hierarchy. status=active entries must have a matching ProductTypeProto enum value (CI-enforced). status=planned entries are aspirational and not yet wired into the proto enum. NOTE: M1 ships a 3-dimensional registry (productType + asset_class + instrument_type). The 4th dimension (index_type — single_name vs index) is intentionally deferred and will be added in a future milestone. Option strategy leaves (butterfly, vertical spread, calendar spread, condor, straddle, ...) are also intentionally absent — strategies are derived from the legs field on SecurityProto, not from a productType enum value. asset_classes is the one canonical asset-class vocabulary (codes and tree); an entry's optional aliases list names legacy values that resolve to it. instrument_types maps each instrument-type code to {label}, in display order; every code must have a matching INSTRUMENT_TYPE_<CODE> InstrumentTypeProto value (checked at load), and that enum value takes its label from here. enum_labels holds display labels (and identifier-type input placeholders) for proto enum values with no entry elsewhere, keyed by proto enum name then value name. See ../docs/adr/asset_class_vocabulary.md. valuation_arms maps a product_type node, optionally narrowed by coupon_types, to its ProductInput arm and the market data it requires; unpriced lists nodes with no arm. The deepest matching node wins; see ../docs/adr/valuation_arms.md.",
|
|
4
4
|
|
|
5
5
|
"product_types": {
|
|
6
6
|
"BOND": { "parent": null, "abstract": true, "label": "Bond" },
|
|
@@ -156,5 +156,22 @@
|
|
|
156
156
|
"UNKNOWN_ASSET_CLASS": { "label": "Unknown" },
|
|
157
157
|
"INDEX": { "label": "Index" }
|
|
158
158
|
}
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
"valuation_arms": {
|
|
162
|
+
"entries": [
|
|
163
|
+
{ "node": "BOND", "arm": "bond", "requires": [] },
|
|
164
|
+
{ "node": "BOND", "coupon_types": ["FLOAT"], "arm": "frn", "requires": ["FRN_FIXINGS"] },
|
|
165
|
+
{ "node": "TIPS", "arm": "tips", "requires": ["CPI_U"] },
|
|
166
|
+
{ "node": "TREASURY_FRN", "arm": "frn", "requires": ["FRN_FIXINGS"] },
|
|
167
|
+
{ "node": "MORTGAGE_BACKED", "arm": "mbs", "requires": [] },
|
|
168
|
+
{ "node": "STOCK", "arm": "equity", "requires": [] },
|
|
169
|
+
{ "node": "CURRENCY", "arm": "cash", "requires": [] },
|
|
170
|
+
{ "node": "MONEY_MARKET_FUND", "arm": "cash", "requires": [] }
|
|
171
|
+
],
|
|
172
|
+
"unpriced": [
|
|
173
|
+
"FX_SPOT", "INDEX", "CRYPTO", "COMMODITY_SPOT", "FUTURE", "OPTION", "SWAP", "FORWARD",
|
|
174
|
+
"FINANCING", "FUND_LP", "CMBS", "ABS", "CLO", "CONVERTIBLE_BOND", "COCO"
|
|
175
|
+
]
|
|
159
176
|
}
|
|
160
177
|
}
|
|
@@ -15,5 +15,17 @@ export declare class ModelValidationError extends Error {
|
|
|
15
15
|
/** UUID string of the object that owns the first bad field, or undefined if unset. */
|
|
16
16
|
get objectId(): string | undefined;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Typed input error: the security's product_type (and coupon_type) has no
|
|
20
|
+
* valuation arm in hierarchy.json valuation_arms, or is listed there as
|
|
21
|
+
* unpriced. Services map it to gRPC INVALID_ARGUMENT. A sibling of
|
|
22
|
+
* ModelValidationError, not a state error (docs/adr/valuation_arms.md).
|
|
23
|
+
*/
|
|
24
|
+
export declare class UnmappedProductTypeError extends Error {
|
|
25
|
+
readonly productType: string;
|
|
26
|
+
readonly couponType: string;
|
|
27
|
+
/** @param productType ProductTypeProto name; @param couponType CouponTypeProto name */
|
|
28
|
+
constructor(productType: string, couponType: string);
|
|
29
|
+
}
|
|
18
30
|
/** Builds one violation. `objectId` may be undefined when the input had no UUID. */
|
|
19
31
|
export declare function violation(field: string, objectId: UUID | undefined, message: string): FieldViolationProto;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.violation = exports.ModelValidationError = void 0;
|
|
3
|
+
exports.violation = exports.UnmappedProductTypeError = exports.ModelValidationError = void 0;
|
|
4
4
|
const field_violation_pb_1 = require("../../fintekkers/requests/util/errors/field_violation_pb");
|
|
5
5
|
const uuid_1 = require("./utils/uuid");
|
|
6
6
|
/**
|
|
@@ -31,6 +31,22 @@ class ModelValidationError extends Error {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
exports.ModelValidationError = ModelValidationError;
|
|
34
|
+
/**
|
|
35
|
+
* Typed input error: the security's product_type (and coupon_type) has no
|
|
36
|
+
* valuation arm in hierarchy.json valuation_arms, or is listed there as
|
|
37
|
+
* unpriced. Services map it to gRPC INVALID_ARGUMENT. A sibling of
|
|
38
|
+
* ModelValidationError, not a state error (docs/adr/valuation_arms.md).
|
|
39
|
+
*/
|
|
40
|
+
class UnmappedProductTypeError extends Error {
|
|
41
|
+
/** @param productType ProductTypeProto name; @param couponType CouponTypeProto name */
|
|
42
|
+
constructor(productType, couponType) {
|
|
43
|
+
super(`No valuation arm for product_type ${productType}, coupon_type ${couponType}`);
|
|
44
|
+
this.name = 'UnmappedProductTypeError';
|
|
45
|
+
this.productType = productType;
|
|
46
|
+
this.couponType = couponType;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.UnmappedProductTypeError = UnmappedProductTypeError;
|
|
34
50
|
/** Builds one violation. `objectId` may be undefined when the input had no UUID. */
|
|
35
51
|
function violation(field, objectId, message) {
|
|
36
52
|
const v = new field_violation_pb_1.FieldViolationProto();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,iGAA+F;AAC/F,uCAAoC;AAEpC;;;;;GAKG;AACH,MAAa,oBAAqB,SAAQ,KAAK;IAG3C,yEAAyE;IACzE,YAAY,UAAiC;QACzC,IAAI,UAAU,CAAC,MAAM,KAAK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AC,CAAC;QACrF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;CACJ;AAXD,4DAWC;AAED,oFAAoF;AACpF,SAAgB,SAAS,CAAC,KAAa,EAAE,QAA0B,EAAE,OAAe;IAChF,MAAM,CAAC,GAAG,IAAI,wCAAmB,EAAE,CAAC;IACpC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACtB,IAAI,QAAQ;QAAE,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IACpD,OAAO,CAAC,CAAC;AACb,CAAC;AAND,8BAMC;AAED,SAAS,UAAU,CAAC,CAAsB;;IACtC,MAAM,GAAG,GAAG,MAAA,CAAC,CAAC,WAAW,EAAE,0CAAE,eAAe,EAAE,CAAC;IAC/C,iFAAiF;IACjF,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,WAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACnF,CAAC"}
|
|
@@ -33,6 +33,25 @@ export class ModelValidationError extends Error {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Typed input error: the security's product_type (and coupon_type) has no
|
|
38
|
+
* valuation arm in hierarchy.json valuation_arms, or is listed there as
|
|
39
|
+
* unpriced. Services map it to gRPC INVALID_ARGUMENT. A sibling of
|
|
40
|
+
* ModelValidationError, not a state error (docs/adr/valuation_arms.md).
|
|
41
|
+
*/
|
|
42
|
+
export class UnmappedProductTypeError extends Error {
|
|
43
|
+
readonly productType: string;
|
|
44
|
+
readonly couponType: string;
|
|
45
|
+
|
|
46
|
+
/** @param productType ProductTypeProto name; @param couponType CouponTypeProto name */
|
|
47
|
+
constructor(productType: string, couponType: string) {
|
|
48
|
+
super(`No valuation arm for product_type ${productType}, coupon_type ${couponType}`);
|
|
49
|
+
this.name = 'UnmappedProductTypeError';
|
|
50
|
+
this.productType = productType;
|
|
51
|
+
this.couponType = couponType;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
36
55
|
/** Builds one violation. `objectId` may be undefined when the input had no UUID. */
|
|
37
56
|
export function violation(field: string, objectId: UUID | undefined, message: string): FieldViolationProto {
|
|
38
57
|
const v = new FieldViolationProto();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which ProductInput arm values a security, and which market data that arm
|
|
3
|
+
* needs. Backed by the valuation_arms section of
|
|
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/valuation_arms.md.
|
|
6
|
+
*
|
|
7
|
+
* Resolution walks from the security's product_type up its parent chain. At
|
|
8
|
+
* each node a coupon_types entry matching bond_details.coupon_type wins, then
|
|
9
|
+
* the node's plain entry, then an unpriced listing. The first node with any
|
|
10
|
+
* match decides. No match, or an unpriced match, throws
|
|
11
|
+
* UnmappedProductTypeError: there is no default arm. A broken section throws
|
|
12
|
+
* a plain Error at load, like product_hierarchy.
|
|
13
|
+
*/
|
|
14
|
+
import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
15
|
+
/** The closed requires vocabulary: market data an arm needs beyond the price. */
|
|
16
|
+
export type MarketDataKind = 'CPI_U' | 'FRN_FIXINGS' | 'FRN_CURVE';
|
|
17
|
+
interface Arm {
|
|
18
|
+
arm: string;
|
|
19
|
+
requires: ReadonlyArray<MarketDataKind>;
|
|
20
|
+
}
|
|
21
|
+
/** A parsed, checked valuation_arms section. */
|
|
22
|
+
export declare class ValuationArms {
|
|
23
|
+
private readonly entries;
|
|
24
|
+
private readonly unpriced;
|
|
25
|
+
/** @param entries node -> coupon type name (or '' for the plain entry) -> arm */
|
|
26
|
+
constructor(entries: Map<string, Map<string, Arm>>, unpriced: ReadonlySet<string>);
|
|
27
|
+
/** The deepest matching node's arm, or null when unmapped or unpriced. */
|
|
28
|
+
resolve(productType: string, couponType: string): Arm | null;
|
|
29
|
+
require(productType: string, couponType: string): Arm;
|
|
30
|
+
/** Leaf product types (active and planned) with neither an entry nor an unpriced listing. */
|
|
31
|
+
uncoveredLeaves(): string[];
|
|
32
|
+
private covers;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parses and checks a valuation_arms section against the shipped
|
|
36
|
+
* product_types tree, the ProductInput oneof and the CouponTypeProto /
|
|
37
|
+
* MarketDataKind vocabularies. Throws on any failure. Exported for tests.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseValuationArms(section: unknown): ValuationArms;
|
|
40
|
+
/** The shipped valuation_arms section, parsed and checked on first use. Exported for tests. */
|
|
41
|
+
export declare function shippedValuationArms(): ValuationArms;
|
|
42
|
+
/** Name of the ProductInput.input oneof field that values `security`, e.g. 'tips'. */
|
|
43
|
+
export declare function armFor(security: SecurityProto): string;
|
|
44
|
+
/** Market data the security's arm needs, in file order. A fresh array; empty when none. */
|
|
45
|
+
export declare function requiredMarketData(security: SecurityProto): MarketDataKind[];
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Which ProductInput arm values a security, and which market data that arm
|
|
4
|
+
* needs. Backed by the valuation_arms section of
|
|
5
|
+
* ledger-models-protos/hierarchy.json; there is no mapping table in code.
|
|
6
|
+
* Same rule in Java / Rust / Python / JS-TS. See docs/adr/valuation_arms.md.
|
|
7
|
+
*
|
|
8
|
+
* Resolution walks from the security's product_type up its parent chain. At
|
|
9
|
+
* each node a coupon_types entry matching bond_details.coupon_type wins, then
|
|
10
|
+
* the node's plain entry, then an unpriced listing. The first node with any
|
|
11
|
+
* match decides. No match, or an unpriced match, throws
|
|
12
|
+
* UnmappedProductTypeError: there is no default arm. A broken section throws
|
|
13
|
+
* a plain Error at load, like product_hierarchy.
|
|
14
|
+
*/
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.requiredMarketData = exports.armFor = exports.shippedValuationArms = exports.parseValuationArms = exports.ValuationArms = void 0;
|
|
20
|
+
const hierarchy_json_1 = __importDefault(require("../../../../hierarchy.json"));
|
|
21
|
+
const coupon_type_pb_1 = require("../../../fintekkers/models/security/coupon_type_pb");
|
|
22
|
+
const product_type_pb_1 = require("../../../fintekkers/models/security/product_type_pb");
|
|
23
|
+
const product_inputs_pb_1 = require("../../../fintekkers/requests/valuation/product_inputs_pb");
|
|
24
|
+
const errors_1 = require("../errors");
|
|
25
|
+
const product_hierarchy_1 = require("./product_hierarchy");
|
|
26
|
+
const MARKET_DATA_KINDS = ['CPI_U', 'FRN_FIXINGS', 'FRN_CURVE'];
|
|
27
|
+
/** Map key for a node's entry with no coupon_types. */
|
|
28
|
+
const ANY_COUPON = '';
|
|
29
|
+
function hasOwn(o, key) {
|
|
30
|
+
return Object.prototype.hasOwnProperty.call(o, key);
|
|
31
|
+
}
|
|
32
|
+
function enumName(e, value) {
|
|
33
|
+
for (const [k, v] of Object.entries(e)) {
|
|
34
|
+
if (v === value)
|
|
35
|
+
return k;
|
|
36
|
+
}
|
|
37
|
+
return String(value);
|
|
38
|
+
}
|
|
39
|
+
/** A parsed, checked valuation_arms section. */
|
|
40
|
+
class ValuationArms {
|
|
41
|
+
/** @param entries node -> coupon type name (or '' for the plain entry) -> arm */
|
|
42
|
+
constructor(entries, unpriced) {
|
|
43
|
+
this.entries = entries;
|
|
44
|
+
this.unpriced = unpriced;
|
|
45
|
+
}
|
|
46
|
+
/** The deepest matching node's arm, or null when unmapped or unpriced. */
|
|
47
|
+
resolve(productType, couponType) {
|
|
48
|
+
var _a;
|
|
49
|
+
for (let node = productType; node !== null; node = (0, product_hierarchy_1.parentOf)(node)) {
|
|
50
|
+
const byCoupon = this.entries.get(node);
|
|
51
|
+
const arm = (_a = byCoupon === null || byCoupon === void 0 ? void 0 : byCoupon.get(couponType)) !== null && _a !== void 0 ? _a : byCoupon === null || byCoupon === void 0 ? void 0 : byCoupon.get(ANY_COUPON);
|
|
52
|
+
if (arm)
|
|
53
|
+
return arm;
|
|
54
|
+
if (this.unpriced.has(node))
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
require(productType, couponType) {
|
|
60
|
+
const arm = this.resolve(productType, couponType);
|
|
61
|
+
if (!arm)
|
|
62
|
+
throw new errors_1.UnmappedProductTypeError(productType, couponType);
|
|
63
|
+
return arm;
|
|
64
|
+
}
|
|
65
|
+
/** Leaf product types (active and planned) with neither an entry nor an unpriced listing. */
|
|
66
|
+
uncoveredLeaves() {
|
|
67
|
+
return (0, product_hierarchy_1.allProductTypes)().filter(n => (0, product_hierarchy_1.descendantsOf)(n).length === 0 && !this.covers(n));
|
|
68
|
+
}
|
|
69
|
+
covers(productType) {
|
|
70
|
+
for (let node = productType; node !== null; node = (0, product_hierarchy_1.parentOf)(node)) {
|
|
71
|
+
if (this.entries.has(node) || this.unpriced.has(node))
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.ValuationArms = ValuationArms;
|
|
78
|
+
function bad(detail) {
|
|
79
|
+
return new Error(`hierarchy.json valuation_arms: ${detail}`);
|
|
80
|
+
}
|
|
81
|
+
function stringOf(body, key) {
|
|
82
|
+
const v = body[key];
|
|
83
|
+
if (typeof v !== 'string')
|
|
84
|
+
throw bad(`'${key}' must be a string in ${JSON.stringify(body)}`);
|
|
85
|
+
return v;
|
|
86
|
+
}
|
|
87
|
+
function stringsOf(body, key) {
|
|
88
|
+
const v = body[key];
|
|
89
|
+
if (!Array.isArray(v) || !v.every(x => typeof x === 'string')) {
|
|
90
|
+
throw bad(`'${key}' must be a list of strings in ${JSON.stringify(body)}`);
|
|
91
|
+
}
|
|
92
|
+
return v;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parses and checks a valuation_arms section against the shipped
|
|
96
|
+
* product_types tree, the ProductInput oneof and the CouponTypeProto /
|
|
97
|
+
* MarketDataKind vocabularies. Throws on any failure. Exported for tests.
|
|
98
|
+
*/
|
|
99
|
+
function parseValuationArms(section) {
|
|
100
|
+
if (typeof section !== 'object' || section === null || Array.isArray(section)) {
|
|
101
|
+
throw bad('section must be an object');
|
|
102
|
+
}
|
|
103
|
+
const s = section;
|
|
104
|
+
const productTypes = new Set((0, product_hierarchy_1.allProductTypes)());
|
|
105
|
+
const arms = new Set(Object.keys(product_inputs_pb_1.ProductInput.InputCase)
|
|
106
|
+
.filter(k => k !== 'INPUT_NOT_SET')
|
|
107
|
+
.map(k => k.toLowerCase()));
|
|
108
|
+
if (!Array.isArray(s.entries))
|
|
109
|
+
throw bad("'entries' must be a list");
|
|
110
|
+
const entries = new Map();
|
|
111
|
+
for (const raw of s.entries) {
|
|
112
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
113
|
+
throw bad(`entry must be an object, got ${JSON.stringify(raw)}`);
|
|
114
|
+
}
|
|
115
|
+
const body = raw;
|
|
116
|
+
const node = stringOf(body, 'node');
|
|
117
|
+
if (!productTypes.has(node))
|
|
118
|
+
throw bad(`node '${node}' is not in product_types`);
|
|
119
|
+
const arm = stringOf(body, 'arm');
|
|
120
|
+
if (!arms.has(arm))
|
|
121
|
+
throw bad(`arm '${arm}' is not a ProductInput.input field`);
|
|
122
|
+
const requires = stringsOf(body, 'requires').map(r => {
|
|
123
|
+
if (!MARKET_DATA_KINDS.includes(r)) {
|
|
124
|
+
throw bad(`requires value '${r}' is not one of CPI_U, FRN_FIXINGS, FRN_CURVE`);
|
|
125
|
+
}
|
|
126
|
+
return r;
|
|
127
|
+
});
|
|
128
|
+
let coupons = [ANY_COUPON];
|
|
129
|
+
if (hasOwn(body, 'coupon_types')) {
|
|
130
|
+
coupons = stringsOf(body, 'coupon_types');
|
|
131
|
+
for (const c of coupons) {
|
|
132
|
+
if (!hasOwn(coupon_type_pb_1.CouponTypeProto, c))
|
|
133
|
+
throw bad(`coupon_types value '${c}' is not a CouponTypeProto name`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
let byCoupon = entries.get(node);
|
|
137
|
+
if (!byCoupon) {
|
|
138
|
+
byCoupon = new Map();
|
|
139
|
+
entries.set(node, byCoupon);
|
|
140
|
+
}
|
|
141
|
+
const value = Object.freeze({ arm, requires: Object.freeze(requires) });
|
|
142
|
+
for (const c of coupons) {
|
|
143
|
+
if (byCoupon.has(c))
|
|
144
|
+
throw bad(`duplicate entry for node ${node}${c ? `, coupon_type ${c}` : ''}`);
|
|
145
|
+
byCoupon.set(c, value);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const unpriced = new Set();
|
|
149
|
+
for (const node of stringsOf(s, 'unpriced')) {
|
|
150
|
+
if (!productTypes.has(node))
|
|
151
|
+
throw bad(`node '${node}' is not in product_types`);
|
|
152
|
+
if (entries.has(node))
|
|
153
|
+
throw bad(`node ${node} is both mapped and unpriced`);
|
|
154
|
+
unpriced.add(node);
|
|
155
|
+
}
|
|
156
|
+
return new ValuationArms(entries, unpriced);
|
|
157
|
+
}
|
|
158
|
+
exports.parseValuationArms = parseValuationArms;
|
|
159
|
+
let shippedArms;
|
|
160
|
+
/** The shipped valuation_arms section, parsed and checked on first use. Exported for tests. */
|
|
161
|
+
function shippedValuationArms() {
|
|
162
|
+
if (!shippedArms) {
|
|
163
|
+
const section = hierarchy_json_1.default.valuation_arms;
|
|
164
|
+
if (section === undefined)
|
|
165
|
+
throw bad('section missing from hierarchy.json');
|
|
166
|
+
shippedArms = parseValuationArms(section);
|
|
167
|
+
}
|
|
168
|
+
return shippedArms;
|
|
169
|
+
}
|
|
170
|
+
exports.shippedValuationArms = shippedValuationArms;
|
|
171
|
+
function productTypeOf(security) {
|
|
172
|
+
return enumName(product_type_pb_1.ProductTypeProto, security.getProductType());
|
|
173
|
+
}
|
|
174
|
+
/** Read from the proto field only; unset bond_details reads as UNKNOWN_COUPON_TYPE. */
|
|
175
|
+
function couponTypeOf(security) {
|
|
176
|
+
const details = security.getBondDetails();
|
|
177
|
+
return details ? enumName(coupon_type_pb_1.CouponTypeProto, details.getCouponType()) : 'UNKNOWN_COUPON_TYPE';
|
|
178
|
+
}
|
|
179
|
+
/** Name of the ProductInput.input oneof field that values `security`, e.g. 'tips'. */
|
|
180
|
+
function armFor(security) {
|
|
181
|
+
return shippedValuationArms().require(productTypeOf(security), couponTypeOf(security)).arm;
|
|
182
|
+
}
|
|
183
|
+
exports.armFor = armFor;
|
|
184
|
+
/** Market data the security's arm needs, in file order. A fresh array; empty when none. */
|
|
185
|
+
function requiredMarketData(security) {
|
|
186
|
+
return [...shippedValuationArms().require(productTypeOf(security), couponTypeOf(security)).requires];
|
|
187
|
+
}
|
|
188
|
+
exports.requiredMarketData = requiredMarketData;
|
|
189
|
+
//# sourceMappingURL=product_inputs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product_inputs.js","sourceRoot":"","sources":["product_inputs.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;AAEH,gFAAmD;AACnD,uFAAqF;AACrF,yFAAuF;AAEvF,gGAAwF;AACxF,sCAAqD;AACrD,2DAA+E;AAK/E,MAAM,iBAAiB,GAA0B,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;AAEvF,uDAAuD;AACvD,MAAM,UAAU,GAAG,EAAE,CAAC;AAOtB,SAAS,MAAM,CAAC,CAAS,EAAE,GAAW;IACpC,OAAO,MAAM,CAAC,SAAS,CA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AQ,CAAC,cAAc,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED,uFAAuF;AACvF,SAAS,YAAY,CAAC,QAAuB;IAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC;IAC1C,OAAO,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,gCAAe,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC;AAC9F,CAAC;AAED,sFAAsF;AACtF,SAAgB,MAAM,CAAC,QAAuB;IAC5C,OAAO,oBAAoB,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC;AAC7F,CAAC;AAFD,wBAEC;AAED,2FAA2F;AAC3F,SAAgB,kBAAkB,CAAC,QAAuB;IACxD,OAAO,CAAC,GAAG,oBAAoB,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AACvG,CAAC;AAFD,gDAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
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-409: valuation_arms in hierarchy.json, resolved by armFor /
|
|
28
|
+
* requiredMarketData.
|
|
29
|
+
*
|
|
30
|
+
* The shared cases live in ledger-models-protos/fixtures/valuation_arms_cases.json,
|
|
31
|
+
* read by the Java, Python and Rust tests too.
|
|
32
|
+
*/
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
|
+
const path = __importStar(require("path"));
|
|
35
|
+
const product_inputs_1 = require("./product_inputs");
|
|
36
|
+
const product_hierarchy_1 = require("./product_hierarchy");
|
|
37
|
+
const errors_1 = require("../errors");
|
|
38
|
+
const coupon_type_pb_1 = require("../../../fintekkers/models/security/coupon_type_pb");
|
|
39
|
+
const product_type_pb_1 = require("../../../fintekkers/models/security/product_type_pb");
|
|
40
|
+
const security_pb_1 = require("../../../fintekkers/models/security/security_pb");
|
|
41
|
+
const PROTOS = path.resolve(__dirname, '../../../../../ledger-models-protos');
|
|
42
|
+
const BUNDLED = path.resolve(__dirname, '../../../../hierarchy.json');
|
|
43
|
+
const cases = JSON.parse(fs.readFileSync(path.join(PROTOS, 'fixtures/valuation_arms_cases.json'), 'utf-8')).cases;
|
|
44
|
+
function sourceSection() {
|
|
45
|
+
return JSON.parse(fs.readFileSync(path.join(PROTOS, 'hierarchy.json'), 'utf-8')).valuation_arms;
|
|
46
|
+
}
|
|
47
|
+
function hasEnumValue(productType) {
|
|
48
|
+
return Object.prototype.hasOwnProperty.call(product_type_pb_1.ProductTypeProto, productType);
|
|
49
|
+
}
|
|
50
|
+
function security(productType, couponType) {
|
|
51
|
+
const details = new security_pb_1.BondDetailsProto();
|
|
52
|
+
details.setCouponType(coupon_type_pb_1.CouponTypeProto[couponType]);
|
|
53
|
+
const s = new security_pb_1.SecurityProto();
|
|
54
|
+
s.setProductType(product_type_pb_1.ProductTypeProto[productType]);
|
|
55
|
+
s.setBondDetails(details);
|
|
56
|
+
return s;
|
|
57
|
+
}
|
|
58
|
+
/** [arm, requires] through a real proto when the type has an enum value; planned leaves by name. */
|
|
59
|
+
function resolve(productType, couponType) {
|
|
60
|
+
if (!hasEnumValue(productType)) {
|
|
61
|
+
const a = (0, product_inputs_1.shippedValuationArms)().require(productType, couponType);
|
|
62
|
+
return [a.arm, [...a.requires]];
|
|
63
|
+
}
|
|
64
|
+
const s = security(productType, couponType);
|
|
65
|
+
return [(0, product_inputs_1.armFor)(s), (0, product_inputs_1.requiredMarketData)(s)];
|
|
66
|
+
}
|
|
67
|
+
function catchUnmapped(fn) {
|
|
68
|
+
try {
|
|
69
|
+
fn();
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
if (e instanceof errors_1.UnmappedProductTypeError)
|
|
73
|
+
return e;
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
throw new Error('expected UnmappedProductTypeError');
|
|
77
|
+
}
|
|
78
|
+
describe('valuation_arms shared fixture (metric 1)', () => {
|
|
79
|
+
test('has the required cases', () => {
|
|
80
|
+
expect(cases.length).toBeGreaterThanOrEqual(5);
|
|
81
|
+
const seen = cases.map(c => `${c.product_type}/${c.coupon_type}`);
|
|
82
|
+
expect(seen).toEqual(expect.arrayContaining([
|
|
83
|
+
'TBILL/ZERO', 'TIPS/FIXED', 'CORP_BOND/FLOAT', 'TREASURY_NOTE/FLOAT', 'FX_SPOT/UNKNOWN_COUPON_TYPE',
|
|
84
|
+
]));
|
|
85
|
+
});
|
|
86
|
+
test.each(cases.map(c => [`${c.product_type}/${c.coupon_type}`, c]))('%s', (_, c) => {
|
|
87
|
+
if (c.error !== undefined) {
|
|
88
|
+
expect(c.error).toBe('UnmappedProductTypeError');
|
|
89
|
+
const e = catchUnmapped(() => resolve(c.product_type, c.coupon_type));
|
|
90
|
+
expect([e.productType, e.couponType]).toEqual([c.product_type, c.coupon_type]);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
expect(resolve(c.product_type, c.coupon_type)).toEqual([c.arm, c.requires]);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('unmapped types raise (metric 2)', () => {
|
|
98
|
+
const unmapped = new Set(['FX_SPOT']);
|
|
99
|
+
for (const root of ['INDEX', 'CRYPTO', 'COMMODITY_SPOT']) {
|
|
100
|
+
for (const n of (0, product_hierarchy_1.descendantsOf)(root))
|
|
101
|
+
if ((0, product_hierarchy_1.descendantsOf)(n).length === 0)
|
|
102
|
+
unmapped.add(n);
|
|
103
|
+
}
|
|
104
|
+
test('the set comes from the registry', () => {
|
|
105
|
+
expect([...unmapped]).toEqual(expect.arrayContaining([
|
|
106
|
+
'FX_SPOT', 'COMMODITY_INDEX', 'PLATINUM', 'PALLADIUM', 'CRYPTOCURRENCY', 'GOLD',
|
|
107
|
+
]));
|
|
108
|
+
});
|
|
109
|
+
test.each([...unmapped].sort())('%s', pt => {
|
|
110
|
+
const e = catchUnmapped(() => resolve(pt, 'UNKNOWN_COUPON_TYPE'));
|
|
111
|
+
expect(e.message).toContain(pt);
|
|
112
|
+
expect(e.message).toContain('UNKNOWN_COUPON_TYPE');
|
|
113
|
+
});
|
|
114
|
+
test('message names product and coupon type', () => {
|
|
115
|
+
const gold = security('GOLD', 'FLOAT');
|
|
116
|
+
const e = catchUnmapped(() => (0, product_inputs_1.armFor)(gold));
|
|
117
|
+
expect(e.message).toContain('GOLD');
|
|
118
|
+
expect(e.message).toContain('FLOAT');
|
|
119
|
+
expect(() => (0, product_inputs_1.requiredMarketData)(gold)).toThrow(errors_1.UnmappedProductTypeError);
|
|
120
|
+
});
|
|
121
|
+
test('unset bond_details reads as UNKNOWN_COUPON_TYPE', () => {
|
|
122
|
+
const corp = new security_pb_1.SecurityProto();
|
|
123
|
+
corp.setProductType(product_type_pb_1.ProductTypeProto.CORP_BOND);
|
|
124
|
+
expect((0, product_inputs_1.armFor)(corp)).toBe('bond');
|
|
125
|
+
const fx = new security_pb_1.SecurityProto();
|
|
126
|
+
fx.setProductType(product_type_pb_1.ProductTypeProto.FX_SPOT);
|
|
127
|
+
expect(catchUnmapped(() => (0, product_inputs_1.armFor)(fx)).couponType).toBe('UNKNOWN_COUPON_TYPE');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
test('bundled valuation_arms equals the source (metric 4)', () => {
|
|
131
|
+
expect(fs.existsSync(BUNDLED)).toBe(true);
|
|
132
|
+
const bundled = JSON.parse(fs.readFileSync(BUNDLED, 'utf-8'));
|
|
133
|
+
expect(bundled.valuation_arms).toBeDefined();
|
|
134
|
+
expect(bundled.valuation_arms).toEqual(sourceSection());
|
|
135
|
+
});
|
|
136
|
+
test('parse rejects a requires value outside the vocabulary (metric 5)', () => {
|
|
137
|
+
const section = sourceSection();
|
|
138
|
+
section.entries[0].requires.push('FX_RATE');
|
|
139
|
+
expect(() => (0, product_inputs_1.parseValuationArms)(section)).toThrow(/FX_RATE/);
|
|
140
|
+
});
|
|
141
|
+
test('every leaf is covered (metric 3)', () => {
|
|
142
|
+
expect((0, product_inputs_1.shippedValuationArms)().uncoveredLeaves()).toEqual([]);
|
|
143
|
+
});
|
|
144
|
+
//# sourceMappingURL=product_inputs.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product_inputs.test.js","sourceRoot":"","sources":["product_inputs.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;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AAE,CAAC,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC/D,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LM-409: valuation_arms in hierarchy.json, resolved by armFor /
|
|
3
|
+
* requiredMarketData.
|
|
4
|
+
*
|
|
5
|
+
* The shared cases live in ledger-models-protos/fixtures/valuation_arms_cases.json,
|
|
6
|
+
* read by the Java, Python and Rust tests too.
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
|
|
11
|
+
import { armFor, parseValuationArms, requiredMarketData, shippedValuationArms } from './product_inputs';
|
|
12
|
+
import { descendantsOf } from './product_hierarchy';
|
|
13
|
+
import { UnmappedProductTypeError } from '../errors';
|
|
14
|
+
import { CouponTypeProto } from '../../../fintekkers/models/security/coupon_type_pb';
|
|
15
|
+
import { ProductTypeProto } from '../../../fintekkers/models/security/product_type_pb';
|
|
16
|
+
import { BondDetailsProto, SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
17
|
+
|
|
18
|
+
const PROTOS = path.resolve(__dirname, '../../../../../ledger-models-protos');
|
|
19
|
+
const BUNDLED = path.resolve(__dirname, '../../../../hierarchy.json');
|
|
20
|
+
|
|
21
|
+
interface Case {
|
|
22
|
+
product_type: string;
|
|
23
|
+
coupon_type: string;
|
|
24
|
+
arm?: string;
|
|
25
|
+
requires?: string[];
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const cases: Case[] = JSON.parse(
|
|
30
|
+
fs.readFileSync(path.join(PROTOS, 'fixtures/valuation_arms_cases.json'), 'utf-8'),
|
|
31
|
+
).cases;
|
|
32
|
+
|
|
33
|
+
function sourceSection(): any {
|
|
34
|
+
return JSON.parse(fs.readFileSync(path.join(PROTOS, 'hierarchy.json'), 'utf-8')).valuation_arms;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function hasEnumValue(productType: string): boolean {
|
|
38
|
+
return Object.prototype.hasOwnProperty.call(ProductTypeProto, productType);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function security(productType: string, couponType: string): SecurityProto {
|
|
42
|
+
const details = new BondDetailsProto();
|
|
43
|
+
details.setCouponType(CouponTypeProto[couponType as keyof typeof CouponTypeProto]);
|
|
44
|
+
const s = new SecurityProto();
|
|
45
|
+
s.setProductType(ProductTypeProto[productType as keyof typeof ProductTypeProto]);
|
|
46
|
+
s.setBondDetails(details);
|
|
47
|
+
return s;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** [arm, requires] through a real proto when the type has an enum value; planned leaves by name. */
|
|
51
|
+
function resolve(productType: string, couponType: string): [string, string[]] {
|
|
52
|
+
if (!hasEnumValue(productType)) {
|
|
53
|
+
const a = shippedValuationArms().require(productType, couponType);
|
|
54
|
+
return [a.arm, [...a.requires]];
|
|
55
|
+
}
|
|
56
|
+
const s = security(productType, couponType);
|
|
57
|
+
return [armFor(s), requiredMarketData(s)];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function catchUnmapped(fn: () => unknown): UnmappedProductTypeError {
|
|
61
|
+
try {
|
|
62
|
+
fn();
|
|
63
|
+
} catch (e) {
|
|
64
|
+
if (e instanceof UnmappedProductTypeError) return e;
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
throw new Error('expected UnmappedProductTypeError');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe('valuation_arms shared fixture (metric 1)', () => {
|
|
71
|
+
test('has the required cases', () => {
|
|
72
|
+
expect(cases.length).toBeGreaterThanOrEqual(5);
|
|
73
|
+
const seen = cases.map(c => `${c.product_type}/${c.coupon_type}`);
|
|
74
|
+
expect(seen).toEqual(expect.arrayContaining([
|
|
75
|
+
'TBILL/ZERO', 'TIPS/FIXED', 'CORP_BOND/FLOAT', 'TREASURY_NOTE/FLOAT', 'FX_SPOT/UNKNOWN_COUPON_TYPE',
|
|
76
|
+
]));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test.each(cases.map(c => [`${c.product_type}/${c.coupon_type}`, c] as [string, Case]))('%s', (_, c) => {
|
|
80
|
+
if (c.error !== undefined) {
|
|
81
|
+
expect(c.error).toBe('UnmappedProductTypeError');
|
|
82
|
+
const e = catchUnmapped(() => resolve(c.product_type, c.coupon_type));
|
|
83
|
+
expect([e.productType, e.couponType]).toEqual([c.product_type, c.coupon_type]);
|
|
84
|
+
} else {
|
|
85
|
+
expect(resolve(c.product_type, c.coupon_type)).toEqual([c.arm, c.requires]);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('unmapped types raise (metric 2)', () => {
|
|
91
|
+
const unmapped = new Set(['FX_SPOT']);
|
|
92
|
+
for (const root of ['INDEX', 'CRYPTO', 'COMMODITY_SPOT']) {
|
|
93
|
+
for (const n of descendantsOf(root)) if (descendantsOf(n).length === 0) unmapped.add(n);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
test('the set comes from the registry', () => {
|
|
97
|
+
expect([...unmapped]).toEqual(expect.arrayContaining([
|
|
98
|
+
'FX_SPOT', 'COMMODITY_INDEX', 'PLATINUM', 'PALLADIUM', 'CRYPTOCURRENCY', 'GOLD',
|
|
99
|
+
]));
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test.each([...unmapped].sort())('%s', pt => {
|
|
103
|
+
const e = catchUnmapped(() => resolve(pt, 'UNKNOWN_COUPON_TYPE'));
|
|
104
|
+
expect(e.message).toContain(pt);
|
|
105
|
+
expect(e.message).toContain('UNKNOWN_COUPON_TYPE');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('message names product and coupon type', () => {
|
|
109
|
+
const gold = security('GOLD', 'FLOAT');
|
|
110
|
+
const e = catchUnmapped(() => armFor(gold));
|
|
111
|
+
expect(e.message).toContain('GOLD');
|
|
112
|
+
expect(e.message).toContain('FLOAT');
|
|
113
|
+
expect(() => requiredMarketData(gold)).toThrow(UnmappedProductTypeError);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('unset bond_details reads as UNKNOWN_COUPON_TYPE', () => {
|
|
117
|
+
const corp = new SecurityProto();
|
|
118
|
+
corp.setProductType(ProductTypeProto.CORP_BOND);
|
|
119
|
+
expect(armFor(corp)).toBe('bond');
|
|
120
|
+
const fx = new SecurityProto();
|
|
121
|
+
fx.setProductType(ProductTypeProto.FX_SPOT);
|
|
122
|
+
expect(catchUnmapped(() => armFor(fx)).couponType).toBe('UNKNOWN_COUPON_TYPE');
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('bundled valuation_arms equals the source (metric 4)', () => {
|
|
127
|
+
expect(fs.existsSync(BUNDLED)).toBe(true);
|
|
128
|
+
const bundled = JSON.parse(fs.readFileSync(BUNDLED, 'utf-8'));
|
|
129
|
+
expect(bundled.valuation_arms).toBeDefined();
|
|
130
|
+
expect(bundled.valuation_arms).toEqual(sourceSection());
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('parse rejects a requires value outside the vocabulary (metric 5)', () => {
|
|
134
|
+
const section = sourceSection();
|
|
135
|
+
section.entries[0].requires.push('FX_RATE');
|
|
136
|
+
expect(() => parseValuationArms(section)).toThrow(/FX_RATE/);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('every leaf is covered (metric 3)', () => {
|
|
140
|
+
expect(shippedValuationArms().uncoveredLeaves()).toEqual([]);
|
|
141
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which ProductInput arm values a security, and which market data that arm
|
|
3
|
+
* needs. Backed by the valuation_arms section of
|
|
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/valuation_arms.md.
|
|
6
|
+
*
|
|
7
|
+
* Resolution walks from the security's product_type up its parent chain. At
|
|
8
|
+
* each node a coupon_types entry matching bond_details.coupon_type wins, then
|
|
9
|
+
* the node's plain entry, then an unpriced listing. The first node with any
|
|
10
|
+
* match decides. No match, or an unpriced match, throws
|
|
11
|
+
* UnmappedProductTypeError: there is no default arm. A broken section throws
|
|
12
|
+
* a plain Error at load, like product_hierarchy.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import hierarchy from '../../../../hierarchy.json';
|
|
16
|
+
import { CouponTypeProto } from '../../../fintekkers/models/security/coupon_type_pb';
|
|
17
|
+
import { ProductTypeProto } from '../../../fintekkers/models/security/product_type_pb';
|
|
18
|
+
import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
19
|
+
import { ProductInput } from '../../../fintekkers/requests/valuation/product_inputs_pb';
|
|
20
|
+
import { UnmappedProductTypeError } from '../errors';
|
|
21
|
+
import { allProductTypes, descendantsOf, parentOf } from './product_hierarchy';
|
|
22
|
+
|
|
23
|
+
/** The closed requires vocabulary: market data an arm needs beyond the price. */
|
|
24
|
+
export type MarketDataKind = 'CPI_U' | 'FRN_FIXINGS' | 'FRN_CURVE';
|
|
25
|
+
|
|
26
|
+
const MARKET_DATA_KINDS: ReadonlyArray<string> = ['CPI_U', 'FRN_FIXINGS', 'FRN_CURVE'];
|
|
27
|
+
|
|
28
|
+
/** Map key for a node's entry with no coupon_types. */
|
|
29
|
+
const ANY_COUPON = '';
|
|
30
|
+
|
|
31
|
+
interface Arm {
|
|
32
|
+
arm: string;
|
|
33
|
+
requires: ReadonlyArray<MarketDataKind>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function hasOwn(o: object, key: string): boolean {
|
|
37
|
+
return Object.prototype.hasOwnProperty.call(o, key);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function enumName(e: object, value: number): string {
|
|
41
|
+
for (const [k, v] of Object.entries(e)) {
|
|
42
|
+
if (v === value) return k;
|
|
43
|
+
}
|
|
44
|
+
return String(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A parsed, checked valuation_arms section. */
|
|
48
|
+
export class ValuationArms {
|
|
49
|
+
/** @param entries node -> coupon type name (or '' for the plain entry) -> arm */
|
|
50
|
+
constructor(
|
|
51
|
+
private readonly entries: Map<string, Map<string, Arm>>,
|
|
52
|
+
private readonly unpriced: ReadonlySet<string>,
|
|
53
|
+
) {}
|
|
54
|
+
|
|
55
|
+
/** The deepest matching node's arm, or null when unmapped or unpriced. */
|
|
56
|
+
resolve(productType: string, couponType: string): Arm | null {
|
|
57
|
+
for (let node: string | null = productType; node !== null; node = parentOf(node)) {
|
|
58
|
+
const byCoupon = this.entries.get(node);
|
|
59
|
+
const arm = byCoupon?.get(couponType) ?? byCoupon?.get(ANY_COUPON);
|
|
60
|
+
if (arm) return arm;
|
|
61
|
+
if (this.unpriced.has(node)) return null;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
require(productType: string, couponType: string): Arm {
|
|
67
|
+
const arm = this.resolve(productType, couponType);
|
|
68
|
+
if (!arm) throw new UnmappedProductTypeError(productType, couponType);
|
|
69
|
+
return arm;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Leaf product types (active and planned) with neither an entry nor an unpriced listing. */
|
|
73
|
+
uncoveredLeaves(): string[] {
|
|
74
|
+
return allProductTypes().filter(n => descendantsOf(n).length === 0 && !this.covers(n));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private covers(productType: string): boolean {
|
|
78
|
+
for (let node: string | null = productType; node !== null; node = parentOf(node)) {
|
|
79
|
+
if (this.entries.has(node) || this.unpriced.has(node)) return true;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function bad(detail: string): Error {
|
|
86
|
+
return new Error(`hierarchy.json valuation_arms: ${detail}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function stringOf(body: Record<string, unknown>, key: string): string {
|
|
90
|
+
const v = body[key];
|
|
91
|
+
if (typeof v !== 'string') throw bad(`'${key}' must be a string in ${JSON.stringify(body)}`);
|
|
92
|
+
return v;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function stringsOf(body: Record<string, unknown>, key: string): string[] {
|
|
96
|
+
const v = body[key];
|
|
97
|
+
if (!Array.isArray(v) || !v.every(x => typeof x === 'string')) {
|
|
98
|
+
throw bad(`'${key}' must be a list of strings in ${JSON.stringify(body)}`);
|
|
99
|
+
}
|
|
100
|
+
return v as string[];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Parses and checks a valuation_arms section against the shipped
|
|
105
|
+
* product_types tree, the ProductInput oneof and the CouponTypeProto /
|
|
106
|
+
* MarketDataKind vocabularies. Throws on any failure. Exported for tests.
|
|
107
|
+
*/
|
|
108
|
+
export function parseValuationArms(section: unknown): ValuationArms {
|
|
109
|
+
if (typeof section !== 'object' || section === null || Array.isArray(section)) {
|
|
110
|
+
throw bad('section must be an object');
|
|
111
|
+
}
|
|
112
|
+
const s = section as Record<string, unknown>;
|
|
113
|
+
const productTypes = new Set(allProductTypes());
|
|
114
|
+
const arms = new Set(Object.keys(ProductInput.InputCase)
|
|
115
|
+
.filter(k => k !== 'INPUT_NOT_SET')
|
|
116
|
+
.map(k => k.toLowerCase()));
|
|
117
|
+
|
|
118
|
+
if (!Array.isArray(s.entries)) throw bad("'entries' must be a list");
|
|
119
|
+
const entries = new Map<string, Map<string, Arm>>();
|
|
120
|
+
for (const raw of s.entries as unknown[]) {
|
|
121
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
122
|
+
throw bad(`entry must be an object, got ${JSON.stringify(raw)}`);
|
|
123
|
+
}
|
|
124
|
+
const body = raw as Record<string, unknown>;
|
|
125
|
+
const node = stringOf(body, 'node');
|
|
126
|
+
if (!productTypes.has(node)) throw bad(`node '${node}' is not in product_types`);
|
|
127
|
+
const arm = stringOf(body, 'arm');
|
|
128
|
+
if (!arms.has(arm)) throw bad(`arm '${arm}' is not a ProductInput.input field`);
|
|
129
|
+
const requires = stringsOf(body, 'requires').map(r => {
|
|
130
|
+
if (!MARKET_DATA_KINDS.includes(r)) {
|
|
131
|
+
throw bad(`requires value '${r}' is not one of CPI_U, FRN_FIXINGS, FRN_CURVE`);
|
|
132
|
+
}
|
|
133
|
+
return r as MarketDataKind;
|
|
134
|
+
});
|
|
135
|
+
let coupons = [ANY_COUPON];
|
|
136
|
+
if (hasOwn(body, 'coupon_types')) {
|
|
137
|
+
coupons = stringsOf(body, 'coupon_types');
|
|
138
|
+
for (const c of coupons) {
|
|
139
|
+
if (!hasOwn(CouponTypeProto, c)) throw bad(`coupon_types value '${c}' is not a CouponTypeProto name`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
let byCoupon = entries.get(node);
|
|
143
|
+
if (!byCoupon) {
|
|
144
|
+
byCoupon = new Map();
|
|
145
|
+
entries.set(node, byCoupon);
|
|
146
|
+
}
|
|
147
|
+
const value: Arm = Object.freeze({ arm, requires: Object.freeze(requires) });
|
|
148
|
+
for (const c of coupons) {
|
|
149
|
+
if (byCoupon.has(c)) throw bad(`duplicate entry for node ${node}${c ? `, coupon_type ${c}` : ''}`);
|
|
150
|
+
byCoupon.set(c, value);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const unpriced = new Set<string>();
|
|
155
|
+
for (const node of stringsOf(s, 'unpriced')) {
|
|
156
|
+
if (!productTypes.has(node)) throw bad(`node '${node}' is not in product_types`);
|
|
157
|
+
if (entries.has(node)) throw bad(`node ${node} is both mapped and unpriced`);
|
|
158
|
+
unpriced.add(node);
|
|
159
|
+
}
|
|
160
|
+
return new ValuationArms(entries, unpriced);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let shippedArms: ValuationArms | undefined;
|
|
164
|
+
|
|
165
|
+
/** The shipped valuation_arms section, parsed and checked on first use. Exported for tests. */
|
|
166
|
+
export function shippedValuationArms(): ValuationArms {
|
|
167
|
+
if (!shippedArms) {
|
|
168
|
+
const section = (hierarchy as Record<string, unknown>).valuation_arms;
|
|
169
|
+
if (section === undefined) throw bad('section missing from hierarchy.json');
|
|
170
|
+
shippedArms = parseValuationArms(section);
|
|
171
|
+
}
|
|
172
|
+
return shippedArms;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function productTypeOf(security: SecurityProto): string {
|
|
176
|
+
return enumName(ProductTypeProto, security.getProductType());
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Read from the proto field only; unset bond_details reads as UNKNOWN_COUPON_TYPE. */
|
|
180
|
+
function couponTypeOf(security: SecurityProto): string {
|
|
181
|
+
const details = security.getBondDetails();
|
|
182
|
+
return details ? enumName(CouponTypeProto, details.getCouponType()) : 'UNKNOWN_COUPON_TYPE';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Name of the ProductInput.input oneof field that values `security`, e.g. 'tips'. */
|
|
186
|
+
export function armFor(security: SecurityProto): string {
|
|
187
|
+
return shippedValuationArms().require(productTypeOf(security), couponTypeOf(security)).arm;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Market data the security's arm needs, in file order. A fresh array; empty when none. */
|
|
191
|
+
export function requiredMarketData(security: SecurityProto): MarketDataKind[] {
|
|
192
|
+
return [...shippedValuationArms().require(productTypeOf(security), couponTypeOf(security)).requires];
|
|
193
|
+
}
|