@fintekkers/ledger-models 1.1.19 → 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/catalog/measures.json +1 -1
- package/hierarchy.json +20 -2
- package/node/fintekkers/models/price/price_type_pb.d.ts +1 -0
- package/node/fintekkers/models/price/price_type_pb.js +2 -1
- package/node/fintekkers/models/security/product_type_pb.d.ts +1 -0
- package/node/fintekkers/models/security/product_type_pb.js +1 -0
- package/node/fintekkers/requests/valuation/product_inputs.test.js +6 -6
- package/node/fintekkers/requests/valuation/product_inputs.test.js.map +1 -1
- package/node/fintekkers/requests/valuation/product_inputs.test.ts +6 -6
- 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/price/lm412EnumValues.test.d.ts +1 -0
- package/node/wrappers/models/price/lm412EnumValues.test.js +66 -0
- package/node/wrappers/models/price/lm412EnumValues.test.js.map +1 -0
- package/node/wrappers/models/price/lm412EnumValues.test.ts +55 -0
- package/node/wrappers/models/security/product_hierarchy.test.d.ts +1 -0
- package/node/wrappers/models/security/product_hierarchy.test.js +16 -0
- package/node/wrappers/models/security/product_hierarchy.test.js.map +1 -0
- package/node/wrappers/models/security/product_hierarchy.test.ts +14 -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
|
@@ -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,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS,EAAE,KAAa;IACxC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QACtC,IAAI,CAAC,KAAK,KAAK;YAAE,OAAO,CAAC,CAAC;KAC3B;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,gDAAgD;AAChD,MAAa,aAAa;IACxB,iFAAiF;IACjF,YACmB,OAAsC,EACtC,QAA6B;QAD7B,YAAO,GAAP,OAAO,CAA+B;QACtC,aAAQ,GAAR,QAAQ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AC;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;;;;;;GAMG;AACH,uCAAyB;AACzB,2CAA6B;AAE7B,qDAAwG;AACxG,2DAAoD;AACpD,sCAAqD;AACrD,uFAAqF;AACrF,yFAAuF;AACvF,iFAAkG;AAElG,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,qCAAqC,CAAC,CAAC;AAC9E,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,4BAA4B,CAAC,CAAC;AAUtE,MAAM,KAAK,GAAW,IAAI,CAAC,KAAK,CAC9B,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,oCAAoC,CAAC,EAAE,OAAO,CAAC,CAClF,CAAC,KAAK,CAAC;AAER,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,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9D,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,WAAW,EAAE,CAAC;IAC7C,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,kEAAkE,EAAE,GAAG,EAAE;IAC5E,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAChC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5C,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,mCAAkB,EAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAC/D,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAC5C,MAAM,CAAC,IAAA,qCAAoB,GAAE,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
|
+
});
|