rustkernel_treasury/types.rs
1//! Treasury management types.
2
3use std::collections::HashMap;
4
5// ============================================================================
6// Cash Flow Types
7// ============================================================================
8
9/// A cash flow entry.
10#[derive(Debug, Clone)]
11pub struct CashFlow {
12 /// Entry ID.
13 pub id: u64,
14 /// Date (Unix timestamp).
15 pub date: u64,
16 /// Amount (positive = inflow, negative = outflow).
17 pub amount: f64,
18 /// Currency.
19 pub currency: String,
20 /// Cash flow category.
21 pub category: CashFlowCategory,
22 /// Certainty level (0-1).
23 pub certainty: f64,
24 /// Description.
25 pub description: String,
26 /// Attributes.
27 pub attributes: HashMap<String, String>,
28}
29
30/// Cash flow category.
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
32pub enum CashFlowCategory {
33 /// Operating cash flows.
34 Operating,
35 /// Investment cash flows.
36 Investing,
37 /// Financing cash flows.
38 Financing,
39 /// Debt service.
40 DebtService,
41 /// Dividend payments.
42 Dividend,
43 /// Tax payments.
44 Tax,
45 /// Other.
46 Other,
47}
48
49/// Cash flow forecast result.
50#[derive(Debug, Clone)]
51pub struct CashFlowForecast {
52 /// Forecast horizon (days).
53 pub horizon_days: u32,
54 /// Daily forecasts.
55 pub daily_forecasts: Vec<DailyForecast>,
56 /// Total inflows.
57 pub total_inflows: f64,
58 /// Total outflows.
59 pub total_outflows: f64,
60 /// Net position at horizon.
61 pub net_position: f64,
62 /// Minimum balance during horizon.
63 pub min_balance: f64,
64 /// Maximum balance during horizon.
65 pub max_balance: f64,
66}
67
68/// Daily forecast.
69#[derive(Debug, Clone)]
70pub struct DailyForecast {
71 /// Date.
72 pub date: u64,
73 /// Expected inflows.
74 pub inflows: f64,
75 /// Expected outflows.
76 pub outflows: f64,
77 /// Net cash flow.
78 pub net: f64,
79 /// Cumulative balance.
80 pub cumulative_balance: f64,
81 /// Forecast uncertainty.
82 pub uncertainty: f64,
83}
84
85// ============================================================================
86// Collateral Types
87// ============================================================================
88
89/// Collateral asset.
90#[derive(Debug, Clone)]
91pub struct CollateralAsset {
92 /// Asset ID.
93 pub id: String,
94 /// Asset type.
95 pub asset_type: AssetType,
96 /// Quantity held.
97 pub quantity: f64,
98 /// Market value.
99 pub market_value: f64,
100 /// Haircut (discount factor).
101 pub haircut: f64,
102 /// Eligible value after haircut.
103 pub eligible_value: f64,
104 /// Currency.
105 pub currency: String,
106 /// Is pledged.
107 pub is_pledged: bool,
108 /// Pledged to (counterparty).
109 pub pledged_to: Option<String>,
110}
111
112/// Asset type.
113#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
114pub enum AssetType {
115 /// Cash.
116 Cash,
117 /// Government bonds.
118 GovBond,
119 /// Corporate bonds.
120 CorpBond,
121 /// Equities.
122 Equity,
123 /// Money market instruments.
124 MoneyMarket,
125 /// Other.
126 Other,
127}
128
129/// Collateral requirement.
130#[derive(Debug, Clone)]
131pub struct CollateralRequirement {
132 /// Counterparty ID.
133 pub counterparty_id: String,
134 /// Required amount.
135 pub required_amount: f64,
136 /// Currency.
137 pub currency: String,
138 /// Eligible asset types.
139 pub eligible_types: Vec<AssetType>,
140 /// Priority.
141 pub priority: u32,
142}
143
144/// Collateral optimization result.
145#[derive(Debug, Clone)]
146pub struct CollateralOptimizationResult {
147 /// Allocations.
148 pub allocations: Vec<CollateralAllocation>,
149 /// Total value allocated.
150 pub total_allocated: f64,
151 /// Excess collateral.
152 pub excess: f64,
153 /// Unmet requirements.
154 pub shortfall: f64,
155 /// Optimization score.
156 pub score: f64,
157}
158
159/// Collateral allocation.
160#[derive(Debug, Clone)]
161pub struct CollateralAllocation {
162 /// Asset ID.
163 pub asset_id: String,
164 /// Counterparty ID.
165 pub counterparty_id: String,
166 /// Allocated quantity.
167 pub quantity: f64,
168 /// Allocated value.
169 pub value: f64,
170}
171
172// ============================================================================
173// FX Types
174// ============================================================================
175
176/// Currency exposure.
177#[derive(Debug, Clone)]
178pub struct CurrencyExposure {
179 /// Currency.
180 pub currency: String,
181 /// Net position.
182 pub net_position: f64,
183 /// Long positions.
184 pub long_positions: f64,
185 /// Short positions.
186 pub short_positions: f64,
187 /// Base currency equivalent.
188 pub base_equivalent: f64,
189}
190
191/// FX rate.
192#[derive(Debug, Clone)]
193pub struct FXRate {
194 /// Base currency.
195 pub base: String,
196 /// Quote currency.
197 pub quote: String,
198 /// Rate.
199 pub rate: f64,
200 /// Bid.
201 pub bid: f64,
202 /// Ask.
203 pub ask: f64,
204 /// Timestamp.
205 pub timestamp: u64,
206}
207
208/// FX hedge.
209#[derive(Debug, Clone)]
210pub struct FXHedge {
211 /// Hedge ID.
212 pub id: u64,
213 /// Currency pair.
214 pub currency_pair: String,
215 /// Notional amount.
216 pub notional: f64,
217 /// Hedge type.
218 pub hedge_type: HedgeType,
219 /// Strike rate (for options).
220 pub strike: Option<f64>,
221 /// Expiry date.
222 pub expiry: u64,
223 /// Cost.
224 pub cost: f64,
225}
226
227/// Hedge type.
228#[derive(Debug, Clone, Copy, PartialEq, Eq)]
229pub enum HedgeType {
230 /// Forward contract.
231 Forward,
232 /// Put option.
233 Put,
234 /// Call option.
235 Call,
236 /// Collar (put + call).
237 Collar,
238 /// Cross-currency swap.
239 Swap,
240}
241
242/// FX hedging result.
243#[derive(Debug, Clone)]
244pub struct FXHedgingResult {
245 /// Recommended hedges.
246 pub hedges: Vec<FXHedge>,
247 /// Net exposure after hedging.
248 pub residual_exposure: f64,
249 /// Hedge ratio.
250 pub hedge_ratio: f64,
251 /// Total hedge cost.
252 pub total_cost: f64,
253 /// VaR reduction.
254 pub var_reduction: f64,
255}
256
257// ============================================================================
258// Interest Rate Risk Types
259// ============================================================================
260
261/// Interest rate sensitive position.
262#[derive(Debug, Clone)]
263pub struct IRPosition {
264 /// Position ID.
265 pub id: String,
266 /// Instrument type.
267 pub instrument_type: IRInstrumentType,
268 /// Notional.
269 pub notional: f64,
270 /// Current rate.
271 pub rate: f64,
272 /// Maturity date.
273 pub maturity: u64,
274 /// Next reset date (for floaters).
275 pub next_reset: Option<u64>,
276 /// Currency.
277 pub currency: String,
278}
279
280/// IR instrument type.
281#[derive(Debug, Clone, Copy, PartialEq, Eq)]
282pub enum IRInstrumentType {
283 /// Fixed rate bond.
284 FixedBond,
285 /// Floating rate note.
286 FloatingNote,
287 /// Interest rate swap.
288 Swap,
289 /// Fixed rate loan.
290 FixedLoan,
291 /// Floating rate loan.
292 FloatingLoan,
293 /// Deposit.
294 Deposit,
295}
296
297/// Interest rate risk metrics.
298#[derive(Debug, Clone)]
299pub struct IRRiskMetrics {
300 /// Total duration.
301 pub duration: f64,
302 /// Modified duration.
303 pub modified_duration: f64,
304 /// Convexity.
305 pub convexity: f64,
306 /// DV01 (dollar value of 1bp).
307 pub dv01: f64,
308 /// PV01 by currency.
309 pub pv01_by_currency: HashMap<String, f64>,
310 /// Gap analysis by time bucket.
311 pub gap_by_bucket: Vec<GapBucket>,
312}
313
314/// Gap analysis bucket.
315#[derive(Debug, Clone)]
316pub struct GapBucket {
317 /// Bucket name.
318 pub bucket: String,
319 /// Start days.
320 pub start_days: u32,
321 /// End days.
322 pub end_days: u32,
323 /// Rate sensitive assets.
324 pub assets: f64,
325 /// Rate sensitive liabilities.
326 pub liabilities: f64,
327 /// Gap (assets - liabilities).
328 pub gap: f64,
329 /// Cumulative gap.
330 pub cumulative_gap: f64,
331}
332
333// ============================================================================
334// Liquidity Types
335// ============================================================================
336
337/// Liquidity position.
338#[derive(Debug, Clone)]
339pub struct LiquidityPosition {
340 /// Asset ID.
341 pub id: String,
342 /// Asset type.
343 pub asset_type: LiquidityAssetType,
344 /// Amount.
345 pub amount: f64,
346 /// Currency.
347 pub currency: String,
348 /// HQLA level (1, 2A, 2B, or None).
349 pub hqla_level: Option<u8>,
350 /// Haircut for LCR.
351 pub lcr_haircut: f64,
352 /// Days to liquidate.
353 pub days_to_liquidate: u32,
354}
355
356/// Liquidity asset type.
357#[derive(Debug, Clone, Copy, PartialEq, Eq)]
358pub enum LiquidityAssetType {
359 /// Cash and central bank reserves.
360 CashReserves,
361 /// Level 1 HQLA.
362 Level1HQLA,
363 /// Level 2A HQLA.
364 Level2AHQLA,
365 /// Level 2B HQLA.
366 Level2BHQLA,
367 /// Other liquid assets.
368 OtherLiquid,
369 /// Illiquid assets.
370 Illiquid,
371}
372
373/// Liquidity outflow.
374#[derive(Debug, Clone)]
375pub struct LiquidityOutflow {
376 /// Category.
377 pub category: OutflowCategory,
378 /// Amount.
379 pub amount: f64,
380 /// Currency.
381 pub currency: String,
382 /// Runoff rate.
383 pub runoff_rate: f64,
384 /// Days to maturity.
385 pub days_to_maturity: u32,
386}
387
388/// Outflow category.
389#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
390pub enum OutflowCategory {
391 /// Retail deposits.
392 RetailDeposits,
393 /// Wholesale funding.
394 WholesaleFunding,
395 /// Secured funding.
396 SecuredFunding,
397 /// Committed facilities.
398 CommittedFacilities,
399 /// Derivatives.
400 Derivatives,
401 /// Other.
402 Other,
403}
404
405/// LCR calculation result.
406#[derive(Debug, Clone)]
407pub struct LCRResult {
408 /// HQLA amount.
409 pub hqla: f64,
410 /// Net cash outflows.
411 pub net_outflows: f64,
412 /// LCR ratio.
413 pub lcr_ratio: f64,
414 /// Is compliant (>= 100%).
415 pub is_compliant: bool,
416 /// Buffer above minimum.
417 pub buffer: f64,
418 /// Breakdown by level.
419 pub hqla_breakdown: HashMap<String, f64>,
420}
421
422/// NSFR calculation result.
423#[derive(Debug, Clone)]
424pub struct NSFRResult {
425 /// Available stable funding.
426 pub asf: f64,
427 /// Required stable funding.
428 pub rsf: f64,
429 /// NSFR ratio.
430 pub nsfr_ratio: f64,
431 /// Is compliant (>= 100%).
432 pub is_compliant: bool,
433 /// Buffer above minimum.
434 pub buffer: f64,
435}
436
437/// Liquidity optimization result.
438#[derive(Debug, Clone)]
439pub struct LiquidityOptimizationResult {
440 /// LCR after optimization.
441 pub lcr: LCRResult,
442 /// NSFR after optimization.
443 pub nsfr: NSFRResult,
444 /// Recommended actions.
445 pub actions: Vec<LiquidityAction>,
446 /// Cost of actions.
447 pub total_cost: f64,
448 /// Improvement in LCR.
449 pub lcr_improvement: f64,
450}
451
452/// Liquidity action.
453#[derive(Debug, Clone)]
454pub struct LiquidityAction {
455 /// Action type.
456 pub action_type: LiquidityActionType,
457 /// Asset/liability ID.
458 pub target_id: String,
459 /// Amount.
460 pub amount: f64,
461 /// Impact on LCR.
462 pub lcr_impact: f64,
463 /// Cost.
464 pub cost: f64,
465}
466
467/// Liquidity action type.
468#[derive(Debug, Clone, Copy, PartialEq, Eq)]
469pub enum LiquidityActionType {
470 /// Convert to HQLA.
471 ConvertToHQLA,
472 /// Extend funding maturity.
473 ExtendFunding,
474 /// Reduce outflow commitment.
475 ReduceCommitment,
476 /// Issue term funding.
477 IssueTerm,
478 /// Sell illiquid assets.
479 SellIlliquid,
480}