ledger_models/fintekkers.models.position.rs
1#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
2#[repr(i32)]
3pub enum FieldProto {
4 UnknownField = 0,
5 /// (UUID.class)
6 Id = 1,
7 /// ZonedDateTime
8 AsOf = 2,
9 /// Attribute fields. Likely to be fields that one would pivot on.
10 ///
11 /// LocalDate.class
12 EffectiveDate = 10,
13 /// common.model.strategy.Strategy.class
14 Strategy = 11,
15 /// common.model.security.Security.class
16 Security = 12,
17 SecurityDescription = 61,
18 SecurityIssuerName = 62,
19 /// common.model.security.Security.class
20 CashImpactSecurity = 13,
21 /// Security Fields
22 ///
23 /// AssetClass(String.class), //FixedIncome, Equity, etc
24 AssetClass = 50,
25 /// ProductClass(String.class), //Bond, CashEquity, etc
26 ProductClass = 51,
27 /// ProductType (String.class), //TBILL, BOND, etc
28 ProductType = 52,
29 SecurityId = 53,
30 Identifier = 54,
31 /// 1M
32 Tenor = 55,
33 IssueDate = 58,
34 MaturityDate = 56,
35 AdjustedTenor = 57,
36 /// Portfolio fields
37 ///
38 /// common.model.portfolio.Portfolio.class
39 Portfolio = 14,
40 /// UUID
41 PortfolioId = 15,
42 PortfolioName = 60,
43 /// Miscellaneous
44 ///
45 /// common.model.price.Price.class
46 Price = 16,
47 /// UUID
48 PriceId = 17,
49 /// Boolean.class
50 IsCancelled = 18,
51 /// PositionStatus.class
52 PositionStatus = 19,
53 /// Transaction only
54 ///
55 /// TradeDate(LocalDate.class),
56 TradeDate = 30,
57 /// SettlementDate(LocalDate.class),
58 SettlementDate = 31,
59 /// BUY, SELL, MATURATION, etc (TransactionType.class)
60 TransactionType = 32,
61 /// Tax Lot only
62 ///
63 /// TaxLotOpenDate(LocalDate.class),
64 TaxLotOpenDate = 40,
65 /// TaxLotCloseDate(LocalDate.class),
66 TaxLotCloseDate = 41,
67}
68impl FieldProto {
69 /// String value of the enum field names used in the ProtoBuf definition.
70 ///
71 /// The values are not transformed in any way and thus are considered stable
72 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
73 pub fn as_str_name(&self) -> &'static str {
74 match self {
75 FieldProto::UnknownField => "UNKNOWN_FIELD",
76 FieldProto::Id => "ID",
77 FieldProto::AsOf => "AS_OF",
78 FieldProto::EffectiveDate => "EFFECTIVE_DATE",
79 FieldProto::Strategy => "STRATEGY",
80 FieldProto::Security => "SECURITY",
81 FieldProto::SecurityDescription => "SECURITY_DESCRIPTION",
82 FieldProto::SecurityIssuerName => "SECURITY_ISSUER_NAME",
83 FieldProto::CashImpactSecurity => "CASH_IMPACT_SECURITY",
84 FieldProto::AssetClass => "ASSET_CLASS",
85 FieldProto::ProductClass => "PRODUCT_CLASS",
86 FieldProto::ProductType => "PRODUCT_TYPE",
87 FieldProto::SecurityId => "SECURITY_ID",
88 FieldProto::Identifier => "IDENTIFIER",
89 FieldProto::Tenor => "TENOR",
90 FieldProto::IssueDate => "ISSUE_DATE",
91 FieldProto::MaturityDate => "MATURITY_DATE",
92 FieldProto::AdjustedTenor => "ADJUSTED_TENOR",
93 FieldProto::Portfolio => "PORTFOLIO",
94 FieldProto::PortfolioId => "PORTFOLIO_ID",
95 FieldProto::PortfolioName => "PORTFOLIO_NAME",
96 FieldProto::Price => "PRICE",
97 FieldProto::PriceId => "PRICE_ID",
98 FieldProto::IsCancelled => "IS_CANCELLED",
99 FieldProto::PositionStatus => "POSITION_STATUS",
100 FieldProto::TradeDate => "TRADE_DATE",
101 FieldProto::SettlementDate => "SETTLEMENT_DATE",
102 FieldProto::TransactionType => "TRANSACTION_TYPE",
103 FieldProto::TaxLotOpenDate => "TAX_LOT_OPEN_DATE",
104 FieldProto::TaxLotCloseDate => "TAX_LOT_CLOSE_DATE",
105 }
106 }
107 /// Creates an enum from field names used in the ProtoBuf definition.
108 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
109 match value {
110 "UNKNOWN_FIELD" => Some(Self::UnknownField),
111 "ID" => Some(Self::Id),
112 "AS_OF" => Some(Self::AsOf),
113 "EFFECTIVE_DATE" => Some(Self::EffectiveDate),
114 "STRATEGY" => Some(Self::Strategy),
115 "SECURITY" => Some(Self::Security),
116 "SECURITY_DESCRIPTION" => Some(Self::SecurityDescription),
117 "SECURITY_ISSUER_NAME" => Some(Self::SecurityIssuerName),
118 "CASH_IMPACT_SECURITY" => Some(Self::CashImpactSecurity),
119 "ASSET_CLASS" => Some(Self::AssetClass),
120 "PRODUCT_CLASS" => Some(Self::ProductClass),
121 "PRODUCT_TYPE" => Some(Self::ProductType),
122 "SECURITY_ID" => Some(Self::SecurityId),
123 "IDENTIFIER" => Some(Self::Identifier),
124 "TENOR" => Some(Self::Tenor),
125 "ISSUE_DATE" => Some(Self::IssueDate),
126 "MATURITY_DATE" => Some(Self::MaturityDate),
127 "ADJUSTED_TENOR" => Some(Self::AdjustedTenor),
128 "PORTFOLIO" => Some(Self::Portfolio),
129 "PORTFOLIO_ID" => Some(Self::PortfolioId),
130 "PORTFOLIO_NAME" => Some(Self::PortfolioName),
131 "PRICE" => Some(Self::Price),
132 "PRICE_ID" => Some(Self::PriceId),
133 "IS_CANCELLED" => Some(Self::IsCancelled),
134 "POSITION_STATUS" => Some(Self::PositionStatus),
135 "TRADE_DATE" => Some(Self::TradeDate),
136 "SETTLEMENT_DATE" => Some(Self::SettlementDate),
137 "TRANSACTION_TYPE" => Some(Self::TransactionType),
138 "TAX_LOT_OPEN_DATE" => Some(Self::TaxLotOpenDate),
139 "TAX_LOT_CLOSE_DATE" => Some(Self::TaxLotCloseDate),
140 _ => None,
141 }
142 }
143}
144/// Absent versus zero: a measure that is missing from a position (no
145/// MeasureMapEntry for it, or an entry with no measure_decimal_value) means
146/// "not computable" for that position, e.g. a price or input it needs was
147/// unavailable. It is distinct from a computed 0, which is a real value and is
148/// always sent as "0".
149///
150/// Serializers in every language must omit a measure they could not compute and
151/// never zero-fill it; deserializers must read an absent measure back as
152/// absent/null, never as 0.
153#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
154#[repr(i32)]
155pub enum MeasureProto {
156 /// Placeholder for unset or unrecognized measure values.
157 /// Should never be requested in a valuation call.
158 UnknownMeasure = 0,
159 /// The signed quantity of a position (e.g. number of shares, or total face value of bonds held).
160 /// This is an input measure provided on the PositionProto, not a computed output.
161 ///
162 /// Formula: N/A — user-supplied input.
163 /// Applicability: All security types (Bond, TIPS, FRN, Equity, Cash).
164 /// Units: Units of the security (shares for equity, face-value dollars for bonds).
165 DirectedQuantity = 1,
166 /// The current dollar value of a position at the given market price.
167 ///
168 /// Formula:
169 /// MarketValue = (price * face_value / 100) * (directed_quantity / face_value)
170 /// = price / 100 * directed_quantity
171 /// Where price is quoted as a percentage of par (e.g. 95 means 95% of face).
172 ///
173 /// Example: face=1000, price=95, qty=20000 → MV = 95/100 * 20000 = 19,000.
174 ///
175 /// Formula (TIPS): the real clean price is scaled by the index ratio.
176 /// MarketValue = (clean_price / 100 * face_value * index_ratio) * (directed_quantity / face_value)
177 /// = clean_price / 100 * index_ratio * directed_quantity
178 /// Where index_ratio is INDEX_RATIO: rounded to 5 decimals per 31 CFR 356
179 /// Appendix B, and unfloored. The deflation floor does not apply to market
180 /// value (see INFLATION_ADJUSTED_PRINCIPAL).
181 /// The TIPS result is rounded to cents (a project rule, not Appendix B
182 /// text), so it equals the PROFIT_LOSS (TIPS) market side.
183 ///
184 /// Example (TIPS): price=97.5, index_ratio=1.2, qty=20000 → MV = 97.5/100 * 1.2 * 20000 = 23,400.
185 ///
186 /// Model assumptions: None — this is a direct mark-to-market calculation.
187 /// Applicability: Bond, TIPS, FRN, Equity (price=share price, face_value=1), Cash.
188 /// Units: Dollars (or settlement currency).
189 MarketValue = 2,
190 /// The original purchase price of the security, before any adjustments for
191 /// amortization, accretion, or corporate actions.
192 ///
193 /// Formula: Returns the price_input as-is (quoted as % of par for bonds).
194 /// Over time this may incorporate adjustments such as stock splits.
195 ///
196 /// Model assumptions: None — pass-through of the input price.
197 /// Applicability: Bond, TIPS, FRN, Equity, Cash.
198 /// Units: Quoted price (% of par for bonds; dollar price for equities).
199 UnadjustedCostBasis = 3,
200 /// Tax amortised cost, per 100 face, quantity-weighted over the open lots
201 /// (LM-364; implemented under VS-110). See docs/adr/amortisation_elections.md.
202 ///
203 /// Inputs: cost_basis (CostBasisInput) on BondInput, TipsInput or FrnInput:
204 /// lots, the holding's open TaxLotProto lots, and elections, the
205 /// portfolio's AmortisationElectionsProto (unset = every default).
206 ///
207 /// Formula, for each open lot i:
208 /// acb_i = the lot's amortised cost per 100 face at the valuation date:
209 /// price_i, adjusted by the OID, premium and market-discount rules below.
210 /// AdjustedCostBasis = sum(open_quantity_i * acb_i) / sum(open_quantity_i)
211 ///
212 /// OID: always accreted (mandatory, whatever the elections) at constant yield
213 /// from the issue price (IssuanceProto.price_for_single_price_auction,
214 /// MDI-82), reduced by any acquisition premium.
215 /// Premium (IRC §171): amortised at constant yield if elected
216 /// (bond_premium; the default is PREMIUM_ELECTED).
217 /// Market discount: accreted only with INCLUDE_CURRENTLY, ratably or at
218 /// constant yield per market_discount_accrual (the default is RATABLE);
219 /// otherwise (AT_DISPOSITION, the default) left until disposition.
220 /// De minimis: OID and market discount below 0.25% × complete years to
221 /// maturity are treated as zero.
222 /// Accrual start: from each lot's open_date plus the product's settlement lag
223 /// (e.g. T+1 for Treasuries).
224 /// TIPS: amortise in real terms, then multiply by the index ratio
225 /// (INDEX_RATIO) at the valuation date, giving a figure per 100 original
226 /// face in nominal dollars:
227 /// AdjustedCostBasis = sum(open_quantity_i * real_acb_i) / sum(open_quantity_i)
228 /// * IndexRatio(valuation date)
229 /// real_acb_i: lot i's amortised cost per 100 real face. It starts from the
230 /// lot's real purchase price (TaxLotProto.price) and accrues at constant
231 /// yield on real principal.
232 /// open_quantity_i: the lot's original (unadjusted) face.
233 /// Accrual start: as above, on real principal. valuation-service owns the
234 /// settlement lag; lots carry no settlement field.
235 /// Elections: premium and market discount accrue or not per the elections,
236 /// as in the fixed-rate rules above.
237 /// IndexRatio(valuation date): INDEX_RATIO for the UTC date of
238 /// ValuationRequestProto.asof_datetime. It uses only the m-3 and m-2
239 /// readings in TipsInput.cpi. Extra lot months there serve PROFIT_LOSS
240 /// and are ignored here.
241 /// Rounding: the index ratio is INDEX_RATIO, rounded to 5 decimals per
242 /// 31 CFR 356 Appendix B. real_acb_i, the weighted average and the
243 /// result are not rounded further.
244 /// Deflation floor: not applied. It applies only to final principal
245 /// (INFLATION_ADJUSTED_PRINCIPAL), never to the basis.
246 /// Example: lots of 10000 at real_acb 99.00 and 5000 at 101.50, index
247 /// ratio 1.2 -> (10000*99.00 + 5000*101.50) / 15000 * 1.2 = 119.80.
248 /// FRN: use the equivalent fixed rate from the fixing at settlement.
249 /// Treasury FRN (frn_extension.reference_rate_index T_BILL_13_WEEK, LM-383):
250 /// Inputs: FrnInput.cost_basis (lots and elections) and FrnInput.fixings.
251 /// Per lot: amortise each lot as the equivalent fixed-rate instrument,
252 /// using the same constant-yield, elections and de minimis rules as the
253 /// fixed-rate bonds above.
254 /// Coupon: the lot's equivalent fixed coupon, as a decimal fraction, is
255 /// coupon_i = MMY(fixing_i) + spread / 10000
256 /// fixing_i: the fixing in effect at the lot's accrual start, i.e. the
257 /// FrnInput.fixings entry with the latest fixing_date on or before it.
258 /// spread: frn_extension.spread, in basis points.
259 /// OID: the fixing in effect on bond_details.issue_date (the latest
260 /// fixing_date on or before it) sets the issue-date OID schedule.
261 /// Resets: later coupon resets do not change a lot's schedule.
262 /// Conversion: fixings.rate is the published high discount rate in
263 /// percent (see ReferenceRateFixingProto.rate). valuation-service
264 /// converts it to the money-market yield, on a 360-day basis:
265 /// MMY = 360 * d / (360 - d * t)
266 /// d = rate / 100.
267 /// t = bill_maturity_date - bill_issue_date, in days, both from the same
268 /// fixing. bill_issue_date is the chosen auction's own issue date, so
269 /// a reopened bill counts from the reopening.
270 /// Example: rate 4.215, t 91 -> d = 0.04215,
271 /// MMY = 360 * 0.04215 / (360 - 0.04215 * 91) = 0.042604 (rounded here only).
272 /// Missing data: no fixing on or before a needed date (a lot's accrual
273 /// start, or the issue date) makes the request invalid.
274 /// Other indices (e.g. SOFR): not defined yet.
275 /// No lots: the measure is absent, with a "no open lots" warning, never 0.
276 ///
277 /// Scope: tax basis only. Book (GAAP/IFRS) cost is out of scope.
278 /// Applicability: TREASURY_NOTE, TREASURY_BOND, SOVEREIGN_BOND, CORP_BOND,
279 /// MUNI_BOND, TIPS, TREASURY_FRN.
280 /// Units: Price per 100 face (% of par). TIPS: per 100 original face, in
281 /// nominal dollars.
282 AdjustedCostBasis = 4,
283 /// Annual coupon income as a percentage of the current market price.
284 ///
285 /// Formula (coupon-bearing bonds):
286 /// CurrentYield = (coupon_rate * principal) / (price * face_value / 100)
287 /// Where principal = face_value for nominal bonds, or inflation-adjusted principal for TIPS.
288 ///
289 /// Formula (zero-coupon bonds):
290 /// CurrentYield = (face_value / dollar_price)^(1 / years_to_maturity) - 1
291 /// This is the annualized investment yield from discount to par.
292 ///
293 /// Model assumptions: Assumes coupon income is constant (no reinvestment assumption).
294 /// For TIPS, uses the inflation-adjusted principal for the annual coupon calculation.
295 /// Day count: Actual/365 for years-to-maturity calculation.
296 /// Applicability: Bond, TIPS. (Equity dividend yield not yet supported.)
297 /// Units: Decimal (0-1 scale; e.g. 0.0526 = 5.26%).
298 CurrentYield = 5,
299 /// The annualized rate of return assuming the bond is held to maturity and all
300 /// coupons are reinvested at the same rate. This is the internal rate of return
301 /// that equates the present value of all future cashflows to the current price.
302 ///
303 /// Formula:
304 /// Solve for r (annual) such that:
305 /// price * (face / 100) = Sum_{t=1}^{N} [C / (1 + r/m)^t] + F / (1 + r/m)^N
306 /// Where C = periodic coupon, F = principal (face or inflation-adjusted),
307 /// m = coupon frequency, N = number of periods.
308 /// For TIPS the left side is also scaled by index_ratio (see REAL_YIELD).
309 ///
310 /// Solver: Newton-Raphson iteration (ytm_solver.rs) with the linear approximation
311 /// YTM ≈ (annual_coupon + (F - P) / years) / ((F + P) / 2)
312 /// as the initial guess. Converges to the exact YTM where PV = price.
313 ///
314 /// Model assumptions:
315 /// - Coupon reinvestment at the YTM rate (standard bond math assumption).
316 /// - For TIPS: returns the same value as REAL_YIELD (the real yield), and adds
317 /// this warning to the response summary:
318 /// "YIELD_TO_MATURITY for TIPS is the real yield (same as REAL_YIELD); a nominal
319 /// yield needs an inflation forecast". There is no nominal TIPS yield without
320 /// an inflation forecast.
321 /// - Settlement on a coupon date (no accrued interest adjustment currently).
322 /// - Day count: Actual/365 for years-to-maturity.
323 ///
324 /// Applicability: Bond, TIPS. Not meaningful for FRN (use DISCOUNT_MARGIN) or Equity.
325 /// Units: Decimal (0-1 scale; e.g. 0.06 = 6.00% annual).
326 YieldToMaturity = 7,
327 /// The weighted average time (in years) to receive all cashflows from a bond,
328 /// where each cashflow's weight is its proportion of the bond's total present value.
329 ///
330 /// Formula:
331 /// D = Sum_{t=1}^{N} [(t / m) * PV_t / TotalPV]
332 /// Where PV_t = cashflow_t / (1 + r/m)^t, TotalPV = Sum(PV_t),
333 /// m = coupon frequency, r = YTM.
334 /// For TIPS, r = REAL_YIELD and cashflow_t is the inflation-adjusted cash flow.
335 ///
336 /// Model assumptions:
337 /// - Uses the bond's YTM (from Newton-Raphson solver) as the discount rate.
338 /// - Flat yield curve (single rate for all maturities).
339 /// - Settlement on a coupon date (integer period exponents).
340 ///
341 /// Applicability: Bond, TIPS. Not typically used for FRN (spread duration is the
342 /// relevant risk measure). Not applicable to Equity or Cash.
343 /// Units: Years (e.g. 4.41 = 4.41 years).
344 MacaulayDuration = 8,
345 /// The theoretical price of a bond computed as the sum of all future cashflows
346 /// (coupons + principal) discounted at the bond's yield to maturity.
347 ///
348 /// Formula:
349 /// PV = Sum_{t=1}^{N} [C / (1 + r/m)^t] + F / (1 + r/m)^N
350 /// Returned as: PV_dollar / (face_value / 100) (quoted price, % of par).
351 ///
352 /// The YTM used for discounting is computed via Newton-Raphson from the input price,
353 /// which guarantees the three-way invariant:
354 /// price == present_value == sum(cashflow_pvs)
355 ///
356 /// Model assumptions:
357 /// - Same as YIELD_TO_MATURITY (the discount rate is derived from the input price).
358 /// - For TIPS: the inflation-adjusted cash flows are discounted at REAL_YIELD,
359 /// consistent with the scaled price clean_price × index_ratio (so the
360 /// invariant reads clean_price × index_ratio == present_value).
361 ///
362 /// Applicability: Bond, TIPS. For FRN, PV uses the discount margin framework instead.
363 /// Units: Quoted price (% of par; e.g. 95.00 = $95 per $100 face).
364 PresentValue = 9,
365 /// The yield of a TIPS bond in real (inflation-adjusted) terms. This is the return
366 /// an investor earns above the rate of inflation.
367 ///
368 /// Formula (TIPS):
369 /// Solve for r (annual) such that:
370 /// clean_price × index_ratio × face / 100 = Σ PV(inflation-adjusted cash flows at r)
371 /// The quoted real price is scaled by the same index ratio as the cash flows, so
372 /// the result is the true real yield and does not change with CPI.
373 ///
374 /// Model assumptions:
375 /// - Same solver and conventions as YIELD_TO_MATURITY.
376 /// - PRESENT_VALUE, MACAULAY_DURATION, MODIFIED_DURATION and CONVEXITY for TIPS
377 /// are computed at this real yield on the inflation-adjusted cash flows.
378 ///
379 /// Applicability: TIPS only. For nominal bonds, returns the same value as YTM.
380 /// Units: Decimal (0-1 scale; e.g. 0.02 = 2.00% real annual yield).
381 RealYield = 10,
382 /// The inflation-adjusted principal of a TIPS bond, reflecting the cumulative
383 /// change in the Consumer Price Index (CPI) since the bond's issuance.
384 ///
385 /// Formula:
386 /// index_ratio = INDEX_RATIO = reference_cpi / base_cpi
387 /// adjusted_principal = max(face_value * index_ratio, face_value)
388 /// The max() enforces the deflation floor: at maturity, TIPS redeem at no less
389 /// than the original face value, even if CPI has fallen. The floor applies
390 /// to this measure only; INDEX_RATIO and MARKET_VALUE are unfloored.
391 ///
392 /// Model assumptions:
393 /// - Uses base_cpi from security.tips_extension and the reference CPI from
394 /// TipsInput.cpi (see REFERENCE_CPI).
395 /// - Deflation floor applies only to the principal at maturity; interim coupons
396 /// use the raw (potentially deflated) adjusted principal.
397 ///
398 /// Applicability: TIPS only.
399 /// Units: Dollars (e.g. 103.36 for face=100 with 3.36% cumulative inflation).
400 InflationAdjustedPrincipal = 11,
401 /// Requests the full schedule of future cashflows for a bond or TIPS.
402 /// When this measure is included in the request, the ValuationResponseProto will
403 /// populate the `cashflows` repeated field with one CashflowProto per payment period.
404 ///
405 /// Each CashflowProto contains:
406 /// - cashflow_date: the payment date
407 /// - fv_amount: the undiscounted (future) value of the cashflow
408 /// - pv_amount: the cashflow discounted to settlement at the bond's YTM
409 /// - coupon_rate: the annualized coupon rate for this period (constant for
410 /// fixed-rate bonds; reference_rate + spread for FRNs)
411 ///
412 /// The sum of all pv_amounts equals the PRESENT_VALUE measure (three-way invariant).
413 ///
414 /// Model assumptions: Same as PRESENT_VALUE.
415 /// Applicability: Bond, TIPS, FRN.
416 /// Units: fv_amount and pv_amount in dollars; coupon_rate as percentage.
417 PresentValueCashflows = 12,
418 /// The discount margin of a Floating Rate Note (FRN) — the spread over the
419 /// reference rate at which the market discounts the FRN's projected cashflows
420 /// to arrive at its current price. This is the FRN analogue of YTM.
421 ///
422 /// Formula:
423 /// Solve for DM such that:
424 /// price = Sum_{t=1}^{N} [(R + QM)/m * FV / (1 + (R + DM)/m)^t]
425 /// + FV / (1 + (R + DM)/m)^N
426 /// Where R = reference rate, QM = quoted margin (fixed spread), FV = face value,
427 /// m = payment frequency, N = number of remaining periods.
428 ///
429 /// Solver: Newton-Raphson — same solver as YTM (ytm_solver.rs). Solve for the
430 /// periodic discount rate, then extract DM = (solved_rate * m) - R.
431 ///
432 /// Model assumptions:
433 /// - Flat forward rates: all future reference rate fixings are assumed equal to
434 /// the current observation of R. This is the standard FRN simplification.
435 /// - When DM = QM, price = par (100) on a reset date.
436 /// - When DM > QM, price < par (discount); when DM < QM, price > par (premium).
437 ///
438 /// Applicability: FRN only. For fixed-rate bonds, use YIELD_TO_MATURITY.
439 /// Units: Decimal (0-1 scale; e.g. 0.0075 = 75 basis points).
440 DiscountMargin = 13,
441 /// The sensitivity of an FRN's price to a 1 basis point change in the discount
442 /// margin. This is the primary risk measure for FRNs, analogous to modified
443 /// duration for fixed-rate bonds but measuring spread risk rather than rate risk.
444 ///
445 /// Formula (numerical differentiation):
446 /// SpreadDuration = -(1/P) * dP/dDM
447 /// ≈ (P_down - P_up) / (2 * 0.0001 * P_base)
448 /// Where P_down and P_up are the FRN prices when DM is bumped down and up by 1bp.
449 ///
450 /// For a 2-year quarterly FRN at par, spread duration ≈ 1.90 years.
451 /// This is approximately equal to the weighted average time to maturity.
452 ///
453 /// Model assumptions:
454 /// - Same flat-forward assumption as DISCOUNT_MARGIN.
455 /// - Uses a symmetric 1bp bump for numerical differentiation.
456 /// - Interest rate duration of an FRN is near-zero (≈ time to next reset);
457 /// spread duration captures the economically significant risk.
458 ///
459 /// Applicability: FRN only. For fixed-rate bonds, use MACAULAY_DURATION.
460 /// Units: Years (e.g. 1.90 = a 1bp spread widening causes ~1.90bp price decline).
461 SpreadDuration = 14,
462 /// The par yield at a given maturity point on the yield curve. The par yield is
463 /// the coupon rate at which a bond would trade at par (price = 100) for a given
464 /// maturity. This is the most commonly quoted yield curve.
465 ///
466 /// Formula:
467 /// For each maturity point, the par yield is the coupon rate c such that:
468 /// 100 = Sum_{t=1}^{N} [c/m / (1 + r_t)^t] + 100 / (1 + r_N)^N
469 /// Where r_t are spot rates, m = coupon frequency, N = number of periods.
470 ///
471 /// In practice, for on-the-run bonds, par yield ≈ YTM when the bond trades
472 /// near par. The par yield curve is bootstrapped from observed bond prices.
473 ///
474 /// Model assumptions:
475 /// - Coupon frequency matches the market convention (semiannual for US Treasuries).
476 /// - Interpolation between observed maturities uses the method specified in
477 /// the CurveRequestProto (linear by default).
478 ///
479 /// Applicability: Bond, TIPS (real par yield curve).
480 /// Not applicable to FRN, Equity, or Cash.
481 /// Units: Decimal (0-1 scale; e.g. 0.045 = 4.50% annual).
482 ParYield = 15,
483 /// The spot (zero-coupon) yield at a given maturity. The spot rate is the yield
484 /// on a zero-coupon bond maturing at that point — it represents the pure time
485 /// value of money with no reinvestment assumption.
486 ///
487 /// Formula:
488 /// Bootstrapped from the par yield curve:
489 /// P = 100 / (1 + s_N)^N → s_N = (100 / P)^(1/N) - 1
490 /// Where s_N is the N-period spot rate, P is the zero-coupon bond price
491 /// implied by stripping coupons from the par curve.
492 ///
493 /// For the first period, spot rate = par yield. For subsequent periods,
494 /// the bootstrap solves:
495 /// 100 = Sum_{t=1}^{N-1} [c/m / (1 + s_t)^t] + (100 + c/m) / (1 + s_N)^N
496 /// for s_N, using previously computed spot rates s_1..s_{N-1}.
497 ///
498 /// Model assumptions:
499 /// - Requires a complete par yield curve as input (no gaps).
500 /// - Bootstrap assumes exact coupon dates (no day-count adjustments).
501 ///
502 /// Applicability: Derived from Bond par curve. Used for discounting cashflows
503 /// and computing forward rates.
504 /// Units: Decimal (0-1 scale; e.g. 0.046 = 4.60% annual).
505 SpotYield = 16,
506 /// The forward yield between two future dates, implied by the spot curve.
507 /// The forward rate f(t1, t2) is the rate agreed today for borrowing/lending
508 /// between future times t1 and t2.
509 ///
510 /// Formula:
511 /// f(t1, t2) = [(1 + s_{t2})^{t2} / (1 + s_{t1})^{t1}]^{1/(t2 - t1)} - 1
512 /// Where s_t are spot rates for maturities t1 and t2.
513 ///
514 /// For example, the 1-year forward rate 1 year from now (1y1y) is:
515 /// f(1,2) = [(1 + s_2)^2 / (1 + s_1)]^1 - 1
516 ///
517 /// Model assumptions:
518 /// - Derived from the spot curve (which is bootstrapped from par).
519 /// - Assumes no arbitrage between spot and forward rates.
520 /// - The forward period is defined by adjacent tenor points in the
521 /// CurveRequestProto.
522 ///
523 /// Applicability: Derived from Bond spot curve. Used for rate expectations
524 /// and forward-starting instrument pricing.
525 /// Units: Decimal (0-1 scale; e.g. 0.048 = 4.80% annual forward rate).
526 ForwardYield = 17,
527 /// The profit or loss on a position relative to its cost basis.
528 ///
529 /// Formula:
530 /// ProfitLoss = MarketValue - (UnadjustedCostBasis / d * DirectedQuantity)
531 /// Where d = 100 for par-quoted securities (bonds, TIPS, FRNs) and
532 /// d = 1 for dollar-quoted securities (equities, cash).
533 ///
534 /// Example (bond): MV=19,000, UCB=90 (% of par), qty=20000 face →
535 /// ProfitLoss = 19000 - (90 / 100 * 20000) = 19000 - 18000 = 1,000.
536 /// Example (equity): MV=5,500, UCB=50 (dollars per share), qty=100 →
537 /// ProfitLoss = 5500 - (50 / 1 * 100) = 5500 - 5000 = 500.
538 ///
539 /// The measure is absent, never 0, when MarketValue, UnadjustedCostBasis
540 /// or DirectedQuantity is unavailable.
541 ///
542 /// Formula (TIPS): replaces the formula above for TIPS. Nominal and clean,
543 /// with both sides index-adjusted (LM-405):
544 /// MarketSide = clean_price / 100 * IndexRatio(valuation date) * directed_quantity
545 /// CostSide = sum over the open lots i in TipsInput.cost_basis.lots of
546 /// price_i / 100 * IndexRatio(S_i) * face_i
547 /// ProfitLoss = MarketSide - CostSide
548 /// MarketSide: the real clean price (TipsInput.clean_price) scaled by
549 /// INDEX_RATIO for the valuation date. It equals MARKET_VALUE for TIPS.
550 /// price_i: the lot's real purchase price per 100 face (TaxLotProto.price).
551 /// face_i: the open lot's remaining quantity (TaxLotProto.open_quantity),
552 /// in original (unadjusted) face units.
553 /// S_i: the lot's settlement date, TaxLotProto.open_date plus the product's
554 /// settlement lag (T+1 business day for Treasuries). valuation-service
555 /// owns the lag; lots carry no settlement field.
556 /// IndexRatio(S_i): REFERENCE_CPI's daily interpolation with S_i as the
557 /// settlement date, from the CPI-U readings for months L-3 and L-2 of
558 /// S_i's month L in TipsInput.cpi.readings, divided by base_cpi, and
559 /// rounded as REFERENCE_CPI and INDEX_RATIO are.
560 /// Accrued interest is excluded on both sides.
561 ///
562 /// Absent (TIPS): the measure is absent, never 0 and never the real-price
563 /// fallback (the UnadjustedCostBasis formula above), when:
564 /// - there are no lots (TipsInput.cost_basis unset or its lots empty);
565 /// - a lot has no open_date;
566 /// - a needed CPI-U month is missing: L-3 or L-2 of any lot's settlement
567 /// month. TipsInput.cpi with reference_cpi carries no lot months, so the
568 /// measure is absent then. (A missing m-3 or m-2 of the valuation month
569 /// makes the whole request invalid; see TipsInput.cpi.)
570 ///
571 /// Rounding (TIPS): 31 CFR 356 Appendix B. Each reference CPI and each
572 /// index ratio is rounded to 5 decimals (half up). Project rule, not
573 /// Appendix B text: MarketSide and CostSide (after the sum) are each
574 /// rounded to cents, and ProfitLoss is the difference of the rounded sides.
575 ///
576 /// Example (TIPS): 912810RL4, 0.750% due 2045-02-15, base_cpi 235.48150.
577 /// Lot: face 100,000, real price 68.1875, open_date 2026-07-27, settling
578 /// 2026-07-28. CPI-U April 2026 333.020, May 2026 335.123 →
579 /// RefCPI = 333.020 + 27/31 * (335.123 - 333.020) = 334.85165,
580 /// IndexRatio = 334.85165 / 235.48150 = 1.42199,
581 /// CostSide = 68.1875 / 100 * 1.42199 * 100,000 = 96,961.94.
582 /// Valuation 2026-10-28, clean_price 67.625. CPI-U July 2026 333.918,
583 /// August 2026 334.980 →
584 /// RefCPI = 333.918 + 27/31 * (334.980 - 333.918) = 334.84297,
585 /// IndexRatio = 334.84297 / 235.48150 = 1.42195,
586 /// MarketSide = 67.625 / 100 * 1.42195 * 100,000 = 96,159.37.
587 /// ProfitLoss = 96,159.37 - 96,961.94 = -802.57.
588 ///
589 /// Applicability: All security types.
590 /// Units: Dollars (or settlement currency).
591 ProfitLoss = 18,
592 /// The profit or loss as a percentage of the original cost basis.
593 ///
594 /// Formula:
595 /// ProfitLossPercent = ProfitLoss / (UnadjustedCostBasis / d * DirectedQuantity)
596 /// Where d = 100 for par-quoted securities (bonds, TIPS, FRNs) and
597 /// d = 1 for dollar-quoted securities (equities, cash).
598 ///
599 /// The measure is absent, never 0, when MarketValue, UnadjustedCostBasis
600 /// or DirectedQuantity is unavailable.
601 ///
602 /// Formula (TIPS): replaces the formula above for TIPS (LM-405):
603 /// ProfitLossPercent = ProfitLoss / CostSide
604 /// ProfitLoss and CostSide are PROFIT_LOSS (TIPS): nominal and clean, with
605 /// the market side at INDEX_RATIO for the valuation date and each open
606 /// lot's real price at the index ratio for its settlement date
607 /// (TaxLotProto.open_date plus the product's settlement lag). Accrued
608 /// interest is excluded on both sides.
609 ///
610 /// Absent (TIPS): the measure is absent, never 0 and never the real-price
611 /// fallback (the UnadjustedCostBasis formula above), when:
612 /// - there are no lots (TipsInput.cost_basis unset or its lots empty);
613 /// - a lot has no open_date;
614 /// - a needed CPI-U month is missing (see PROFIT_LOSS).
615 ///
616 /// Rounding (TIPS): ProfitLoss and CostSide are rounded as in PROFIT_LOSS:
617 /// 31 CFR 356 Appendix B, reference CPI and index ratio to 5 decimals,
618 /// then each side to cents (a project rule). The ratio is not rounded
619 /// further.
620 ///
621 /// Example (TIPS): 912810RL4 (see PROFIT_LOSS): cost 96,961.94,
622 /// market 96,159.37, P&L -802.57 →
623 /// ProfitLossPercent = -802.57 / 96,961.94 = -0.0082772 (rounded here only).
624 ///
625 /// Applicability: All security types.
626 /// Units: Decimal (0-1 scale; e.g. 0.05 = 5.00% gain).
627 ProfitLossPercent = 19,
628 /// The coupon interest accrued from the last coupon date up to (but not
629 /// including) the settlement date, per the security's day count. Earned but not
630 /// yet received.
631 ///
632 /// Fixed-coupon bonds and TIPS:
633 /// AccruedInterest = (coupon_rate / coupon_frequency) * (days_since_last_coupon / days_in_period)
634 /// * directed_quantity
635 /// Day count: the security's (Actual/Actual (ICMA) for US Treasuries).
636 ///
637 /// Treasury FRNs: the sum, over each day from the last coupon date to
638 /// settlement, of that day's (13-week bill index fixing + spread) / 360 on face:
639 /// AccruedInterest = Σ_{each day} (index_fixing_d + spread) / 360 * directed_quantity
640 /// where directed_quantity is the position's face.
641 /// The fixings are the ones supplied in the request; no curve is used.
642 ///
643 /// Applicability: Bond, TIPS, FRN (coupon-bearing securities).
644 /// Returns null/zero for Equity, Cash, and zero-coupon bonds.
645 /// Units: Dollars (absolute dollar amount for the position).
646 AccruedInterest = 20,
647 /// The second derivative of a bond's price with respect to yield, normalised by price.
648 /// Convexity measures how the duration of a bond changes as yield changes — a bond
649 /// with higher convexity gains more in price when yields fall and loses less when
650 /// yields rise, compared to a bond with lower convexity of equal duration.
651 ///
652 /// Formula:
653 /// Convexity = (1/P) × Σ_{t=1}^{N} [CF_t × t × (t+1) / (1+y/n)^(t+2)] / n²
654 ///
655 /// Equivalently, in terms of periodic-discount PVs:
656 /// Convexity = Σ_{t=1}^{N} [t(t+1) × PV_t] / (P_dollar × n² × (1+r)²)
657 /// Where r = y/n (periodic yield), P_dollar = dollar price,
658 /// PV_t = CF_t / (1+r)^t, n = coupon frequency (periods per year).
659 ///
660 /// Model assumptions:
661 /// - Same as MACAULAY_DURATION (flat yield curve, YTM-based discounting).
662 /// - For TIPS: y = REAL_YIELD and CF_t are the inflation-adjusted cash flows.
663 /// - For FRN: uses flat-forwards effective YTM (same model as PRESENT_VALUE).
664 /// - Settlement on a coupon date (integer period exponents).
665 ///
666 /// Applicability: Bond, TIPS, FRN. UNIMPLEMENTED for Equity and Cash.
667 /// Units: Years² (e.g. 20.5 = 20.5 years²).
668 Convexity = 21,
669 /// The full (invoice) price of a bond including accrued interest, expressed as a
670 /// percentage of face value.
671 ///
672 /// Formula:
673 /// DirtyPrice = CLEAN_PRICE + accrued_interest_per_bond / face_value * 100
674 /// where CLEAN_PRICE is the supplied market clean price and
675 /// accrued_interest_per_bond is ACCRUED_INTEREST for one bond of face_value,
676 /// as of the settlement date.
677 /// The result is a percentage of par, per bond, and is never scaled by quantity.
678 ///
679 /// Applicability: Bond, TIPS, FRN. UNIMPLEMENTED for Equity and Cash.
680 /// Units: Percentage of par (e.g. 99.5 = 99.5% of par).
681 DirtyPrice = 22,
682 /// The market clean price per 100 of face (excluding accrued interest), as
683 /// supplied in the request — e.g. the FedInvest end-of-day price via price-service.
684 ///
685 /// An input, never computed: valuation-service returns UNIMPLEMENTED for it.
686 ///
687 /// Units: Percentage of par (e.g. 98.75 = 98.75% of par).
688 CleanPrice = 23,
689 /// Modified Duration = MacaulayDuration / (1 + ytm/coupon_frequency).
690 ///
691 /// Measures the percentage price change of a bond for a 1% (100bp) change in yield.
692 /// Unlike Macaulay Duration (which is expressed in years), Modified Duration is a
693 /// direct measure of price sensitivity: a bond with ModifiedDuration=5 will move
694 /// approximately 5% in price for a 100bp parallel shift in yield.
695 ///
696 /// Formula:
697 /// ModifiedDuration = MacaulayDuration / (1 + ytm/n)
698 /// where ytm = yield to maturity (annual), n = coupon periods per year.
699 /// For TIPS, ytm = REAL_YIELD (on the inflation-adjusted cash flows).
700 ///
701 /// Applicability: Bond, TIPS, FRN. UNIMPLEMENTED for Equity and Cash.
702 /// Units: Years (dimensionally equivalent to years, interpreted as % per 100bp).
703 ModifiedDuration = 24,
704 /// DV01 (Dollar Value of 01) = the dollar P&L impact of a 1bp (0.01%) yield increase.
705 ///
706 /// Formula:
707 /// DV01 = ModifiedDuration × MarketValue × 0.0001
708 ///
709 /// For a $1M market value position with ModifiedDuration=5:
710 /// DV01 = 5 × 1,000,000 × 0.0001 = $500 per bp
711 ///
712 /// Applicability: Bond, TIPS, FRN. UNIMPLEMENTED for Equity and Cash.
713 /// Units: Dollars per basis point.
714 Dv01 = 25,
715 /// U.S. Treasury Bill discount-basis yield. The market convention used by
716 /// TreasuryDirect auction results ("High discount rate"), Bloomberg TBILL
717 /// screens, and most short-tenor money-market quotes.
718 ///
719 /// Formula:
720 /// DiscountYield = (F - P) / F × 360 / days_to_maturity
721 /// Where F = face value (par), P = dollar price, day count is Actual/360.
722 ///
723 /// Example: 13W TBill 912797TW7 priced at 99.082, days_to_maturity=91:
724 /// DiscountYield = (100 - 99.082) / 100 × 360 / 91 = 0.0363 = 3.63%
725 ///
726 /// Distinct from YIELD_TO_MATURITY which uses the annual-compound convention
727 /// (F/P)^(1/years) - 1; the two differ by 5-14bp at typical TBill tenors.
728 /// The U.S. Treasury publishes BOTH conventions for each auction plus
729 /// BOND_EQUIVALENT_YIELD; the industry-standard wire format for TBills is
730 /// DiscountYield. See #209.
731 ///
732 /// Model assumptions:
733 /// - Simple (non-compounded) discount basis — standard U.S. money-market.
734 /// - 360-day year (Actual/360 day count).
735 /// - Assumes the security has a defined maturity_date and face_value;
736 /// null for instruments where days_to_maturity is undefined.
737 ///
738 /// Applicability: Zero-coupon short-tenor securities — Tbill, principal-only
739 /// Strips with <1yr remaining. Returns null/error for other product types.
740 /// Units: Decimal (0-1 scale; e.g. 0.0363 = 3.63%).
741 DiscountYield = 26,
742 /// Bond-Equivalent Yield (BEY) for U.S. Treasury Bills — also known as the
743 /// "investment rate" published alongside DISCOUNT_YIELD on TreasuryDirect.
744 /// The conventional way to compare TBill returns to coupon-bearing bond
745 /// yields (which conventionally use a 365-day year).
746 ///
747 /// Formula:
748 /// BondEquivalentYield = (F - P) / P × 365 / days_to_maturity
749 /// Where F = face value (par), P = dollar price, day count is Actual/365.
750 ///
751 /// Example: 13W TBill 912797TW7 priced at 99.082, days_to_maturity=91:
752 /// BEY = (100 - 99.082) / 99.082 × 365 / 91 = 0.0371 = 3.71%
753 ///
754 /// Distinct from DISCOUNT_YIELD which uses 360-day simple discount; BEY's
755 /// dividing-by-P (not F) and 365-day basis make it directly comparable to
756 /// YTM on a coupon-bearing Treasury Note of equivalent tenor. The Treasury
757 /// calls this the "investment rate" on auction results. See #209.
758 ///
759 /// Model assumptions:
760 /// - Simple (non-compounded) basis.
761 /// - 365-day year (Actual/365 day count).
762 /// - Same applicability constraints as DISCOUNT_YIELD.
763 ///
764 /// Applicability: Zero-coupon short-tenor securities — Tbill, principal-only
765 /// Strips with <1yr remaining. Returns null/error for other product types.
766 /// Units: Decimal (0-1 scale; e.g. 0.0371 = 3.71%).
767 BondEquivalentYield = 27,
768 /// The reference CPI of a TIPS for the settlement date (the UTC date of
769 /// ValuationRequestProto.asof_datetime), the numerator of INDEX_RATIO.
770 ///
771 /// Formula:
772 /// With TipsInput.cpi.reference_cpi: the value as given.
773 /// With TipsInput.cpi.readings:
774 /// RefCPI = CPI(m-3) + (d - 1) / days_in_month * (CPI(m-2) - CPI(m-3))
775 /// Where m is the settlement month, the month of the UTC date of
776 /// ValuationRequestProto.asof_datetime (asof_datetime.timestamp in UTC;
777 /// time_zone is not used), d the settlement day of month,
778 /// days_in_month the number of days in month m, and CPI(m-k) the reading
779 /// for the month k months before m.
780 ///
781 /// Example: settlement 2026-07-16, CPI(April)=320.0, CPI(May)=321.5 →
782 /// RefCPI = 320.0 + 15/31 * (321.5 - 320.0) = 320.72580645... → 320.72581.
783 ///
784 /// Model assumptions:
785 /// - Rounding: with readings, RefCPI is rounded to 5 decimals (half up)
786 /// per 31 CFR 356 Appendix B. A given reference_cpi is used as-is.
787 /// - With readings, months m-3 and m-2 are required: the request is
788 /// rejected when either is missing. Extra months (e.g. those lot
789 /// settlement dates need for PROFIT_LOSS) are allowed and ignored here.
790 /// A duplicate (year, month) or a month outside 1-12 is rejected.
791 /// - The measure is absent when no CPI is given.
792 ///
793 /// Applicability: TIPS only.
794 /// Units: Index points (e.g. 310.326).
795 ReferenceCpi = 28,
796 /// The index ratio of a TIPS for the settlement date.
797 ///
798 /// Formula:
799 /// IndexRatio = REFERENCE_CPI / security.tips_extension.base_cpi
800 ///
801 /// Example: RefCPI=312.0, base_cpi=260.0 → IndexRatio = 1.2.
802 ///
803 /// Model assumptions:
804 /// - Rounding: computed from the rounded REFERENCE_CPI and rounded to
805 /// 5 decimals (half up) per 31 CFR 356 Appendix B. Every measure that
806 /// uses the index ratio (MARKET_VALUE, ADJUSTED_COST_BASIS,
807 /// INFLATION_ADJUSTED_PRINCIPAL, REAL_YIELD, PRESENT_VALUE, PROFIT_LOSS)
808 /// uses this rounded ratio.
809 /// - Unfloored: a ratio below 1 is returned as is. The deflation floor
810 /// belongs to INFLATION_ADJUSTED_PRINCIPAL only.
811 /// - The measure is absent when REFERENCE_CPI or base_cpi is absent.
812 ///
813 /// Applicability: TIPS only.
814 /// Units: Dimensionless ratio (e.g. 1.2 = 20% cumulative inflation since base).
815 IndexRatio = 29,
816}
817impl MeasureProto {
818 /// String value of the enum field names used in the ProtoBuf definition.
819 ///
820 /// The values are not transformed in any way and thus are considered stable
821 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
822 pub fn as_str_name(&self) -> &'static str {
823 match self {
824 MeasureProto::UnknownMeasure => "UNKNOWN_MEASURE",
825 MeasureProto::DirectedQuantity => "DIRECTED_QUANTITY",
826 MeasureProto::MarketValue => "MARKET_VALUE",
827 MeasureProto::UnadjustedCostBasis => "UNADJUSTED_COST_BASIS",
828 MeasureProto::AdjustedCostBasis => "ADJUSTED_COST_BASIS",
829 MeasureProto::CurrentYield => "CURRENT_YIELD",
830 MeasureProto::YieldToMaturity => "YIELD_TO_MATURITY",
831 MeasureProto::MacaulayDuration => "MACAULAY_DURATION",
832 MeasureProto::PresentValue => "PRESENT_VALUE",
833 MeasureProto::RealYield => "REAL_YIELD",
834 MeasureProto::InflationAdjustedPrincipal => "INFLATION_ADJUSTED_PRINCIPAL",
835 MeasureProto::PresentValueCashflows => "PRESENT_VALUE_CASHFLOWS",
836 MeasureProto::DiscountMargin => "DISCOUNT_MARGIN",
837 MeasureProto::SpreadDuration => "SPREAD_DURATION",
838 MeasureProto::ParYield => "PAR_YIELD",
839 MeasureProto::SpotYield => "SPOT_YIELD",
840 MeasureProto::ForwardYield => "FORWARD_YIELD",
841 MeasureProto::ProfitLoss => "PROFIT_LOSS",
842 MeasureProto::ProfitLossPercent => "PROFIT_LOSS_PERCENT",
843 MeasureProto::AccruedInterest => "ACCRUED_INTEREST",
844 MeasureProto::Convexity => "CONVEXITY",
845 MeasureProto::DirtyPrice => "DIRTY_PRICE",
846 MeasureProto::CleanPrice => "CLEAN_PRICE",
847 MeasureProto::ModifiedDuration => "MODIFIED_DURATION",
848 MeasureProto::Dv01 => "DV01",
849 MeasureProto::DiscountYield => "DISCOUNT_YIELD",
850 MeasureProto::BondEquivalentYield => "BOND_EQUIVALENT_YIELD",
851 MeasureProto::ReferenceCpi => "REFERENCE_CPI",
852 MeasureProto::IndexRatio => "INDEX_RATIO",
853 }
854 }
855 /// Creates an enum from field names used in the ProtoBuf definition.
856 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
857 match value {
858 "UNKNOWN_MEASURE" => Some(Self::UnknownMeasure),
859 "DIRECTED_QUANTITY" => Some(Self::DirectedQuantity),
860 "MARKET_VALUE" => Some(Self::MarketValue),
861 "UNADJUSTED_COST_BASIS" => Some(Self::UnadjustedCostBasis),
862 "ADJUSTED_COST_BASIS" => Some(Self::AdjustedCostBasis),
863 "CURRENT_YIELD" => Some(Self::CurrentYield),
864 "YIELD_TO_MATURITY" => Some(Self::YieldToMaturity),
865 "MACAULAY_DURATION" => Some(Self::MacaulayDuration),
866 "PRESENT_VALUE" => Some(Self::PresentValue),
867 "REAL_YIELD" => Some(Self::RealYield),
868 "INFLATION_ADJUSTED_PRINCIPAL" => Some(Self::InflationAdjustedPrincipal),
869 "PRESENT_VALUE_CASHFLOWS" => Some(Self::PresentValueCashflows),
870 "DISCOUNT_MARGIN" => Some(Self::DiscountMargin),
871 "SPREAD_DURATION" => Some(Self::SpreadDuration),
872 "PAR_YIELD" => Some(Self::ParYield),
873 "SPOT_YIELD" => Some(Self::SpotYield),
874 "FORWARD_YIELD" => Some(Self::ForwardYield),
875 "PROFIT_LOSS" => Some(Self::ProfitLoss),
876 "PROFIT_LOSS_PERCENT" => Some(Self::ProfitLossPercent),
877 "ACCRUED_INTEREST" => Some(Self::AccruedInterest),
878 "CONVEXITY" => Some(Self::Convexity),
879 "DIRTY_PRICE" => Some(Self::DirtyPrice),
880 "CLEAN_PRICE" => Some(Self::CleanPrice),
881 "MODIFIED_DURATION" => Some(Self::ModifiedDuration),
882 "DV01" => Some(Self::Dv01),
883 "DISCOUNT_YIELD" => Some(Self::DiscountYield),
884 "BOND_EQUIVALENT_YIELD" => Some(Self::BondEquivalentYield),
885 "REFERENCE_CPI" => Some(Self::ReferenceCpi),
886 "INDEX_RATIO" => Some(Self::IndexRatio),
887 _ => None,
888 }
889 }
890}
891#[allow(clippy::derive_partial_eq_without_eq)]
892#[derive(Clone, PartialEq, ::prost::Message)]
893pub struct MeasureMapEntry {
894 #[prost(enumeration = "MeasureProto", tag = "1")]
895 pub measure: i32,
896 #[prost(message, optional, tag = "2")]
897 pub measure_decimal_value: ::core::option::Option<super::util::DecimalValueProto>,
898}
899#[allow(clippy::derive_partial_eq_without_eq)]
900#[derive(Clone, PartialEq, ::prost::Message)]
901pub struct FieldMapEntry {
902 #[prost(enumeration = "FieldProto", tag = "1")]
903 pub field: i32,
904 /// Used for position filters, but not for responses
905 #[prost(enumeration = "PositionFilterOperator", tag = "20")]
906 pub operator: i32,
907 #[prost(oneof = "field_map_entry::FieldMapValueOneOf", tags = "4, 5, 6")]
908 pub field_map_value_one_of: ::core::option::Option<
909 field_map_entry::FieldMapValueOneOf,
910 >,
911}
912/// Nested message and enum types in `FieldMapEntry`.
913pub mod field_map_entry {
914 #[allow(clippy::derive_partial_eq_without_eq)]
915 #[derive(Clone, PartialEq, ::prost::Oneof)]
916 pub enum FieldMapValueOneOf {
917 /// If the field is a 'complex' proto type (e.g. a full enum) we serialize the enum and wrap it in an Any. You can think of the Any as a string describing the type, and a binary of the proto itself
918 #[prost(message, tag = "4")]
919 FieldValuePacked(::prost_types::Any),
920 /// If the field is an enum type, then we use the number to denote which value it is
921 #[prost(int32, tag = "5")]
922 EnumValue(i32),
923 /// If the field is a string type, we just serialize the string (packing has an overhead)
924 #[prost(string, tag = "6")]
925 StringValue(::prost::alloc::string::String),
926 }
927}
928#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
929#[repr(i32)]
930pub enum PositionFilterOperator {
931 UnknownOperator = 0,
932 Equals = 1,
933 NotEquals = 2,
934 LessThan = 3,
935 LessThanOrEquals = 4,
936 MoreThan = 5,
937 MoreThanOrEquals = 6,
938}
939impl PositionFilterOperator {
940 /// String value of the enum field names used in the ProtoBuf definition.
941 ///
942 /// The values are not transformed in any way and thus are considered stable
943 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
944 pub fn as_str_name(&self) -> &'static str {
945 match self {
946 PositionFilterOperator::UnknownOperator => "UNKNOWN_OPERATOR",
947 PositionFilterOperator::Equals => "EQUALS",
948 PositionFilterOperator::NotEquals => "NOT_EQUALS",
949 PositionFilterOperator::LessThan => "LESS_THAN",
950 PositionFilterOperator::LessThanOrEquals => "LESS_THAN_OR_EQUALS",
951 PositionFilterOperator::MoreThan => "MORE_THAN",
952 PositionFilterOperator::MoreThanOrEquals => "MORE_THAN_OR_EQUALS",
953 }
954 }
955 /// Creates an enum from field names used in the ProtoBuf definition.
956 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
957 match value {
958 "UNKNOWN_OPERATOR" => Some(Self::UnknownOperator),
959 "EQUALS" => Some(Self::Equals),
960 "NOT_EQUALS" => Some(Self::NotEquals),
961 "LESS_THAN" => Some(Self::LessThan),
962 "LESS_THAN_OR_EQUALS" => Some(Self::LessThanOrEquals),
963 "MORE_THAN" => Some(Self::MoreThan),
964 "MORE_THAN_OR_EQUALS" => Some(Self::MoreThanOrEquals),
965 _ => None,
966 }
967 }
968}
969#[allow(clippy::derive_partial_eq_without_eq)]
970#[derive(Clone, PartialEq, ::prost::Message)]
971pub struct PositionProto {
972 #[prost(enumeration = "super::util::ObjectTypeProto", tag = "1")]
973 pub object_type: i32,
974 #[prost(message, optional, tag = "2")]
975 pub version: ::core::option::Option<super::util::VersionProto>,
976 #[prost(enumeration = "PositionViewProto", tag = "10")]
977 pub position_view: i32,
978 #[prost(enumeration = "PositionTypeProto", tag = "11")]
979 pub position_type: i32,
980 #[prost(message, repeated, tag = "20")]
981 pub measures: ::prost::alloc::vec::Vec<MeasureMapEntry>,
982 #[prost(message, repeated, tag = "21")]
983 pub fields: ::prost::alloc::vec::Vec<FieldMapEntry>,
984 /// The base/reporting currency for monetary measures in this position.
985 /// Set to the portfolio's base currency (e.g. USD cash security).
986 /// Allows the UI to display the currency alongside MARKET_VALUE and other measures.
987 #[prost(message, optional, tag = "22")]
988 pub reporting_currency: ::core::option::Option<super::security::SecurityProto>,
989}
990#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
991#[repr(i32)]
992pub enum PositionViewProto {
993 UnknownPositionView = 0,
994 DefaultView = 1,
995 StrategyView = 2,
996}
997impl PositionViewProto {
998 /// String value of the enum field names used in the ProtoBuf definition.
999 ///
1000 /// The values are not transformed in any way and thus are considered stable
1001 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
1002 pub fn as_str_name(&self) -> &'static str {
1003 match self {
1004 PositionViewProto::UnknownPositionView => "UNKNOWN_POSITION_VIEW",
1005 PositionViewProto::DefaultView => "DEFAULT_VIEW",
1006 PositionViewProto::StrategyView => "STRATEGY_VIEW",
1007 }
1008 }
1009 /// Creates an enum from field names used in the ProtoBuf definition.
1010 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
1011 match value {
1012 "UNKNOWN_POSITION_VIEW" => Some(Self::UnknownPositionView),
1013 "DEFAULT_VIEW" => Some(Self::DefaultView),
1014 "STRATEGY_VIEW" => Some(Self::StrategyView),
1015 _ => None,
1016 }
1017 }
1018}
1019#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
1020#[repr(i32)]
1021pub enum PositionTypeProto {
1022 UnknownPositionType = 0,
1023 Transaction = 1,
1024 TaxLot = 2,
1025}
1026impl PositionTypeProto {
1027 /// String value of the enum field names used in the ProtoBuf definition.
1028 ///
1029 /// The values are not transformed in any way and thus are considered stable
1030 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
1031 pub fn as_str_name(&self) -> &'static str {
1032 match self {
1033 PositionTypeProto::UnknownPositionType => "UNKNOWN_POSITION_TYPE",
1034 PositionTypeProto::Transaction => "TRANSACTION",
1035 PositionTypeProto::TaxLot => "TAX_LOT",
1036 }
1037 }
1038 /// Creates an enum from field names used in the ProtoBuf definition.
1039 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
1040 match value {
1041 "UNKNOWN_POSITION_TYPE" => Some(Self::UnknownPositionType),
1042 "TRANSACTION" => Some(Self::Transaction),
1043 "TAX_LOT" => Some(Self::TaxLot),
1044 _ => None,
1045 }
1046 }
1047}
1048#[allow(clippy::derive_partial_eq_without_eq)]
1049#[derive(Clone, PartialEq, ::prost::Message)]
1050pub struct PositionFilterProto {
1051 #[prost(enumeration = "super::util::ObjectTypeProto", tag = "1")]
1052 pub object_type: i32,
1053 #[prost(message, optional, tag = "2")]
1054 pub version: ::core::option::Option<super::util::VersionProto>,
1055 #[prost(message, repeated, tag = "21")]
1056 pub filters: ::prost::alloc::vec::Vec<FieldMapEntry>,
1057}
1058#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
1059#[repr(i32)]
1060pub enum PositionStatusProto {
1061 Unknown = 0,
1062 /// Hypothetical status means a transaction, tax lot or position that may never occur. This can be used to understand how potential actions could impact a portfolio
1063 Hypothetical = 1,
1064 /// Intended status means a transaction, tax lot or position that is expected to occur if nothing changes. For example a fixed income bond that is expected to pay a coupon, or a security that is expected to mature in a specific point in the future
1065 Intended = 2,
1066 /// Executed status means a transaction, tax lot or position that is the result of a legally binding transaction
1067 Executed = 3,
1068}
1069impl PositionStatusProto {
1070 /// String value of the enum field names used in the ProtoBuf definition.
1071 ///
1072 /// The values are not transformed in any way and thus are considered stable
1073 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
1074 pub fn as_str_name(&self) -> &'static str {
1075 match self {
1076 PositionStatusProto::Unknown => "UNKNOWN",
1077 PositionStatusProto::Hypothetical => "HYPOTHETICAL",
1078 PositionStatusProto::Intended => "INTENDED",
1079 PositionStatusProto::Executed => "EXECUTED",
1080 }
1081 }
1082 /// Creates an enum from field names used in the ProtoBuf definition.
1083 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
1084 match value {
1085 "UNKNOWN" => Some(Self::Unknown),
1086 "HYPOTHETICAL" => Some(Self::Hypothetical),
1087 "INTENDED" => Some(Self::Intended),
1088 "EXECUTED" => Some(Self::Executed),
1089 _ => None,
1090 }
1091 }
1092}
1093/// One open tax lot of a holding.
1094///
1095/// The proto form of the tax lots ledger-models already computes in Java
1096/// (common.models.taxLot.TaxLotSummary). A domain model, not a request-only
1097/// input: CostBasisInput.lots carries it to valuation-service for
1098/// MeasureProto.ADJUSTED_COST_BASIS (LM-364).
1099/// See docs/adr/amortisation_elections.md.
1100#[allow(clippy::derive_partial_eq_without_eq)]
1101#[derive(Clone, PartialEq, ::prost::Message)]
1102pub struct TaxLotProto {
1103 /// the opening trade date
1104 #[prost(message, optional, tag = "1")]
1105 pub open_date: ::core::option::Option<super::util::LocalDateProto>,
1106 /// quantity still open, in the position's units (face value for bonds; TIPS: original face, not inflation-adjusted)
1107 #[prost(message, optional, tag = "2")]
1108 pub open_quantity: ::core::option::Option<super::util::DecimalValueProto>,
1109 /// purchase price per 100 face, clean; TIPS: the real (unadjusted) price
1110 #[prost(message, optional, tag = "3")]
1111 pub price: ::core::option::Option<super::util::DecimalValueProto>,
1112}