finance_query/models/economic/mod.rs
1//! Macro-economic data models.
2//!
3//! Canonical public types for FRED series and US Treasury yield curve data.
4
5use serde::{Deserialize, Serialize};
6
7#[cfg(feature = "fiscaldata")]
8mod auctions;
9mod catalog;
10#[cfg(feature = "fiscaldata")]
11pub use auctions::{TreasuryAuction, TreasuryAuctionQuery, UpcomingAuction};
12pub use catalog::{EconomicCategory, EconomicRelease, EconomicSeriesMatch};
13
14/// A provider-agnostic economic data series with metadata.
15///
16/// Obtain via [`Providers::economic`](crate::Providers::economic) then
17/// [`.series()`](crate::domains::EconomicIndicator::series). Supported providers:
18/// Alpha Vantage, Polygon, FRED.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[non_exhaustive]
21pub struct EconomicSeries {
22 /// Series identifier (e.g., `"REAL_GDP"`, `"FEDFUNDS"`, `"inflation"`)
23 pub series_id: String,
24 /// Human-readable series title
25 pub title: Option<String>,
26 /// Unit of measurement (e.g., `"Billions of Dollars"`, `"Percent"`)
27 pub units: Option<String>,
28 /// Reporting frequency (e.g., `"Annual"`, `"Monthly"`)
29 pub frequency: Option<String>,
30 /// Chronologically ordered observations
31 pub observations: Vec<MacroObservation>,
32}
33
34/// A single observation in a FRED data series.
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[non_exhaustive]
37pub struct MacroObservation {
38 /// Date of the observation as `YYYY-MM-DD`
39 pub date: String,
40 /// Observation value. `None` when FRED reports a missing value (`"."`).
41 pub value: Option<f64>,
42}
43
44/// A FRED macro-economic time series with all its observations.
45///
46/// Obtain via [`fred::series`](crate::fred::series).
47#[cfg(feature = "fred")]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[non_exhaustive]
50pub struct MacroSeries {
51 /// FRED series ID (e.g., `"FEDFUNDS"`, `"CPIAUCSL"`, `"DGS10"`)
52 pub id: String,
53 /// Chronologically ordered observations
54 pub observations: Vec<MacroObservation>,
55}
56
57/// One day of US Treasury yield curve rates.
58///
59/// Maturities with no published rate on a given date are `None`.
60/// Obtain via [`fred::treasury_yields`](crate::fred::treasury_yields).
61#[cfg(feature = "fred")]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[non_exhaustive]
64pub struct TreasuryYield {
65 /// Date as `MM/DD/YYYY` (Treasury's native format)
66 pub date: String,
67 /// 1-month Treasury yield (%)
68 pub y1m: Option<f64>,
69 /// 2-month Treasury yield (%)
70 pub y2m: Option<f64>,
71 /// 3-month Treasury yield (%)
72 pub y3m: Option<f64>,
73 /// 4-month Treasury yield (%)
74 pub y4m: Option<f64>,
75 /// 6-month Treasury yield (%)
76 pub y6m: Option<f64>,
77 /// 1-year Treasury yield (%)
78 pub y1: Option<f64>,
79 /// 2-year Treasury yield (%)
80 pub y2: Option<f64>,
81 /// 3-year Treasury yield (%)
82 pub y3: Option<f64>,
83 /// 5-year Treasury yield (%)
84 pub y5: Option<f64>,
85 /// 7-year Treasury yield (%)
86 pub y7: Option<f64>,
87 /// 10-year Treasury yield (%)
88 pub y10: Option<f64>,
89 /// 20-year Treasury yield (%)
90 pub y20: Option<f64>,
91 /// 30-year Treasury yield (%)
92 pub y30: Option<f64>,
93}