Skip to main content

finance_query/fred/
models.rs

1//! Data models for macro-economic sources (FRED, US Treasury).
2
3use serde::{Deserialize, Serialize};
4
5/// A single observation in a FRED data series.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[non_exhaustive]
8pub struct MacroObservation {
9    /// Date of the observation as `YYYY-MM-DD`
10    pub date: String,
11    /// Observation value. `None` when FRED reports a missing value (`"."`).
12    pub value: Option<f64>,
13}
14
15/// A FRED macro-economic time series with all its observations.
16///
17/// Obtain via [`super::series`].
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[non_exhaustive]
20pub struct MacroSeries {
21    /// FRED series ID (e.g., `"FEDFUNDS"`, `"CPIAUCSL"`, `"DGS10"`)
22    pub id: String,
23    /// Chronologically ordered observations
24    pub observations: Vec<MacroObservation>,
25}
26
27/// One day of US Treasury yield curve rates.
28///
29/// Maturities with no published rate on a given date are `None`.
30/// Obtain via [`super::treasury_yields`].
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[non_exhaustive]
33pub struct TreasuryYield {
34    /// Date as `MM/DD/YYYY` (Treasury's native format)
35    pub date: String,
36    /// 1-month Treasury yield (%)
37    pub y1m: Option<f64>,
38    /// 2-month Treasury yield (%)
39    pub y2m: Option<f64>,
40    /// 3-month Treasury yield (%)
41    pub y3m: Option<f64>,
42    /// 4-month Treasury yield (%)
43    pub y4m: Option<f64>,
44    /// 6-month Treasury yield (%)
45    pub y6m: Option<f64>,
46    /// 1-year Treasury yield (%)
47    pub y1: Option<f64>,
48    /// 2-year Treasury yield (%)
49    pub y2: Option<f64>,
50    /// 3-year Treasury yield (%)
51    pub y3: Option<f64>,
52    /// 5-year Treasury yield (%)
53    pub y5: Option<f64>,
54    /// 7-year Treasury yield (%)
55    pub y7: Option<f64>,
56    /// 10-year Treasury yield (%)
57    pub y10: Option<f64>,
58    /// 20-year Treasury yield (%)
59    pub y20: Option<f64>,
60    /// 30-year Treasury yield (%)
61    pub y30: Option<f64>,
62}