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