Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/// @file src/main.cpp
2/// @brief SRFM CLI entry point — AGT-06.
3///
4/// Usage:
5/// srfm --backtest <csv_file> Run a relativistic backtest on OHLCV data
6/// srfm --stream Read OHLCV bars from stdin (one CSV row each)
7/// srfm --help Print usage
8
9#include "srfm/engine.hpp"
10#include "srfm/data_loader.hpp"
11
12#include <fmt/core.h>
13
14#include <cstring>
15#include <iostream>
16#include <string>
17
18namespace {
19
20void print_usage() {
21 fmt::print(
22 "Usage:\n"
23 " srfm --backtest <csv_file> Backtest on OHLCV CSV data\n"
24 " srfm --stream Stream OHLCV bars from stdin\n"
25 " srfm --help Show this help\n"
26 "\n"
27 "CSV format (header required):\n"
28 " timestamp,open,high,low,close,volume\n"
29 );
30}
31
32/// Run a full batch backtest on the given CSV file.
33/// Returns 0 on success, 1 on error.
34int run_backtest(const std::string& filepath) {
35 auto bars = srfm::core::DataLoader::load_csv(filepath);
36 if (!bars) {
37 fmt::print(stderr, "Error: cannot open file '{}'\n", filepath);
38 return 1;
39 }
40
41 if (bars->empty()) {
42 fmt::print(stderr, "Error: no valid bars loaded from '{}'\n", filepath);
43 return 1;
44 }
45
46 fmt::print("Loaded {} bars from '{}'\n", bars->size(), filepath);
47
48 srfm::core::Engine engine;
49 auto result = engine.run_backtest(*bars);
50
51 if (!result) {
52 fmt::print(stderr,
53 "Error: backtest failed — too few bars ({} loaded, {} required)\n",
55 return 1;
56 }
57
58 fmt::print("{}\n", result->to_string());
59 return 0;
60}
61
62/// Read OHLCV CSV rows from stdin and process each bar through the engine.
63/// The header line is the first line of stdin.
64/// Returns 0 on success, 1 on error.
65int run_stream() {
66 srfm::core::Engine engine;
67
68 std::string line;
69 bool header_skipped = false;
70 std::size_t bar_count = 0;
71
72 fmt::print("SRFM streaming mode. Enter OHLCV rows (timestamp,open,high,low,close,volume).\n");
73 fmt::print("First line: header. Ctrl-D to finish.\n");
74
75 while (std::getline(std::cin, line)) {
76 // Trim carriage return for Windows-style line endings.
77 if (!line.empty() && line.back() == '\r') {
78 line.pop_back();
79 }
80
81 if (!header_skipped) {
82 if (!line.empty() && line[0] != '#') {
83 header_skipped = true;
84 }
85 continue;
86 }
87
88 // Parse this row as a standalone CSV string with a dummy header.
89 const std::string wrapped = "timestamp,open,high,low,close,volume\n" + line;
90 auto batch = srfm::core::DataLoader::parse_csv_string(wrapped);
91 if (batch.empty()) {
92 fmt::print(stderr, "Skipping malformed row: {}\n", line);
93 continue;
94 }
95
96 ++bar_count;
97 auto result = engine.process_stream_bar(batch[0]);
98 if (result) {
99 fmt::print(
100 "Bar {:4d}: close={:.4f} β={:.4f} γ={:.4f} interval={}\n",
101 bar_count,
102 result->raw.close,
103 result->beta.value,
104 result->gamma.value,
105 srfm::manifold::to_string(result->interval_type)
106 );
107 }
108 }
109
110 fmt::print("Processed {} bars.\n", bar_count);
111 return 0;
112}
113
114} // anonymous namespace
115
116int main(int argc, char* argv[]) {
117 if (argc < 2) {
118 print_usage();
119 return 1;
120 }
121
122 const std::string mode(argv[1]);
123
124 if (mode == "--help" || mode == "-h") {
125 print_usage();
126 return 0;
127 }
128
129 if (mode == "--backtest") {
130 if (argc < 3) {
131 fmt::print(stderr, "Error: --backtest requires a CSV file path\n");
132 print_usage();
133 return 1;
134 }
135 return run_backtest(std::string(argv[2]));
136 }
137
138 if (mode == "--stream") {
139 return run_stream();
140 }
141
142 fmt::print(stderr, "Unknown option: {}\n", mode);
143 print_usage();
144 return 1;
145}
static std::optional< std::vector< OHLCV > > load_csv(const std::string &filepath) noexcept
static std::vector< OHLCV > parse_csv_string(const std::string &csv_content) noexcept
Orchestrates the full relativistic signal-processing pipeline.
Definition engine.hpp:88
std::optional< PipelineBar > process_stream_bar(const OHLCV &bar) noexcept
Definition engine.cpp:84
std::optional< backtest::BacktestComparison > run_backtest(std::span< const OHLCV > bars) const noexcept
Definition engine.cpp:27
CSV data loader for OHLCV market data — AGT-06.
Core Integration Engine — AGT-06 public API.
int main(int argc, char *argv[])
Definition main.cpp:116
static constexpr std::size_t MIN_RETURN_SERIES_LENGTH
Definition constants.hpp:49
const char * to_string(IntervalType t) noexcept
Convert IntervalType to a human-readable string.