Special Relativity in Financial Modeling
1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
include
srfm
data_loader.hpp
Go to the documentation of this file.
1
#pragma once
2
3
/// @file include/srfm/data_loader.hpp
4
/// @brief CSV data loader for OHLCV market data — AGT-06.
5
///
6
/// # Module: DataLoader
7
///
8
/// ## Responsibility
9
/// Parse CSV files containing OHLCV market data into `std::vector<OHLCV>`.
10
/// Malformed or non-finite rows are skipped with a warning; the loader never
11
/// crashes on bad input.
12
///
13
/// ## Expected CSV Format
14
/// ```
15
/// timestamp,open,high,low,close,volume
16
/// 1,100.0,105.0,99.0,103.0,1000000
17
/// 2,103.0,107.0,102.0,106.5,1200000
18
/// ```
19
/// The first line is treated as a header and skipped.
20
///
21
/// ## Guarantees
22
/// - Never throws; returns `nullopt` on unrecoverable errors
23
/// - Skips individual bad rows rather than failing the entire load
24
/// - Does not modify any file or external state
25
26
#include "
srfm/engine.hpp
"
27
28
#include <optional>
29
#include <string>
30
#include <vector>
31
32
namespace
srfm::core
{
33
34
/// Loads OHLCV data from CSV files and stdin streams.
35
class
DataLoader
{
36
public
:
37
/// Load OHLCV bars from a CSV file on disk.
38
///
39
/// # Arguments
40
/// * `filepath` — Path to a CSV file with header row
41
/// (timestamp, open, high, low, close, volume)
42
///
43
/// # Returns
44
/// - `nullopt` if the file cannot be opened
45
/// - Empty vector if the file has a header but no valid data rows
46
/// - Vector of parsed bars, skipping any malformed or non-finite rows
47
[[nodiscard]]
static
std::optional<std::vector<OHLCV>>
48
load_csv
(
const
std::string& filepath)
noexcept
;
49
50
/// Parse OHLCV bars from a CSV-formatted string (useful for testing).
51
///
52
/// Same format as `load_csv` — first line is treated as a header.
53
///
54
/// # Returns
55
/// Parsed bars. Never returns `nullopt`; returns empty vector on
56
/// completely empty or header-only input.
57
[[nodiscard]]
static
std::vector<OHLCV>
58
parse_csv_string
(
const
std::string& csv_content)
noexcept
;
59
60
/// Validate a single OHLCV bar.
61
///
62
/// A bar is valid if:
63
/// - All fields are finite
64
/// - low <= open, close <= high
65
/// - high >= low
66
/// - volume >= 0
67
[[nodiscard]]
static
bool
validate_bar
(
const
OHLCV
& bar)
noexcept
;
68
69
private
:
70
/// Parse a single CSV data row into an OHLCV.
71
/// Returns `nullopt` if the row is malformed or values are non-finite.
72
[[nodiscard]]
static
std::optional<OHLCV>
73
parse_row(
const
std::string& line)
noexcept
;
74
};
75
76
}
// namespace srfm::core
srfm::core::DataLoader
Loads OHLCV data from CSV files and stdin streams.
Definition
data_loader.hpp:35
srfm::core::DataLoader::load_csv
static std::optional< std::vector< OHLCV > > load_csv(const std::string &filepath) noexcept
Definition
data_loader.cpp:193
srfm::core::DataLoader::validate_bar
static bool validate_bar(const OHLCV &bar) noexcept
Definition
data_loader.cpp:66
srfm::core::DataLoader::parse_csv_string
static std::vector< OHLCV > parse_csv_string(const std::string &csv_content) noexcept
Definition
data_loader.cpp:161
engine.hpp
Core Integration Engine — AGT-06 public API.
srfm::core
Definition
data_loader.cpp:13
srfm::core::OHLCV
A single OHLCV bar of market data.
Definition
engine.hpp:44
Generated on Fri Sep 25 2026 23:20:56 for Special Relativity in Financial Modeling by
1.9.8