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 /// Model assumptions: None — this is a direct mark-to-market calculation.
176 /// Applicability: Bond, TIPS, FRN, Equity (price=share price, face_value=1), Cash.
177 /// Units: Dollars (or settlement currency).
178 MarketValue = 2,
179 /// The original purchase price of the security, before any adjustments for
180 /// amortization, accretion, or corporate actions.
181 ///
182 /// Formula: Returns the price_input as-is (quoted as % of par for bonds).
183 /// Over time this may incorporate adjustments such as stock splits.
184 ///
185 /// Model assumptions: None — pass-through of the input price.
186 /// Applicability: Bond, TIPS, FRN, Equity, Cash.
187 /// Units: Quoted price (% of par for bonds; dollar price for equities).
188 UnadjustedCostBasis = 3,
189 /// Reserved for future use. The cost basis adjusted for amortization of premium,
190 /// accretion of discount, or corporate actions (e.g. stock splits, return of capital).
191 ///
192 /// Not currently implemented.
193 /// Applicability: Bond, TIPS, FRN, Equity.
194 /// Units: Quoted price (% of par for bonds; dollar price for equities).
195 AdjustedCostBasis = 4,
196 /// Annual coupon income as a percentage of the current market price.
197 ///
198 /// Formula (coupon-bearing bonds):
199 /// CurrentYield = (coupon_rate * principal) / (price * face_value / 100)
200 /// Where principal = face_value for nominal bonds, or inflation-adjusted principal for TIPS.
201 ///
202 /// Formula (zero-coupon bonds):
203 /// CurrentYield = (face_value / dollar_price)^(1 / years_to_maturity) - 1
204 /// This is the annualized investment yield from discount to par.
205 ///
206 /// Model assumptions: Assumes coupon income is constant (no reinvestment assumption).
207 /// For TIPS, uses the inflation-adjusted principal for the annual coupon calculation.
208 /// Day count: Actual/365 for years-to-maturity calculation.
209 /// Applicability: Bond, TIPS. (Equity dividend yield not yet supported.)
210 /// Units: Decimal (0-1 scale; e.g. 0.0526 = 5.26%).
211 CurrentYield = 5,
212 /// The annualized rate of return assuming the bond is held to maturity and all
213 /// coupons are reinvested at the same rate. This is the internal rate of return
214 /// that equates the present value of all future cashflows to the current price.
215 ///
216 /// Formula:
217 /// Solve for r (annual) such that:
218 /// price * (face / 100) = Sum_{t=1}^{N} [C / (1 + r/m)^t] + F / (1 + r/m)^N
219 /// Where C = periodic coupon, F = principal (face or inflation-adjusted),
220 /// m = coupon frequency, N = number of periods.
221 ///
222 /// Solver: Newton-Raphson iteration (ytm_solver.rs) with the linear approximation
223 /// YTM ≈ (annual_coupon + (F - P) / years) / ((F + P) / 2)
224 /// as the initial guess. Converges to the exact YTM where PV = price.
225 ///
226 /// Model assumptions:
227 /// - Coupon reinvestment at the YTM rate (standard bond math assumption).
228 /// - For TIPS: uses inflation-adjusted principal for cashflows, but the input
229 /// price is real — yielding a "mixed" rate, not the true real yield. Use
230 /// REAL_YIELD for the economically correct TIPS yield.
231 /// - Settlement on a coupon date (no accrued interest adjustment currently).
232 /// - Day count: Actual/365 for years-to-maturity.
233 ///
234 /// Applicability: Bond, TIPS. Not meaningful for FRN (use DISCOUNT_MARGIN) or Equity.
235 /// Units: Decimal (0-1 scale; e.g. 0.06 = 6.00% annual).
236 YieldToMaturity = 7,
237 /// The weighted average time (in years) to receive all cashflows from a bond,
238 /// where each cashflow's weight is its proportion of the bond's total present value.
239 ///
240 /// Formula:
241 /// D = Sum_{t=1}^{N} [(t / m) * PV_t / TotalPV]
242 /// Where PV_t = cashflow_t / (1 + r/m)^t, TotalPV = Sum(PV_t),
243 /// m = coupon frequency, r = YTM.
244 ///
245 /// Model assumptions:
246 /// - Uses the bond's YTM (from Newton-Raphson solver) as the discount rate.
247 /// - Flat yield curve (single rate for all maturities).
248 /// - Settlement on a coupon date (integer period exponents).
249 ///
250 /// Applicability: Bond, TIPS. Not typically used for FRN (spread duration is the
251 /// relevant risk measure). Not applicable to Equity or Cash.
252 /// Units: Years (e.g. 4.41 = 4.41 years).
253 MacaulayDuration = 8,
254 /// The theoretical price of a bond computed as the sum of all future cashflows
255 /// (coupons + principal) discounted at the bond's yield to maturity.
256 ///
257 /// Formula:
258 /// PV = Sum_{t=1}^{N} [C / (1 + r/m)^t] + F / (1 + r/m)^N
259 /// Returned as: PV_dollar / (face_value / 100) (quoted price, % of par).
260 ///
261 /// The YTM used for discounting is computed via Newton-Raphson from the input price,
262 /// which guarantees the three-way invariant:
263 /// price == present_value == sum(cashflow_pvs)
264 ///
265 /// Model assumptions:
266 /// - Same as YIELD_TO_MATURITY (the discount rate is derived from the input price).
267 /// - For TIPS: cashflows use inflation-adjusted principal; discount rate is the
268 /// Newton-Raphson-solved rate equating nominal cashflows to the real price.
269 ///
270 /// Applicability: Bond, TIPS. For FRN, PV uses the discount margin framework instead.
271 /// Units: Quoted price (% of par; e.g. 95.00 = $95 per $100 face).
272 PresentValue = 9,
273 /// The yield of a TIPS bond in real (inflation-adjusted) terms. This is the return
274 /// an investor earns above the rate of inflation.
275 ///
276 /// Formula: Currently delegates to the YTM calculator, which uses inflation-adjusted
277 /// principal for cashflows. For a par TIPS (real coupon = real yield), the solver
278 /// finds a "mixed" rate rather than the true real yield (see YIELD_TO_MATURITY notes).
279 ///
280 /// Model assumptions:
281 /// - Same as YIELD_TO_MATURITY but applied to TIPS securities.
282 /// - Known limitation: the current implementation mixes real price with nominal
283 /// (inflation-adjusted) cashflows in the solver, which produces a rate that is
284 /// not the true real yield for non-par TIPS.
285 ///
286 /// Applicability: TIPS only. For nominal bonds, returns the same value as YTM.
287 /// Units: Decimal (0-1 scale; e.g. 0.02 = 2.00% real annual yield).
288 RealYield = 10,
289 /// The inflation-adjusted principal of a TIPS bond, reflecting the cumulative
290 /// change in the Consumer Price Index (CPI) since the bond's issuance.
291 ///
292 /// Formula:
293 /// index_ratio = current_cpi / base_cpi
294 /// adjusted_principal = max(face_value * index_ratio, face_value)
295 /// The max() enforces the deflation floor: at maturity, TIPS redeem at no less
296 /// than the original face value, even if CPI has fallen.
297 ///
298 /// Model assumptions:
299 /// - Uses the CPI values provided in the request (base_cpi on the security,
300 /// current_cpi on the cpi_price_input).
301 /// - Deflation floor applies only to the principal at maturity; interim coupons
302 /// use the raw (potentially deflated) adjusted principal.
303 ///
304 /// Applicability: TIPS only.
305 /// Units: Dollars (e.g. 103.36 for face=100 with 3.36% cumulative inflation).
306 InflationAdjustedPrincipal = 11,
307 /// Requests the full schedule of future cashflows for a bond or TIPS.
308 /// When this measure is included in the request, the ValuationResponseProto will
309 /// populate the `cashflows` repeated field with one CashflowProto per payment period.
310 ///
311 /// Each CashflowProto contains:
312 /// - cashflow_date: the payment date
313 /// - fv_amount: the undiscounted (future) value of the cashflow
314 /// - pv_amount: the cashflow discounted to settlement at the bond's YTM
315 /// - coupon_rate: the annualized coupon rate for this period (constant for
316 /// fixed-rate bonds; reference_rate + spread for FRNs)
317 ///
318 /// The sum of all pv_amounts equals the PRESENT_VALUE measure (three-way invariant).
319 ///
320 /// Model assumptions: Same as PRESENT_VALUE.
321 /// Applicability: Bond, TIPS, FRN.
322 /// Units: fv_amount and pv_amount in dollars; coupon_rate as percentage.
323 PresentValueCashflows = 12,
324 /// The discount margin of a Floating Rate Note (FRN) — the spread over the
325 /// reference rate at which the market discounts the FRN's projected cashflows
326 /// to arrive at its current price. This is the FRN analogue of YTM.
327 ///
328 /// Formula:
329 /// Solve for DM such that:
330 /// price = Sum_{t=1}^{N} [(R + QM)/m * FV / (1 + (R + DM)/m)^t]
331 /// + FV / (1 + (R + DM)/m)^N
332 /// Where R = reference rate, QM = quoted margin (fixed spread), FV = face value,
333 /// m = payment frequency, N = number of remaining periods.
334 ///
335 /// Solver: Newton-Raphson — same solver as YTM (ytm_solver.rs). Solve for the
336 /// periodic discount rate, then extract DM = (solved_rate * m) - R.
337 ///
338 /// Model assumptions:
339 /// - Flat forward rates: all future reference rate fixings are assumed equal to
340 /// the current observation of R. This is the standard FRN simplification.
341 /// - When DM = QM, price = par (100) on a reset date.
342 /// - When DM > QM, price < par (discount); when DM < QM, price > par (premium).
343 ///
344 /// Applicability: FRN only. For fixed-rate bonds, use YIELD_TO_MATURITY.
345 /// Units: Decimal (0-1 scale; e.g. 0.0075 = 75 basis points).
346 DiscountMargin = 13,
347 /// The sensitivity of an FRN's price to a 1 basis point change in the discount
348 /// margin. This is the primary risk measure for FRNs, analogous to modified
349 /// duration for fixed-rate bonds but measuring spread risk rather than rate risk.
350 ///
351 /// Formula (numerical differentiation):
352 /// SpreadDuration = -(1/P) * dP/dDM
353 /// ≈ (P_down - P_up) / (2 * 0.0001 * P_base)
354 /// Where P_down and P_up are the FRN prices when DM is bumped down and up by 1bp.
355 ///
356 /// For a 2-year quarterly FRN at par, spread duration ≈ 1.90 years.
357 /// This is approximately equal to the weighted average time to maturity.
358 ///
359 /// Model assumptions:
360 /// - Same flat-forward assumption as DISCOUNT_MARGIN.
361 /// - Uses a symmetric 1bp bump for numerical differentiation.
362 /// - Interest rate duration of an FRN is near-zero (≈ time to next reset);
363 /// spread duration captures the economically significant risk.
364 ///
365 /// Applicability: FRN only. For fixed-rate bonds, use MACAULAY_DURATION.
366 /// Units: Years (e.g. 1.90 = a 1bp spread widening causes ~1.90bp price decline).
367 SpreadDuration = 14,
368 /// The par yield at a given maturity point on the yield curve. The par yield is
369 /// the coupon rate at which a bond would trade at par (price = 100) for a given
370 /// maturity. This is the most commonly quoted yield curve.
371 ///
372 /// Formula:
373 /// For each maturity point, the par yield is the coupon rate c such that:
374 /// 100 = Sum_{t=1}^{N} [c/m / (1 + r_t)^t] + 100 / (1 + r_N)^N
375 /// Where r_t are spot rates, m = coupon frequency, N = number of periods.
376 ///
377 /// In practice, for on-the-run bonds, par yield ≈ YTM when the bond trades
378 /// near par. The par yield curve is bootstrapped from observed bond prices.
379 ///
380 /// Model assumptions:
381 /// - Coupon frequency matches the market convention (semiannual for US Treasuries).
382 /// - Interpolation between observed maturities uses the method specified in
383 /// the CurveRequestProto (linear by default).
384 ///
385 /// Applicability: Bond, TIPS (real par yield curve).
386 /// Not applicable to FRN, Equity, or Cash.
387 /// Units: Decimal (0-1 scale; e.g. 0.045 = 4.50% annual).
388 ParYield = 15,
389 /// The spot (zero-coupon) yield at a given maturity. The spot rate is the yield
390 /// on a zero-coupon bond maturing at that point — it represents the pure time
391 /// value of money with no reinvestment assumption.
392 ///
393 /// Formula:
394 /// Bootstrapped from the par yield curve:
395 /// P = 100 / (1 + s_N)^N → s_N = (100 / P)^(1/N) - 1
396 /// Where s_N is the N-period spot rate, P is the zero-coupon bond price
397 /// implied by stripping coupons from the par curve.
398 ///
399 /// For the first period, spot rate = par yield. For subsequent periods,
400 /// the bootstrap solves:
401 /// 100 = Sum_{t=1}^{N-1} [c/m / (1 + s_t)^t] + (100 + c/m) / (1 + s_N)^N
402 /// for s_N, using previously computed spot rates s_1..s_{N-1}.
403 ///
404 /// Model assumptions:
405 /// - Requires a complete par yield curve as input (no gaps).
406 /// - Bootstrap assumes exact coupon dates (no day-count adjustments).
407 ///
408 /// Applicability: Derived from Bond par curve. Used for discounting cashflows
409 /// and computing forward rates.
410 /// Units: Decimal (0-1 scale; e.g. 0.046 = 4.60% annual).
411 SpotYield = 16,
412 /// The forward yield between two future dates, implied by the spot curve.
413 /// The forward rate f(t1, t2) is the rate agreed today for borrowing/lending
414 /// between future times t1 and t2.
415 ///
416 /// Formula:
417 /// f(t1, t2) = [(1 + s_{t2})^{t2} / (1 + s_{t1})^{t1}]^{1/(t2 - t1)} - 1
418 /// Where s_t are spot rates for maturities t1 and t2.
419 ///
420 /// For example, the 1-year forward rate 1 year from now (1y1y) is:
421 /// f(1,2) = [(1 + s_2)^2 / (1 + s_1)]^1 - 1
422 ///
423 /// Model assumptions:
424 /// - Derived from the spot curve (which is bootstrapped from par).
425 /// - Assumes no arbitrage between spot and forward rates.
426 /// - The forward period is defined by adjacent tenor points in the
427 /// CurveRequestProto.
428 ///
429 /// Applicability: Derived from Bond spot curve. Used for rate expectations
430 /// and forward-starting instrument pricing.
431 /// Units: Decimal (0-1 scale; e.g. 0.048 = 4.80% annual forward rate).
432 ForwardYield = 17,
433 /// The profit or loss on a position relative to its cost basis.
434 ///
435 /// Formula:
436 /// ProfitLoss = MarketValue - (UnadjustedCostBasis / 100 * DirectedQuantity)
437 ///
438 /// Applicability: All security types.
439 /// Units: Dollars (or settlement currency).
440 ProfitLoss = 18,
441 /// The profit or loss as a percentage of the original cost basis.
442 ///
443 /// Formula:
444 /// ProfitLossPercent = ProfitLoss / (UnadjustedCostBasis / 100 * DirectedQuantity)
445 ///
446 /// Applicability: All security types.
447 /// Units: Decimal (0-1 scale; e.g. 0.05 = 5.00% gain).
448 ProfitLossPercent = 19,
449 /// The accrued interest on a bond position — the pro-rated coupon income earned
450 /// since the last coupon payment date but not yet received.
451 ///
452 /// Formula (coupon-bearing bonds):
453 /// AccruedInterest = (coupon_rate / coupon_frequency) * (days_since_last_coupon / days_in_period)
454 /// * directed_quantity
455 /// Day count: Actual/Actual (ICMA) for US Treasuries.
456 ///
457 /// Accrued interest on settlement date T is the interest accumulated from the
458 /// last coupon date up to but not including T.
459 ///
460 /// Applicability: Bond, TIPS, FRN (coupon-bearing securities).
461 /// Returns null/zero for Equity, Cash, and zero-coupon bonds.
462 /// Units: Dollars (absolute dollar amount for the position).
463 AccruedInterest = 20,
464 /// The second derivative of a bond's price with respect to yield, normalised by price.
465 /// Convexity measures how the duration of a bond changes as yield changes — a bond
466 /// with higher convexity gains more in price when yields fall and loses less when
467 /// yields rise, compared to a bond with lower convexity of equal duration.
468 ///
469 /// Formula:
470 /// Convexity = (1/P) × Σ_{t=1}^{N} [CF_t × t × (t+1) / (1+y/n)^(t+2)] / n²
471 ///
472 /// Equivalently, in terms of periodic-discount PVs:
473 /// Convexity = Σ_{t=1}^{N} [t(t+1) × PV_t] / (P_dollar × n² × (1+r)²)
474 /// Where r = y/n (periodic yield), P_dollar = dollar price,
475 /// PV_t = CF_t / (1+r)^t, n = coupon frequency (periods per year).
476 ///
477 /// Model assumptions:
478 /// - Same as MACAULAY_DURATION (flat yield curve, YTM-based discounting).
479 /// - For FRN: uses flat-forwards effective YTM (same model as PRESENT_VALUE).
480 /// - Settlement on a coupon date (integer period exponents).
481 ///
482 /// Applicability: Bond, TIPS, FRN. UNIMPLEMENTED for Equity and Cash.
483 /// Units: Years² (e.g. 20.5 = 20.5 years²).
484 Convexity = 21,
485 /// The full (invoice) price of a bond including accrued interest, expressed as a
486 /// percentage of face value.
487 ///
488 /// Formula:
489 /// DirtyPrice = market_value / (num_bonds * face_value) * 100
490 /// where num_bonds = directed_quantity / face_value
491 /// Equivalently: market_value / directed_quantity * 100
492 ///
493 /// Applicability: Bond, TIPS. UNIMPLEMENTED for Equity and Cash.
494 /// Units: Percentage of par (e.g. 99.5 = 99.5% of par).
495 DirtyPrice = 22,
496 /// The quoted price of a bond excluding accrued interest, expressed as a
497 /// percentage of face value. This is the price conventionally quoted in bond markets.
498 ///
499 /// Formula:
500 /// CleanPrice = DirtyPrice - (accrued_interest / directed_quantity * 100)
501 ///
502 /// Applicability: Bond, TIPS. UNIMPLEMENTED for Equity and Cash.
503 /// Units: Percentage of par (e.g. 98.75 = 98.75% of par).
504 CleanPrice = 23,
505 /// Modified Duration = MacaulayDuration / (1 + ytm/coupon_frequency).
506 ///
507 /// Measures the percentage price change of a bond for a 1% (100bp) change in yield.
508 /// Unlike Macaulay Duration (which is expressed in years), Modified Duration is a
509 /// direct measure of price sensitivity: a bond with ModifiedDuration=5 will move
510 /// approximately 5% in price for a 100bp parallel shift in yield.
511 ///
512 /// Formula:
513 /// ModifiedDuration = MacaulayDuration / (1 + ytm/n)
514 /// where ytm = yield to maturity (annual), n = coupon periods per year.
515 ///
516 /// Applicability: Bond, TIPS, FRN. UNIMPLEMENTED for Equity and Cash.
517 /// Units: Years (dimensionally equivalent to years, interpreted as % per 100bp).
518 ModifiedDuration = 24,
519 /// DV01 (Dollar Value of 01) = the dollar P&L impact of a 1bp (0.01%) yield increase.
520 ///
521 /// Formula:
522 /// DV01 = ModifiedDuration × MarketValue × 0.0001
523 ///
524 /// For a $1M market value position with ModifiedDuration=5:
525 /// DV01 = 5 × 1,000,000 × 0.0001 = $500 per bp
526 ///
527 /// Applicability: Bond, TIPS, FRN. UNIMPLEMENTED for Equity and Cash.
528 /// Units: Dollars per basis point.
529 Dv01 = 25,
530 /// U.S. Treasury Bill discount-basis yield. The market convention used by
531 /// TreasuryDirect auction results ("High discount rate"), Bloomberg TBILL
532 /// screens, and most short-tenor money-market quotes.
533 ///
534 /// Formula:
535 /// DiscountYield = (F - P) / F × 360 / days_to_maturity
536 /// Where F = face value (par), P = dollar price, day count is Actual/360.
537 ///
538 /// Example: 13W TBill 912797TW7 priced at 99.082, days_to_maturity=91:
539 /// DiscountYield = (100 - 99.082) / 100 × 360 / 91 = 0.0363 = 3.63%
540 ///
541 /// Distinct from YIELD_TO_MATURITY which uses the annual-compound convention
542 /// (F/P)^(1/years) - 1; the two differ by 5-14bp at typical TBill tenors.
543 /// The U.S. Treasury publishes BOTH conventions for each auction plus
544 /// BOND_EQUIVALENT_YIELD; the industry-standard wire format for TBills is
545 /// DiscountYield. See #209.
546 ///
547 /// Model assumptions:
548 /// - Simple (non-compounded) discount basis — standard U.S. money-market.
549 /// - 360-day year (Actual/360 day count).
550 /// - Assumes the security has a defined maturity_date and face_value;
551 /// null for instruments where days_to_maturity is undefined.
552 ///
553 /// Applicability: Zero-coupon short-tenor securities — Tbill, principal-only
554 /// Strips with <1yr remaining. Returns null/error for other product types.
555 /// Units: Decimal (0-1 scale; e.g. 0.0363 = 3.63%).
556 DiscountYield = 26,
557 /// Bond-Equivalent Yield (BEY) for U.S. Treasury Bills — also known as the
558 /// "investment rate" published alongside DISCOUNT_YIELD on TreasuryDirect.
559 /// The conventional way to compare TBill returns to coupon-bearing bond
560 /// yields (which conventionally use a 365-day year).
561 ///
562 /// Formula:
563 /// BondEquivalentYield = (F - P) / P × 365 / days_to_maturity
564 /// Where F = face value (par), P = dollar price, day count is Actual/365.
565 ///
566 /// Example: 13W TBill 912797TW7 priced at 99.082, days_to_maturity=91:
567 /// BEY = (100 - 99.082) / 99.082 × 365 / 91 = 0.0371 = 3.71%
568 ///
569 /// Distinct from DISCOUNT_YIELD which uses 360-day simple discount; BEY's
570 /// dividing-by-P (not F) and 365-day basis make it directly comparable to
571 /// YTM on a coupon-bearing Treasury Note of equivalent tenor. The Treasury
572 /// calls this the "investment rate" on auction results. See #209.
573 ///
574 /// Model assumptions:
575 /// - Simple (non-compounded) basis.
576 /// - 365-day year (Actual/365 day count).
577 /// - Same applicability constraints as DISCOUNT_YIELD.
578 ///
579 /// Applicability: Zero-coupon short-tenor securities — Tbill, principal-only
580 /// Strips with <1yr remaining. Returns null/error for other product types.
581 /// Units: Decimal (0-1 scale; e.g. 0.0371 = 3.71%).
582 BondEquivalentYield = 27,
583}
584impl MeasureProto {
585 /// String value of the enum field names used in the ProtoBuf definition.
586 ///
587 /// The values are not transformed in any way and thus are considered stable
588 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
589 pub fn as_str_name(&self) -> &'static str {
590 match self {
591 MeasureProto::UnknownMeasure => "UNKNOWN_MEASURE",
592 MeasureProto::DirectedQuantity => "DIRECTED_QUANTITY",
593 MeasureProto::MarketValue => "MARKET_VALUE",
594 MeasureProto::UnadjustedCostBasis => "UNADJUSTED_COST_BASIS",
595 MeasureProto::AdjustedCostBasis => "ADJUSTED_COST_BASIS",
596 MeasureProto::CurrentYield => "CURRENT_YIELD",
597 MeasureProto::YieldToMaturity => "YIELD_TO_MATURITY",
598 MeasureProto::MacaulayDuration => "MACAULAY_DURATION",
599 MeasureProto::PresentValue => "PRESENT_VALUE",
600 MeasureProto::RealYield => "REAL_YIELD",
601 MeasureProto::InflationAdjustedPrincipal => "INFLATION_ADJUSTED_PRINCIPAL",
602 MeasureProto::PresentValueCashflows => "PRESENT_VALUE_CASHFLOWS",
603 MeasureProto::DiscountMargin => "DISCOUNT_MARGIN",
604 MeasureProto::SpreadDuration => "SPREAD_DURATION",
605 MeasureProto::ParYield => "PAR_YIELD",
606 MeasureProto::SpotYield => "SPOT_YIELD",
607 MeasureProto::ForwardYield => "FORWARD_YIELD",
608 MeasureProto::ProfitLoss => "PROFIT_LOSS",
609 MeasureProto::ProfitLossPercent => "PROFIT_LOSS_PERCENT",
610 MeasureProto::AccruedInterest => "ACCRUED_INTEREST",
611 MeasureProto::Convexity => "CONVEXITY",
612 MeasureProto::DirtyPrice => "DIRTY_PRICE",
613 MeasureProto::CleanPrice => "CLEAN_PRICE",
614 MeasureProto::ModifiedDuration => "MODIFIED_DURATION",
615 MeasureProto::Dv01 => "DV01",
616 MeasureProto::DiscountYield => "DISCOUNT_YIELD",
617 MeasureProto::BondEquivalentYield => "BOND_EQUIVALENT_YIELD",
618 }
619 }
620 /// Creates an enum from field names used in the ProtoBuf definition.
621 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
622 match value {
623 "UNKNOWN_MEASURE" => Some(Self::UnknownMeasure),
624 "DIRECTED_QUANTITY" => Some(Self::DirectedQuantity),
625 "MARKET_VALUE" => Some(Self::MarketValue),
626 "UNADJUSTED_COST_BASIS" => Some(Self::UnadjustedCostBasis),
627 "ADJUSTED_COST_BASIS" => Some(Self::AdjustedCostBasis),
628 "CURRENT_YIELD" => Some(Self::CurrentYield),
629 "YIELD_TO_MATURITY" => Some(Self::YieldToMaturity),
630 "MACAULAY_DURATION" => Some(Self::MacaulayDuration),
631 "PRESENT_VALUE" => Some(Self::PresentValue),
632 "REAL_YIELD" => Some(Self::RealYield),
633 "INFLATION_ADJUSTED_PRINCIPAL" => Some(Self::InflationAdjustedPrincipal),
634 "PRESENT_VALUE_CASHFLOWS" => Some(Self::PresentValueCashflows),
635 "DISCOUNT_MARGIN" => Some(Self::DiscountMargin),
636 "SPREAD_DURATION" => Some(Self::SpreadDuration),
637 "PAR_YIELD" => Some(Self::ParYield),
638 "SPOT_YIELD" => Some(Self::SpotYield),
639 "FORWARD_YIELD" => Some(Self::ForwardYield),
640 "PROFIT_LOSS" => Some(Self::ProfitLoss),
641 "PROFIT_LOSS_PERCENT" => Some(Self::ProfitLossPercent),
642 "ACCRUED_INTEREST" => Some(Self::AccruedInterest),
643 "CONVEXITY" => Some(Self::Convexity),
644 "DIRTY_PRICE" => Some(Self::DirtyPrice),
645 "CLEAN_PRICE" => Some(Self::CleanPrice),
646 "MODIFIED_DURATION" => Some(Self::ModifiedDuration),
647 "DV01" => Some(Self::Dv01),
648 "DISCOUNT_YIELD" => Some(Self::DiscountYield),
649 "BOND_EQUIVALENT_YIELD" => Some(Self::BondEquivalentYield),
650 _ => None,
651 }
652 }
653}
654#[allow(clippy::derive_partial_eq_without_eq)]
655#[derive(Clone, PartialEq, ::prost::Message)]
656pub struct MeasureMapEntry {
657 #[prost(enumeration = "MeasureProto", tag = "1")]
658 pub measure: i32,
659 #[prost(message, optional, tag = "2")]
660 pub measure_decimal_value: ::core::option::Option<super::util::DecimalValueProto>,
661}
662#[allow(clippy::derive_partial_eq_without_eq)]
663#[derive(Clone, PartialEq, ::prost::Message)]
664pub struct FieldMapEntry {
665 #[prost(enumeration = "FieldProto", tag = "1")]
666 pub field: i32,
667 /// Used for position filters, but not for responses
668 #[prost(enumeration = "PositionFilterOperator", tag = "20")]
669 pub operator: i32,
670 #[prost(oneof = "field_map_entry::FieldMapValueOneOf", tags = "4, 5, 6")]
671 pub field_map_value_one_of: ::core::option::Option<
672 field_map_entry::FieldMapValueOneOf,
673 >,
674}
675/// Nested message and enum types in `FieldMapEntry`.
676pub mod field_map_entry {
677 #[allow(clippy::derive_partial_eq_without_eq)]
678 #[derive(Clone, PartialEq, ::prost::Oneof)]
679 pub enum FieldMapValueOneOf {
680 /// 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
681 #[prost(message, tag = "4")]
682 FieldValuePacked(::prost_types::Any),
683 /// If the field is an enum type, then we use the number to denote which value it is
684 #[prost(int32, tag = "5")]
685 EnumValue(i32),
686 /// If the field is a string type, we just serialize the string (packing has an overhead)
687 #[prost(string, tag = "6")]
688 StringValue(::prost::alloc::string::String),
689 }
690}
691#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
692#[repr(i32)]
693pub enum PositionFilterOperator {
694 UnknownOperator = 0,
695 Equals = 1,
696 NotEquals = 2,
697 LessThan = 3,
698 LessThanOrEquals = 4,
699 MoreThan = 5,
700 MoreThanOrEquals = 6,
701}
702impl PositionFilterOperator {
703 /// String value of the enum field names used in the ProtoBuf definition.
704 ///
705 /// The values are not transformed in any way and thus are considered stable
706 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
707 pub fn as_str_name(&self) -> &'static str {
708 match self {
709 PositionFilterOperator::UnknownOperator => "UNKNOWN_OPERATOR",
710 PositionFilterOperator::Equals => "EQUALS",
711 PositionFilterOperator::NotEquals => "NOT_EQUALS",
712 PositionFilterOperator::LessThan => "LESS_THAN",
713 PositionFilterOperator::LessThanOrEquals => "LESS_THAN_OR_EQUALS",
714 PositionFilterOperator::MoreThan => "MORE_THAN",
715 PositionFilterOperator::MoreThanOrEquals => "MORE_THAN_OR_EQUALS",
716 }
717 }
718 /// Creates an enum from field names used in the ProtoBuf definition.
719 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
720 match value {
721 "UNKNOWN_OPERATOR" => Some(Self::UnknownOperator),
722 "EQUALS" => Some(Self::Equals),
723 "NOT_EQUALS" => Some(Self::NotEquals),
724 "LESS_THAN" => Some(Self::LessThan),
725 "LESS_THAN_OR_EQUALS" => Some(Self::LessThanOrEquals),
726 "MORE_THAN" => Some(Self::MoreThan),
727 "MORE_THAN_OR_EQUALS" => Some(Self::MoreThanOrEquals),
728 _ => None,
729 }
730 }
731}
732#[allow(clippy::derive_partial_eq_without_eq)]
733#[derive(Clone, PartialEq, ::prost::Message)]
734pub struct PositionProto {
735 #[prost(string, tag = "1")]
736 pub object_class: ::prost::alloc::string::String,
737 #[prost(string, tag = "2")]
738 pub version: ::prost::alloc::string::String,
739 #[prost(enumeration = "PositionViewProto", tag = "10")]
740 pub position_view: i32,
741 #[prost(enumeration = "PositionTypeProto", tag = "11")]
742 pub position_type: i32,
743 #[prost(message, repeated, tag = "20")]
744 pub measures: ::prost::alloc::vec::Vec<MeasureMapEntry>,
745 #[prost(message, repeated, tag = "21")]
746 pub fields: ::prost::alloc::vec::Vec<FieldMapEntry>,
747 /// The base/reporting currency for monetary measures in this position.
748 /// Set to the portfolio's base currency (e.g. USD cash security).
749 /// Allows the UI to display the currency alongside MARKET_VALUE and other measures.
750 #[prost(message, optional, tag = "22")]
751 pub reporting_currency: ::core::option::Option<super::security::SecurityProto>,
752}
753#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
754#[repr(i32)]
755pub enum PositionViewProto {
756 UnknownPositionView = 0,
757 DefaultView = 1,
758 StrategyView = 2,
759}
760impl PositionViewProto {
761 /// String value of the enum field names used in the ProtoBuf definition.
762 ///
763 /// The values are not transformed in any way and thus are considered stable
764 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
765 pub fn as_str_name(&self) -> &'static str {
766 match self {
767 PositionViewProto::UnknownPositionView => "UNKNOWN_POSITION_VIEW",
768 PositionViewProto::DefaultView => "DEFAULT_VIEW",
769 PositionViewProto::StrategyView => "STRATEGY_VIEW",
770 }
771 }
772 /// Creates an enum from field names used in the ProtoBuf definition.
773 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
774 match value {
775 "UNKNOWN_POSITION_VIEW" => Some(Self::UnknownPositionView),
776 "DEFAULT_VIEW" => Some(Self::DefaultView),
777 "STRATEGY_VIEW" => Some(Self::StrategyView),
778 _ => None,
779 }
780 }
781}
782#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
783#[repr(i32)]
784pub enum PositionTypeProto {
785 UnknownPositionType = 0,
786 Transaction = 1,
787 TaxLot = 2,
788}
789impl PositionTypeProto {
790 /// String value of the enum field names used in the ProtoBuf definition.
791 ///
792 /// The values are not transformed in any way and thus are considered stable
793 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
794 pub fn as_str_name(&self) -> &'static str {
795 match self {
796 PositionTypeProto::UnknownPositionType => "UNKNOWN_POSITION_TYPE",
797 PositionTypeProto::Transaction => "TRANSACTION",
798 PositionTypeProto::TaxLot => "TAX_LOT",
799 }
800 }
801 /// Creates an enum from field names used in the ProtoBuf definition.
802 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
803 match value {
804 "UNKNOWN_POSITION_TYPE" => Some(Self::UnknownPositionType),
805 "TRANSACTION" => Some(Self::Transaction),
806 "TAX_LOT" => Some(Self::TaxLot),
807 _ => None,
808 }
809 }
810}
811#[allow(clippy::derive_partial_eq_without_eq)]
812#[derive(Clone, PartialEq, ::prost::Message)]
813pub struct PositionFilterProto {
814 #[prost(string, tag = "1")]
815 pub object_class: ::prost::alloc::string::String,
816 #[prost(string, tag = "2")]
817 pub version: ::prost::alloc::string::String,
818 #[prost(message, repeated, tag = "21")]
819 pub filters: ::prost::alloc::vec::Vec<FieldMapEntry>,
820}
821#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
822#[repr(i32)]
823pub enum PositionStatusProto {
824 Unknown = 0,
825 /// 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
826 Hypothetical = 1,
827 /// 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
828 Intended = 2,
829 /// Executed status means a transaction, tax lot or position that is the result of a legally binding transaction
830 Executed = 3,
831}
832impl PositionStatusProto {
833 /// String value of the enum field names used in the ProtoBuf definition.
834 ///
835 /// The values are not transformed in any way and thus are considered stable
836 /// (if the ProtoBuf definition does not change) and safe for programmatic use.
837 pub fn as_str_name(&self) -> &'static str {
838 match self {
839 PositionStatusProto::Unknown => "UNKNOWN",
840 PositionStatusProto::Hypothetical => "HYPOTHETICAL",
841 PositionStatusProto::Intended => "INTENDED",
842 PositionStatusProto::Executed => "EXECUTED",
843 }
844 }
845 /// Creates an enum from field names used in the ProtoBuf definition.
846 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
847 match value {
848 "UNKNOWN" => Some(Self::Unknown),
849 "HYPOTHETICAL" => Some(Self::Hypothetical),
850 "INTENDED" => Some(Self::Intended),
851 "EXECUTED" => Some(Self::Executed),
852 _ => None,
853 }
854 }
855}