22 "HawkingTemp T_H={:+.4f} z={:+.4f} Δz={:+.4f} "
23 "μ={:.2f} σ={:.4f} horizon={}",
43 "HawkingSignal dir={} strength={:.4f} action={:+d} | {}",
54 if (window.size() == max_size) {
56 const double oldest = window.front();
58 sum_sq -= oldest * oldest;
59 window.erase(window.begin());
61 window.push_back(price);
63 sum_sq += price * price;
67 if (
window.empty())
return 0.0;
68 return sum /
static_cast<double>(
window.size());
72 const std::size_t n =
window.size();
73 if (n < 2)
return 0.0;
74 const double n_d =
static_cast<double>(n);
75 const double m =
sum / n_d;
76 const double var = (
sum_sq / n_d) - (m * m);
77 return (var > 0.0) ? std::sqrt(var) : 0.0;
85 state_.max_size = config.bb_window;
95std::optional<HawkingTemperature>
97 if (!std::isfinite(close))
return std::nullopt;
102 if (!state_.full())
return std::nullopt;
104 const double mu = state_.mean();
105 const double sigma = state_.stddev();
108 if (sigma < 1e-12)
return std::nullopt;
110 const double z = (close - mu) / sigma;
111 const double delta_z = has_prev_z_ ? (z - prev_z_) : 0.0;
118 const double temperature = z * delta_z;
147HawkingDirection HawkingSignalGenerator::classify(
double temperature)
const noexcept {
153double HawkingSignalGenerator::strength(
double temperature)
noexcept {
156 const double abs_t = std::fabs(temperature);
157 return abs_t / (abs_t + 1.0);
160int HawkingSignalGenerator::direction_to_action(
HawkingDirection d)
noexcept {
176std::optional<HawkingSignal>
178 auto temp = horizon_.update(close);
179 if (!temp.has_value())
return std::nullopt;
182 const double str = strength(temp->temperature);
183 const int action = direction_to_action(dir);
188 int final_action = action;
190 final_action = (temp->z_score > 0.0) ? -1 : +1;
193 final_action = (temp->z_score > 0.0) ? +1 : -1;
200 .action = final_action,
209 "HawkingSharpe={:.4f} TimelikeSharpe={:.4f} "
210 "SharpeImprovement={:+.4f} | "
211 "MeanTemp={:.4f} Coverage={:.1%}",
226 : signal_gen_(hawking_cfg)
227 , engine_(engine_cfg)
228 , hawking_cfg_(hawking_cfg)
231std::optional<HawkingBacktestResult>
233 const std::size_t N = bars.size();
234 const std::size_t min_req = hawking_cfg_.bb_window + 30;
235 if (N < min_req)
return std::nullopt;
238 std::vector<core::PipelineBar> pipeline_bars;
239 pipeline_bars.reserve(N);
242 for (
const auto& bar : bars) {
244 if (pb) pipeline_bars.push_back(*pb);
248 if (pipeline_bars.size() < min_req)
return std::nullopt;
249 const std::size_t M = pipeline_bars.size();
252 std::vector<double> returns;
254 for (
const auto& pb : pipeline_bars) returns.push_back(pb.price_return);
260 std::vector<backtest::BarData> hawking_data;
261 std::vector<backtest::BarData> timelike_data;
262 hawking_data.reserve(M);
263 timelike_data.reserve(M);
265 double total_temperature = 0.0;
266 std::size_t non_neutral = 0;
267 const std::size_t offset = bars.size() - M;
269 for (std::size_t i = 0; i < M; ++i) {
270 const auto& pb = pipeline_bars[i];
271 const double close = bars[offset + i].close;
274 auto sig = local_gen.
update(close);
275 double h_signal = sig ?
static_cast<double>(sig->action) : 0.0;
277 total_temperature += std::fabs(sig->temperature.temperature);
284 hawking_data.push_back({
285 .raw_signal = h_signal,
287 .benchmark = pb.price_return,
289 timelike_data.push_back({
290 .raw_signal = t_signal,
292 .benchmark = pb.price_return,
298 auto hawking_result = bt.
run(hawking_data, returns);
299 auto timelike_result = bt.
run(timelike_data, returns);
301 if (!hawking_result || !timelike_result)
return std::nullopt;
307 ? (total_temperature /
static_cast<double>(non_neutral))
310 /
static_cast<double>(M);
std::optional< BacktestComparison > run(std::span< const BarData > bars, std::span< const double > asset_returns) const noexcept
Orchestrates the full relativistic signal-processing pipeline.
std::optional< PipelineBar > process_stream_bar(const OHLCV &bar) noexcept
HawkingBacktest(PriceEventHorizon::Config hawking_cfg=PriceEventHorizon::Config{}, core::EngineConfig engine_cfg=core::EngineConfig{}) noexcept
std::optional< HawkingBacktestResult > run(std::span< const core::OHLCV > bars) const noexcept
void reset() noexcept
Reset internal state.
HawkingSignalGenerator(PriceEventHorizon::Config config=PriceEventHorizon::Config{}) noexcept
std::optional< HawkingSignal > update(double close) noexcept
void reset() noexcept
Reset the internal rolling state (e.g. at session boundaries).
std::optional< HawkingTemperature > update(double close) noexcept
PriceEventHorizon(Config config=Config{}) noexcept
Physical and financial constants for the SRFM system.
Hawking Radiation Analogy — event-horizon detection for price series.
const char * to_string(HawkingDirection d) noexcept
Return a human-readable string for a HawkingDirection value.
HawkingDirection
Trading signal derived from Hawking temperature.
@ Reversal
T_H high → trend exhaustion → fade the move.
@ Neutral
Temperature in the normal range → no signal.
@ Continuation
T_H low → healthy trend → follow the trend.
@ Timelike
ds² < 0 — causal market movement (β < c)
Configuration parameters for the core engine.
Internal rolling state for Bollinger Band computation.
std::vector< double > window
Rolling price window (oldest first).
double stddev() const noexcept
Return the rolling standard deviation (population σ).
double sum
Running sum for fast mean.
double sum_sq
Running sum of squares for fast σ.
void push(double price) noexcept
Push a new price and pop the oldest if window is full.
double mean() const noexcept
Return the rolling mean (NaN-safe).
Comparison of Hawking-signal strategy vs the existing TIMELIKE classifier.
backtest::PerformanceMetrics hawking_metrics
Performance of the Hawking temperature signal strategy.
double sharpe_improvement() const noexcept
Improvement in Sharpe: hawking − timelike.
std::string to_string() const
Format a one-line human-readable summary.
double signal_coverage
Fraction of bars where the Hawking signal was non-neutral.
double mean_temperature
Mean |T_H| across all bars with a non-neutral signal.
backtest::PerformanceMetrics timelike_metrics
Performance of the TIMELIKE (standard relativistic) strategy.
A single bar's Hawking-derived trading signal.
std::string to_string() const
Format a compact one-liner for logging.
int action
+1 (buy), -1 (sell), 0 (neutral).
HawkingDirection direction
Trading implication.
HawkingTemperature temperature
Full temperature measurement.
double strength
|T_H| normalized to [0, 1].
double delta_z
Change in z-score from previous bar.
double temperature
T_H = z × Δz.
double bollinger_std
Rolling σ
double bollinger_mean
Rolling μ
std::string to_string() const
Format a compact one-liner for logging.
bool near_horizon
|z_score| ≥ bb_sigma
double z_score
(P − μ) / σ
Configuration for the Bollinger Band event horizon detector.
std::size_t bb_window
Rolling window size for Bollinger Band mean and std dev.