diff --git a/docs/index.html b/docs/index.html index 26fc3445..6258803b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -72,7 +72,7 @@
Sample captured locally using :timing
on in the REPL: 10M generated ticks. Timings vary by machine and
- run.
symbol_codes(rows);
+ for (std::size_t i = 0; i < rows; ++i) {
+ symbol_codes[i] = static_cast(symbol_idx[i]); // 0..names.size()-1
+ }
+ Column symbol_col(names, std::move(symbol_codes));
+
+ // Per-symbol mean-reverting walk. A pure additive walk's variance grows with
+ // the row count, so over the millions of rows this generator targets every
+ // symbol drifts arbitrarily far from its base and the levels reconverge into
+ // noise. The reversion term (pull toward `symbol_base`) keeps each series
+ // fluctuating around its own price.
+ constexpr double kReversion = 0.005;
+ std::vector symbol_price = symbol_base;
auto ts_ms = static_cast(base_ts_ms);
for (std::size_t i = 0; i < rows; ++i) {
ts_ms += gaps_ms[i];
ts_col.push_back(Timestamp{static_cast(ts_ms * 1'000'000.0)});
- symbol_col.push_back(names[static_cast(symbol_idx[i])]);
- price += price_steps[i];
+ const auto sym = static_cast(symbol_idx[i]);
+ double price = symbol_price[sym] + price_steps[i] +
+ kReversion * (symbol_base[sym] - symbol_price[sym]);
price = std::max(price, 0.01);
+ symbol_price[sym] = price;
price_col.push_back(price);
volume_col.push_back(volume[i]);
}
@@ -213,10 +237,13 @@ auto gen_reference(const std::string& symbols) -> runtime::Table {
}
}
- Column symbol_col;
- Column name_col;
- Column sector_col;
- Column currency_col;
+ // Dimension-table string columns are Categorical: `symbol` so its type
+ // matches `gen_ticks`'s join key, and the rest so that gathering them across
+ // a join to a large fact table copies dictionary codes rather than strings.
+ Column symbol_col;
+ Column name_col;
+ Column sector_col;
+ Column currency_col;
Column lot_size_col;
Column tick_size_col;
for (const auto& symbol : distinct) {
diff --git a/libs/data_gen/data_gen.hpp b/libs/data_gen/data_gen.hpp
index aa00b723..49f1559c 100644
--- a/libs/data_gen/data_gen.hpp
+++ b/libs/data_gen/data_gen.hpp
@@ -26,8 +26,11 @@
namespace ibex::data_gen {
-/// Synthetic tick data: timestamp, symbol, price (random walk per symbol),
-/// volume. `symbols` is a comma-separated list, e.g. "AAPL,MSFT,GOOG".
+/// Synthetic tick data: timestamp, symbol, price, volume. `symbols` is a
+/// comma-separated list, e.g. "AAPL,MSFT,GOOG". Each symbol has its own base
+/// price (spread around `start_price`) and its own mean-reverting random walk,
+/// so the series stay distinct even over millions of rows. `symbol` is a
+/// Categorical column.
/// Inter-arrival times are drawn from an Exponential distribution with mean
/// `interval_ms` (a Poisson process), not evenly spaced. `start_ts_ms` is the
/// first timestamp in Unix milliseconds (0 means "use current wall-clock time").