Skip to main content

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