@fintekkers/ledger-models 1.1.20 → 1.1.22
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 +30 -0
- package/node/wrappers/models/errors.js +39 -1
- package/node/wrappers/models/errors.js.map +1 -1
- package/node/wrappers/models/errors.ts +44 -0
- package/node/wrappers/models/security/TreasuryFrnFixings.js +5 -0
- package/node/wrappers/models/security/TreasuryFrnFixings.js.map +1 -1
- package/node/wrappers/models/security/TreasuryFrnFixings.ts +5 -0
- package/node/wrappers/models/security/product_input_builders.test.d.ts +1 -0
- package/node/wrappers/models/security/product_input_builders.test.js +192 -0
- package/node/wrappers/models/security/product_input_builders.test.js.map +1 -0
- package/node/wrappers/models/security/product_input_builders.test.ts +192 -0
- package/node/wrappers/models/security/product_inputs.d.ts +79 -0
- package/node/wrappers/models/security/product_inputs.js +290 -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 +308 -0
- package/node/wrappers/requests/valuation/ValuationRequests.d.ts +21 -0
- package/node/wrappers/requests/valuation/ValuationRequests.js +33 -0
- package/node/wrappers/requests/valuation/ValuationRequests.js.map +1 -0
- package/node/wrappers/requests/valuation/ValuationRequests.ts +37 -0
- package/node/wrappers/util/object-types.test.js +6 -1
- package/node/wrappers/util/object-types.test.js.map +1 -1
- package/node/wrappers/util/object-types.test.ts +9 -1
- 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,35 @@ 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
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Typed input error: the security's valuation arm requires market data
|
|
32
|
+
* (hierarchy.json valuation_arms `requires`) that the caller did not supply,
|
|
33
|
+
* e.g. arm `tips` with no `CPI_U`. Thrown by product_inputs.forSecurity and
|
|
34
|
+
* ValuationRequests.typed. Carries one violation on the arm field, e.g.
|
|
35
|
+
* `tips.cpi` (docs/adr/product_input_builders.md).
|
|
36
|
+
*/
|
|
37
|
+
export declare class MissingMarketDataError extends ModelValidationError {
|
|
38
|
+
readonly arm: string;
|
|
39
|
+
readonly kind: string;
|
|
40
|
+
/**
|
|
41
|
+
* @param arm the ProductInput.input field, e.g. `tips`
|
|
42
|
+
* @param kind the missing MarketDataKind, e.g. `CPI_U`
|
|
43
|
+
* @param field the arm field that holds it, e.g. `tips.cpi`
|
|
44
|
+
* @param objectId the security's UUID, or undefined if it has none
|
|
45
|
+
*/
|
|
46
|
+
constructor(arm: string, kind: string, field: string, objectId: UUID | undefined);
|
|
47
|
+
}
|
|
18
48
|
/** Builds one violation. `objectId` may be undefined when the input had no UUID. */
|
|
19
49
|
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.MissingMarketDataError = 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,44 @@ 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;
|
|
50
|
+
/**
|
|
51
|
+
* Typed input error: the security's valuation arm requires market data
|
|
52
|
+
* (hierarchy.json valuation_arms `requires`) that the caller did not supply,
|
|
53
|
+
* e.g. arm `tips` with no `CPI_U`. Thrown by product_inputs.forSecurity and
|
|
54
|
+
* ValuationRequests.typed. Carries one violation on the arm field, e.g.
|
|
55
|
+
* `tips.cpi` (docs/adr/product_input_builders.md).
|
|
56
|
+
*/
|
|
57
|
+
class MissingMarketDataError extends ModelValidationError {
|
|
58
|
+
/**
|
|
59
|
+
* @param arm the ProductInput.input field, e.g. `tips`
|
|
60
|
+
* @param kind the missing MarketDataKind, e.g. `CPI_U`
|
|
61
|
+
* @param field the arm field that holds it, e.g. `tips.cpi`
|
|
62
|
+
* @param objectId the security's UUID, or undefined if it has none
|
|
63
|
+
*/
|
|
64
|
+
constructor(arm, kind, field, objectId) {
|
|
65
|
+
super([violation(field, objectId, `missing market data ${kind} for arm ${arm}`)]);
|
|
66
|
+
this.name = 'MissingMarketDataError';
|
|
67
|
+
this.arm = arm;
|
|
68
|
+
this.kind = kind;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.MissingMarketDataError = MissingMarketDataError;
|
|
34
72
|
/** Builds one violation. `objectId` may be undefined when the input had no UUID. */
|
|
35
73
|
function violation(field, objectId, message) {
|
|
36
74
|
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,CAAC,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;SACxE;QACD,KAAK,CAAC,UAAU;aACX,GAAG,CAAC,CAAC,CAAC,EAAE,WAAC,OAAA,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,UAAU,EAAE,QAAQ,MAAA,UAAU,CAAC,CAAC,CAAC,mCAAI,MAAM,GAAG,CAAA,EAAA,CAAC;aAC9E,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,0EAA0E;IAC1E,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAA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DAgBC;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,50 @@ 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
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Typed input error: the security's valuation arm requires market data
|
|
57
|
+
* (hierarchy.json valuation_arms `requires`) that the caller did not supply,
|
|
58
|
+
* e.g. arm `tips` with no `CPI_U`. Thrown by product_inputs.forSecurity and
|
|
59
|
+
* ValuationRequests.typed. Carries one violation on the arm field, e.g.
|
|
60
|
+
* `tips.cpi` (docs/adr/product_input_builders.md).
|
|
61
|
+
*/
|
|
62
|
+
export class MissingMarketDataError extends ModelValidationError {
|
|
63
|
+
readonly arm: string;
|
|
64
|
+
readonly kind: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param arm the ProductInput.input field, e.g. `tips`
|
|
68
|
+
* @param kind the missing MarketDataKind, e.g. `CPI_U`
|
|
69
|
+
* @param field the arm field that holds it, e.g. `tips.cpi`
|
|
70
|
+
* @param objectId the security's UUID, or undefined if it has none
|
|
71
|
+
*/
|
|
72
|
+
constructor(arm: string, kind: string, field: string, objectId: UUID | undefined) {
|
|
73
|
+
super([violation(field, objectId, `missing market data ${kind} for arm ${arm}`)]);
|
|
74
|
+
this.name = 'MissingMarketDataError';
|
|
75
|
+
this.arm = arm;
|
|
76
|
+
this.kind = kind;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
36
80
|
/** Builds one violation. `objectId` may be undefined when the input had no UUID. */
|
|
37
81
|
export function violation(field: string, objectId: UUID | undefined, message: string): FieldViolationProto {
|
|
38
82
|
const v = new FieldViolationProto();
|
|
@@ -11,6 +11,11 @@ const date_1 = require("../utils/date");
|
|
|
11
11
|
* `treasury_frn_fixings` and Rust's `treasury_frn_fixings`; all are tested
|
|
12
12
|
* against `test-fixtures/treasury-frn-fixings.json`.
|
|
13
13
|
* See `docs/adr/frn_reference_rate_fixings.md` (LM-382, LM-385, LM-386).
|
|
14
|
+
*
|
|
15
|
+
* Deprecated (LM-410): FRN fixings now come from price-service (MDI-100) and
|
|
16
|
+
* reach forSecurity ready to use through MarketData; nothing here picks them
|
|
17
|
+
* any more. To be deleted in LM-411, once ledger-service no longer calls the
|
|
18
|
+
* Java copy (LS-202). See docs/adr/product_input_builders.md.
|
|
14
19
|
*/
|
|
15
20
|
/** Treasury's standard bill terms, in weeks. */
|
|
16
21
|
const STANDARD_BILL_WEEKS = [4, 6, 8, 13, 17, 26, 52];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreasuryFrnFixings.js","sourceRoot":"","sources":["TreasuryFrnFixings.ts"],"names":[],"mappings":";;;AAGA,qFAAmF;AACnF,2FAAyF;AACzF,gGAAoG;AACpG,wCAA+F;AAE/F
|
|
1
|
+
{"version":3,"file":"TreasuryFrnFixings.js","sourceRoot":"","sources":["TreasuryFrnFixings.ts"],"names":[],"mappings":";;;AAGA,qFAAmF;AACnF,2FAAyF;AACzF,gGAAoG;AACpG,wCAA+F;AAE/F;;;;;;;;;;;GAWG;AAEH,gDAAgD;AAChD,MAAM,mBAAmB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAEtD,0FAA0F;AAC1F,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,KAAmB,EAAE,MAAmB;IACvE,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,8BAAc,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAC9E,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAChC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,GAAG,GAAG,IAAA,eAAQ,EAAC,IAAA,wBAAiB,EAAC,MAAM,EAAE,EAAE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QAAQ,GAAG,IAAI,CAAC;gBAChB,IAAI,GAAG,QAAQ,CAAC;gBAChB,eAAe,GAAG,WAAW,CAAC;aAC/B;SACF;KACF;IACD,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,QAAQ,GAAG,QAAQ,CAAC,eAAe,EAAU,CAAC;IACpD,OAAO,IAAI,4CAAwB,EAAE;SAClC,QAAQ,CAAC,8BAAc,CAAC,cAAc,CAAC;SACvC,aAAa,CAAC,MAAA,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,0CAAE,YAAY,EAAE,CAAC;SAC1D,OAAO,CAAC,MAAA,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,0CAAE,YAAY,EAAE,CAAC;SACzD,mBAAmB,CAAC,IAAA,2BAAoB,EAAC,QAAQ,CAAC,CAAC;SACnD,gBAAgB,CAAC,MAAA,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,0CAAE,YAAY,EAAE,CAAC,CAAC;AACxE,CAAC;AA3BD,wBA2BC"}
|
|
@@ -12,6 +12,11 @@ import { dateToLocalDateProto, daysBetween, plusDays, plusMonthsClamped } from '
|
|
|
12
12
|
* `treasury_frn_fixings` and Rust's `treasury_frn_fixings`; all are tested
|
|
13
13
|
* against `test-fixtures/treasury-frn-fixings.json`.
|
|
14
14
|
* See `docs/adr/frn_reference_rate_fixings.md` (LM-382, LM-385, LM-386).
|
|
15
|
+
*
|
|
16
|
+
* Deprecated (LM-410): FRN fixings now come from price-service (MDI-100) and
|
|
17
|
+
* reach forSecurity ready to use through MarketData; nothing here picks them
|
|
18
|
+
* any more. To be deleted in LM-411, once ledger-service no longer calls the
|
|
19
|
+
* Java copy (LS-202). See docs/adr/product_input_builders.md.
|
|
15
20
|
*/
|
|
16
21
|
|
|
17
22
|
/** Treasury's standard bill terms, in weeks. */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
/**
|
|
30
|
+
* LM-410: product_inputs.forSecurity and ValuationRequests.typed.
|
|
31
|
+
*
|
|
32
|
+
* The shared cases live in test-fixtures/product-inputs/, one file per case,
|
|
33
|
+
* generated by ledger-models-python/test/requests/test_product_input_builders.py
|
|
34
|
+
* and read by the Java, Python and Rust tests too. The directory is listed at
|
|
35
|
+
* run time. See docs/adr/product_input_builders.md.
|
|
36
|
+
*/
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const hierarchy_json_1 = __importDefault(require("../../../../hierarchy.json"));
|
|
40
|
+
const product_inputs_1 = require("./product_inputs");
|
|
41
|
+
const ValuationRequests_1 = require("../../requests/valuation/ValuationRequests");
|
|
42
|
+
const errors_1 = require("../errors");
|
|
43
|
+
const measure_pb_1 = require("../../../fintekkers/models/position/measure_pb");
|
|
44
|
+
const position_pb_1 = require("../../../fintekkers/models/position/position_pb");
|
|
45
|
+
const price_pb_1 = require("../../../fintekkers/models/price/price_pb");
|
|
46
|
+
const security_pb_1 = require("../../../fintekkers/models/security/security_pb");
|
|
47
|
+
const local_timestamp_pb_1 = require("../../../fintekkers/models/util/local_timestamp_pb");
|
|
48
|
+
const valuation_request_pb_1 = require("../../../fintekkers/requests/valuation/valuation_request_pb");
|
|
49
|
+
const product_inputs_pb_1 = require("../../../fintekkers/requests/valuation/product_inputs_pb");
|
|
50
|
+
const FIXTURES = path.resolve(__dirname, '../../../../../test-fixtures/product-inputs');
|
|
51
|
+
const cases = fs.readdirSync(FIXTURES)
|
|
52
|
+
.filter((f) => f.endsWith('.json'))
|
|
53
|
+
.sort()
|
|
54
|
+
.map((f) => (Object.assign(Object.assign({}, JSON.parse(fs.readFileSync(path.join(FIXTURES, f), 'utf-8'))), { name: f.replace(/\.json$/, '') })));
|
|
55
|
+
const success = cases.filter((c) => c.arm !== undefined);
|
|
56
|
+
const errors = cases.filter((c) => c.error !== undefined);
|
|
57
|
+
const fixture = (name) => cases.find((c) => c.name === name);
|
|
58
|
+
const bytes = (hex) => Uint8Array.from(Buffer.from(hex, 'hex'));
|
|
59
|
+
const hexOf = (m) => Buffer.from(m.serializeBinary()).toString('hex');
|
|
60
|
+
const security = (c) => security_pb_1.SecurityProto.deserializeBinary(bytes(c.security_hex));
|
|
61
|
+
const price = (c) => price_pb_1.PriceProto.deserializeBinary(bytes(c.price_hex));
|
|
62
|
+
function marketData(c) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const md = (_a = c.market_data) !== null && _a !== void 0 ? _a : {};
|
|
65
|
+
return {
|
|
66
|
+
cpi: md.cpi_hex ? product_inputs_pb_1.InflationIndexInput.deserializeBinary(bytes(md.cpi_hex)) : undefined,
|
|
67
|
+
fixings: ((_b = md.fixings_hex) !== null && _b !== void 0 ? _b : []).map((h) => product_inputs_pb_1.ReferenceRateFixingProto.deserializeBinary(bytes(h))),
|
|
68
|
+
curve: md.curve_hex ? product_inputs_pb_1.YieldCurveInput.deserializeBinary(bytes(md.curve_hex)) : undefined,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function typedArgs(c) {
|
|
72
|
+
return [
|
|
73
|
+
local_timestamp_pb_1.LocalTimestampProto.deserializeBinary(bytes(c.typed.asof_hex)),
|
|
74
|
+
position_pb_1.PositionProto.deserializeBinary(bytes(c.typed.position_hex)),
|
|
75
|
+
c.typed.measures.map((m) => measure_pb_1.MeasureProto[m]),
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
function caught(fn) {
|
|
79
|
+
try {
|
|
80
|
+
fn();
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
return e;
|
|
84
|
+
}
|
|
85
|
+
throw new Error('expected a throw');
|
|
86
|
+
}
|
|
87
|
+
function expectError(e, spec) {
|
|
88
|
+
expect(e.constructor.name).toBe(spec.type);
|
|
89
|
+
if (spec.type === 'MissingMarketDataError') {
|
|
90
|
+
const m = e;
|
|
91
|
+
expect(m).toBeInstanceOf(errors_1.MissingMarketDataError);
|
|
92
|
+
expect([m.arm, m.kind, m.field]).toEqual([spec.arm, spec.kind, spec.field]);
|
|
93
|
+
expect(m.message).toContain(spec.arm);
|
|
94
|
+
expect(m.message).toContain(spec.kind);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
expect(e).toBeInstanceOf(errors_1.UnmappedProductTypeError);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// ---- forSecurity
|
|
101
|
+
test('fixtures cover every arm in valuation_arms', () => {
|
|
102
|
+
const entries = hierarchy_json_1.default.valuation_arms.entries;
|
|
103
|
+
const arms = new Set(entries.map((e) => e.arm));
|
|
104
|
+
expect(new Set(success.map((c) => c.arm))).toEqual(arms);
|
|
105
|
+
expect(success).toHaveLength(arms.size);
|
|
106
|
+
});
|
|
107
|
+
test.each(success.map((c) => [c.name, c]))('%s: forSecurity matches the fixture bytes', (_name, c) => {
|
|
108
|
+
expect(hexOf((0, product_inputs_1.forSecurity)(security(c), price(c), marketData(c)))).toBe(c.expected_hex);
|
|
109
|
+
});
|
|
110
|
+
// R1: the arm is armFor's, and each field is the input it came from.
|
|
111
|
+
test.each(success.map((c) => [c.name, c]))('%s: forSecurity fields', (_name, c) => {
|
|
112
|
+
const [s, p, md] = [security(c), price(c), marketData(c)];
|
|
113
|
+
const out = (0, product_inputs_1.forSecurity)(s, p, md);
|
|
114
|
+
expect((0, product_inputs_1.armFor)(s)).toBe(c.arm);
|
|
115
|
+
const body = {
|
|
116
|
+
bond: out.getBond(), tips: out.getTips(), frn: out.getFrn(), mbs: out.getMbs(), equity: out.getEquity(), cash: out.getCash(),
|
|
117
|
+
}[c.arm];
|
|
118
|
+
expect(body).toBeDefined();
|
|
119
|
+
expect(hexOf(body.getSecurity())).toBe(hexOf(s));
|
|
120
|
+
const fields = body;
|
|
121
|
+
if (c.arm === 'equity' || c.arm === 'cash') {
|
|
122
|
+
expect(hexOf(fields.getUnitPrice.call(body))).toBe(hexOf(p.getPrice()));
|
|
123
|
+
expect(fields.getCleanPrice).toBeUndefined();
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
expect(hexOf(fields.getCleanPrice.call(body))).toBe(hexOf(p.getPrice()));
|
|
127
|
+
expect(fields.getUnitPrice).toBeUndefined();
|
|
128
|
+
expect(fields.hasCostBasis.call(body)).toBe(false);
|
|
129
|
+
}
|
|
130
|
+
if (c.arm === 'tips')
|
|
131
|
+
expect(hexOf(out.getTips().getCpi())).toBe(hexOf(md.cpi));
|
|
132
|
+
if (c.arm === 'frn') {
|
|
133
|
+
expect(out.getFrn().getFixingsList().map(hexOf)).toEqual(md.fixings.map(hexOf));
|
|
134
|
+
expect(hexOf(out.getFrn().getCurve())).toBe(hexOf(md.curve));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
test.each(errors.map((c) => [c.name, c]))('%s: forSecurity throws the fixture error', (_name, c) => {
|
|
138
|
+
expectError(caught(() => (0, product_inputs_1.forSecurity)(security(c), price(c), marketData(c))), c.error);
|
|
139
|
+
});
|
|
140
|
+
test('forSecurity with no market data throws MissingMarketDataError(tips, CPI_U)', () => {
|
|
141
|
+
const c = fixture('tips');
|
|
142
|
+
for (const md of [undefined, null]) {
|
|
143
|
+
const e = caught(() => (0, product_inputs_1.forSecurity)(security(c), price(c), md));
|
|
144
|
+
expect(e).toBeInstanceOf(errors_1.MissingMarketDataError);
|
|
145
|
+
expect([e.arm, e.kind]).toEqual(['tips', 'CPI_U']);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
// ---- ValuationRequests.typed
|
|
149
|
+
test.each(success.map((c) => [c.name, c]))('%s: typed matches the fixture and sets only typed fields', (_name, c) => {
|
|
150
|
+
const productInput = (0, product_inputs_1.forSecurity)(security(c), price(c), marketData(c));
|
|
151
|
+
const [asof, position, measures] = typedArgs(c);
|
|
152
|
+
const request = ValuationRequests_1.ValuationRequests.typed(asof, productInput, position, measures);
|
|
153
|
+
// jspb writes fields in .proto declaration order (measures, 30, before
|
|
154
|
+
// position_input, 21), the other bindings in field-number order. Both are
|
|
155
|
+
// valid encodings of the same message, so compare the fixture re-encoded by
|
|
156
|
+
// jspb. ProductInput's declaration order is its field order: its bytes match
|
|
157
|
+
// the fixture as they are (test above).
|
|
158
|
+
expect(hexOf(request)).toBe(hexOf(valuation_request_pb_1.ValuationRequestProto.deserializeBinary(bytes(c.typed.expected_hex))));
|
|
159
|
+
expect(request.hasSecurityInput()).toBe(false);
|
|
160
|
+
expect(request.hasPriceInput()).toBe(false);
|
|
161
|
+
expect(request.hasPositionInput()).toBe(true);
|
|
162
|
+
expect(request.getPositionInput()).toBe(position);
|
|
163
|
+
expect(request.getProductInput()).toBe(productInput);
|
|
164
|
+
});
|
|
165
|
+
test.each(errors.map((c) => [c.name, c]))('%s: typed throws the fixture error', (_name, c) => {
|
|
166
|
+
const productInput = product_inputs_pb_1.ProductInput.deserializeBinary(bytes(c.typed.product_input_hex));
|
|
167
|
+
const [asof, position, measures] = typedArgs(c);
|
|
168
|
+
expectError(caught(() => ValuationRequests_1.ValuationRequests.typed(asof, productInput, position, measures)), c.error);
|
|
169
|
+
});
|
|
170
|
+
test('typed requires a position', () => {
|
|
171
|
+
const c = fixture('bond');
|
|
172
|
+
const [asof, , measures] = typedArgs(c);
|
|
173
|
+
const e = caught(() => ValuationRequests_1.ValuationRequests.typed(asof, (0, product_inputs_1.forSecurity)(security(c), price(c)), undefined, measures));
|
|
174
|
+
expect(e).toBeInstanceOf(errors_1.ModelValidationError);
|
|
175
|
+
expect(e.field).toBe('position_input');
|
|
176
|
+
});
|
|
177
|
+
test('typed rejects an arm armFor did not pick', () => {
|
|
178
|
+
const c = fixture('tips');
|
|
179
|
+
const wrong = new product_inputs_pb_1.ProductInput().setBond(new product_inputs_pb_1.BondInput().setSecurity(security(c)).setCleanPrice(price(c).getPrice()));
|
|
180
|
+
const [asof, position, measures] = typedArgs(c);
|
|
181
|
+
const e = caught(() => ValuationRequests_1.ValuationRequests.typed(asof, wrong, position, measures));
|
|
182
|
+
expect(e).toBeInstanceOf(errors_1.ModelValidationError);
|
|
183
|
+
expect(e).not.toBeInstanceOf(errors_1.MissingMarketDataError);
|
|
184
|
+
expect(e.field).toBe('product_input.bond');
|
|
185
|
+
});
|
|
186
|
+
test('typed rejects an input with no arm', () => {
|
|
187
|
+
const [asof, position, measures] = typedArgs(fixture('bond'));
|
|
188
|
+
const e = caught(() => ValuationRequests_1.ValuationRequests.typed(asof, new product_inputs_pb_1.ProductInput(), position, measures));
|
|
189
|
+
expect(e.field).toBe('product_input');
|
|
190
|
+
expect(() => (0, product_inputs_1.checkProductInput)(new product_inputs_pb_1.ProductInput())).toThrow(errors_1.ModelValidationError);
|
|
191
|
+
});
|
|
192
|
+
//# sourceMappingURL=product_input_builders.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product_input_builders.test.js","sourceRoot":"","sources":["product_input_builders.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;GAOG;AACH,uCAAyB;AACzB,2CAA6B;AAG7B,gFAAmD;AACnD,qDAAsF;AACtF,kFAA+E;AAC/E,sCAAmG;AACnG,+EAA8E;AAC9E,iFAAgF;AAChF,wEAAuE;AACvE,iFAAgF;AAChF,2FAAyF;AACzF,sGAAoG;AACpG,gGAEkE;AAElE,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,6CAA6C,CAAC,CAAC;AAcxF,MAAM,KAAK,GAAc,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC;KAC9C,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;KAClC,IAAI,EAAE;KACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iCAAM,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,KAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,IAAG,CAAC,CAAC;AACrH,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC;AACzD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CA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C,CAAC,CAAC;IAChD,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC,qCAAiB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IACjF,MAAM,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,6BAAoB,CAAC,CAAC;IAC/C,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,+BAAsB,CAAC,CAAC;IACrD,MAAM,CAAE,CAA0B,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AACvE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;IAC9C,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC,qCAAiB,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,gCAAY,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9F,MAAM,CAAE,CAA0B,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAChE,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,kCAAiB,EAAC,IAAI,gCAAY,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,6BAAoB,CAAC,CAAC;AACpF,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LM-410: product_inputs.forSecurity and ValuationRequests.typed.
|
|
3
|
+
*
|
|
4
|
+
* The shared cases live in test-fixtures/product-inputs/, one file per case,
|
|
5
|
+
* generated by ledger-models-python/test/requests/test_product_input_builders.py
|
|
6
|
+
* and read by the Java, Python and Rust tests too. The directory is listed at
|
|
7
|
+
* run time. See docs/adr/product_input_builders.md.
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import * as jspb from 'google-protobuf';
|
|
12
|
+
|
|
13
|
+
import hierarchy from '../../../../hierarchy.json';
|
|
14
|
+
import { armFor, checkProductInput, forSecurity, MarketData } from './product_inputs';
|
|
15
|
+
import { ValuationRequests } from '../../requests/valuation/ValuationRequests';
|
|
16
|
+
import { MissingMarketDataError, ModelValidationError, UnmappedProductTypeError } from '../errors';
|
|
17
|
+
import { MeasureProto } from '../../../fintekkers/models/position/measure_pb';
|
|
18
|
+
import { PositionProto } from '../../../fintekkers/models/position/position_pb';
|
|
19
|
+
import { PriceProto } from '../../../fintekkers/models/price/price_pb';
|
|
20
|
+
import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
21
|
+
import { LocalTimestampProto } from '../../../fintekkers/models/util/local_timestamp_pb';
|
|
22
|
+
import { ValuationRequestProto } from '../../../fintekkers/requests/valuation/valuation_request_pb';
|
|
23
|
+
import {
|
|
24
|
+
BondInput, InflationIndexInput, ProductInput, ReferenceRateFixingProto, YieldCurveInput,
|
|
25
|
+
} from '../../../fintekkers/requests/valuation/product_inputs_pb';
|
|
26
|
+
|
|
27
|
+
const FIXTURES = path.resolve(__dirname, '../../../../../test-fixtures/product-inputs');
|
|
28
|
+
|
|
29
|
+
interface ErrorSpec { type: string; arm?: string; kind?: string; field?: string }
|
|
30
|
+
interface Fixture {
|
|
31
|
+
name: string;
|
|
32
|
+
security_hex: string;
|
|
33
|
+
price_hex: string;
|
|
34
|
+
market_data?: { cpi_hex?: string; fixings_hex?: string[]; curve_hex?: string };
|
|
35
|
+
arm?: string;
|
|
36
|
+
expected_hex?: string;
|
|
37
|
+
error?: ErrorSpec;
|
|
38
|
+
typed: { asof_hex: string; position_hex: string; measures: string[]; expected_hex?: string; product_input_hex?: string };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const cases: Fixture[] = fs.readdirSync(FIXTURES)
|
|
42
|
+
.filter((f) => f.endsWith('.json'))
|
|
43
|
+
.sort()
|
|
44
|
+
.map((f) => ({ ...JSON.parse(fs.readFileSync(path.join(FIXTURES, f), 'utf-8')), name: f.replace(/\.json$/, '') }));
|
|
45
|
+
const success = cases.filter((c) => c.arm !== undefined);
|
|
46
|
+
const errors = cases.filter((c) => c.error !== undefined);
|
|
47
|
+
const fixture = (name: string): Fixture => cases.find((c) => c.name === name)!;
|
|
48
|
+
|
|
49
|
+
const bytes = (hex: string): Uint8Array => Uint8Array.from(Buffer.from(hex, 'hex'));
|
|
50
|
+
const hexOf = (m: jspb.Message): string => Buffer.from(m.serializeBinary()).toString('hex');
|
|
51
|
+
|
|
52
|
+
const security = (c: Fixture) => SecurityProto.deserializeBinary(bytes(c.security_hex));
|
|
53
|
+
const price = (c: Fixture) => PriceProto.deserializeBinary(bytes(c.price_hex));
|
|
54
|
+
function marketData(c: Fixture): MarketData {
|
|
55
|
+
const md = c.market_data ?? {};
|
|
56
|
+
return {
|
|
57
|
+
cpi: md.cpi_hex ? InflationIndexInput.deserializeBinary(bytes(md.cpi_hex)) : undefined,
|
|
58
|
+
fixings: (md.fixings_hex ?? []).map((h) => ReferenceRateFixingProto.deserializeBinary(bytes(h))),
|
|
59
|
+
curve: md.curve_hex ? YieldCurveInput.deserializeBinary(bytes(md.curve_hex)) : undefined,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function typedArgs(c: Fixture): [LocalTimestampProto, PositionProto, MeasureProto[]] {
|
|
63
|
+
return [
|
|
64
|
+
LocalTimestampProto.deserializeBinary(bytes(c.typed.asof_hex)),
|
|
65
|
+
PositionProto.deserializeBinary(bytes(c.typed.position_hex)),
|
|
66
|
+
c.typed.measures.map((m) => MeasureProto[m as keyof typeof MeasureProto]),
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function caught(fn: () => unknown): Error {
|
|
71
|
+
try {
|
|
72
|
+
fn();
|
|
73
|
+
} catch (e) {
|
|
74
|
+
return e as Error;
|
|
75
|
+
}
|
|
76
|
+
throw new Error('expected a throw');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function expectError(e: Error, spec: ErrorSpec): void {
|
|
80
|
+
expect(e.constructor.name).toBe(spec.type);
|
|
81
|
+
if (spec.type === 'MissingMarketDataError') {
|
|
82
|
+
const m = e as MissingMarketDataError;
|
|
83
|
+
expect(m).toBeInstanceOf(MissingMarketDataError);
|
|
84
|
+
expect([m.arm, m.kind, m.field]).toEqual([spec.arm, spec.kind, spec.field]);
|
|
85
|
+
expect(m.message).toContain(spec.arm);
|
|
86
|
+
expect(m.message).toContain(spec.kind);
|
|
87
|
+
} else {
|
|
88
|
+
expect(e).toBeInstanceOf(UnmappedProductTypeError);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ---- forSecurity
|
|
93
|
+
|
|
94
|
+
test('fixtures cover every arm in valuation_arms', () => {
|
|
95
|
+
const entries = (hierarchy as unknown as { valuation_arms: { entries: { arm: string }[] } }).valuation_arms.entries;
|
|
96
|
+
const arms = new Set(entries.map((e) => e.arm));
|
|
97
|
+
expect(new Set(success.map((c) => c.arm))).toEqual(arms);
|
|
98
|
+
expect(success).toHaveLength(arms.size);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test.each(success.map((c) => [c.name, c] as const))('%s: forSecurity matches the fixture bytes', (_name, c) => {
|
|
102
|
+
expect(hexOf(forSecurity(security(c), price(c), marketData(c)))).toBe(c.expected_hex);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// R1: the arm is armFor's, and each field is the input it came from.
|
|
106
|
+
test.each(success.map((c) => [c.name, c] as const))('%s: forSecurity fields', (_name, c) => {
|
|
107
|
+
const [s, p, md] = [security(c), price(c), marketData(c)];
|
|
108
|
+
const out = forSecurity(s, p, md);
|
|
109
|
+
expect(armFor(s)).toBe(c.arm);
|
|
110
|
+
const body = {
|
|
111
|
+
bond: out.getBond(), tips: out.getTips(), frn: out.getFrn(), mbs: out.getMbs(), equity: out.getEquity(), cash: out.getCash(),
|
|
112
|
+
}[c.arm!]!;
|
|
113
|
+
expect(body).toBeDefined();
|
|
114
|
+
expect(hexOf(body.getSecurity()!)).toBe(hexOf(s));
|
|
115
|
+
const fields = body as unknown as Record<string, unknown>;
|
|
116
|
+
if (c.arm === 'equity' || c.arm === 'cash') {
|
|
117
|
+
expect(hexOf((fields.getUnitPrice as () => jspb.Message).call(body))).toBe(hexOf(p.getPrice()!));
|
|
118
|
+
expect(fields.getCleanPrice).toBeUndefined();
|
|
119
|
+
} else {
|
|
120
|
+
expect(hexOf((fields.getCleanPrice as () => jspb.Message).call(body))).toBe(hexOf(p.getPrice()!));
|
|
121
|
+
expect(fields.getUnitPrice).toBeUndefined();
|
|
122
|
+
expect((fields.hasCostBasis as () => boolean).call(body)).toBe(false);
|
|
123
|
+
}
|
|
124
|
+
if (c.arm === 'tips') expect(hexOf(out.getTips()!.getCpi()!)).toBe(hexOf(md.cpi!));
|
|
125
|
+
if (c.arm === 'frn') {
|
|
126
|
+
expect(out.getFrn()!.getFixingsList().map(hexOf)).toEqual(md.fixings!.map(hexOf));
|
|
127
|
+
expect(hexOf(out.getFrn()!.getCurve()!)).toBe(hexOf(md.curve!));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test.each(errors.map((c) => [c.name, c] as const))('%s: forSecurity throws the fixture error', (_name, c) => {
|
|
132
|
+
expectError(caught(() => forSecurity(security(c), price(c), marketData(c))), c.error!);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('forSecurity with no market data throws MissingMarketDataError(tips, CPI_U)', () => {
|
|
136
|
+
const c = fixture('tips');
|
|
137
|
+
for (const md of [undefined, null]) {
|
|
138
|
+
const e = caught(() => forSecurity(security(c), price(c), md)) as MissingMarketDataError;
|
|
139
|
+
expect(e).toBeInstanceOf(MissingMarketDataError);
|
|
140
|
+
expect([e.arm, e.kind]).toEqual(['tips', 'CPI_U']);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// ---- ValuationRequests.typed
|
|
145
|
+
|
|
146
|
+
test.each(success.map((c) => [c.name, c] as const))('%s: typed matches the fixture and sets only typed fields', (_name, c) => {
|
|
147
|
+
const productInput = forSecurity(security(c), price(c), marketData(c));
|
|
148
|
+
const [asof, position, measures] = typedArgs(c);
|
|
149
|
+
const request = ValuationRequests.typed(asof, productInput, position, measures);
|
|
150
|
+
// jspb writes fields in .proto declaration order (measures, 30, before
|
|
151
|
+
// position_input, 21), the other bindings in field-number order. Both are
|
|
152
|
+
// valid encodings of the same message, so compare the fixture re-encoded by
|
|
153
|
+
// jspb. ProductInput's declaration order is its field order: its bytes match
|
|
154
|
+
// the fixture as they are (test above).
|
|
155
|
+
expect(hexOf(request)).toBe(hexOf(ValuationRequestProto.deserializeBinary(bytes(c.typed.expected_hex!))));
|
|
156
|
+
expect(request.hasSecurityInput()).toBe(false);
|
|
157
|
+
expect(request.hasPriceInput()).toBe(false);
|
|
158
|
+
expect(request.hasPositionInput()).toBe(true);
|
|
159
|
+
expect(request.getPositionInput()).toBe(position);
|
|
160
|
+
expect(request.getProductInput()).toBe(productInput);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test.each(errors.map((c) => [c.name, c] as const))('%s: typed throws the fixture error', (_name, c) => {
|
|
164
|
+
const productInput = ProductInput.deserializeBinary(bytes(c.typed.product_input_hex!));
|
|
165
|
+
const [asof, position, measures] = typedArgs(c);
|
|
166
|
+
expectError(caught(() => ValuationRequests.typed(asof, productInput, position, measures)), c.error!);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('typed requires a position', () => {
|
|
170
|
+
const c = fixture('bond');
|
|
171
|
+
const [asof, , measures] = typedArgs(c);
|
|
172
|
+
const e = caught(() => ValuationRequests.typed(asof, forSecurity(security(c), price(c)), undefined, measures));
|
|
173
|
+
expect(e).toBeInstanceOf(ModelValidationError);
|
|
174
|
+
expect((e as ModelValidationError).field).toBe('position_input');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('typed rejects an arm armFor did not pick', () => {
|
|
178
|
+
const c = fixture('tips');
|
|
179
|
+
const wrong = new ProductInput().setBond(new BondInput().setSecurity(security(c)).setCleanPrice(price(c).getPrice()));
|
|
180
|
+
const [asof, position, measures] = typedArgs(c);
|
|
181
|
+
const e = caught(() => ValuationRequests.typed(asof, wrong, position, measures));
|
|
182
|
+
expect(e).toBeInstanceOf(ModelValidationError);
|
|
183
|
+
expect(e).not.toBeInstanceOf(MissingMarketDataError);
|
|
184
|
+
expect((e as ModelValidationError).field).toBe('product_input.bond');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('typed rejects an input with no arm', () => {
|
|
188
|
+
const [asof, position, measures] = typedArgs(fixture('bond'));
|
|
189
|
+
const e = caught(() => ValuationRequests.typed(asof, new ProductInput(), position, measures));
|
|
190
|
+
expect((e as ModelValidationError).field).toBe('product_input');
|
|
191
|
+
expect(() => checkProductInput(new ProductInput())).toThrow(ModelValidationError);
|
|
192
|
+
});
|