Skip to main content

run_streaming_pipeline

Function run_streaming_pipeline 

Source
pub fn run_streaming_pipeline(
    events: &[StreamEvent],
    cfg: StreamingPipelineConfig,
) -> Result<StreamingRunReport, StreamingHpcError>
Expand description

Runs a fresh StreamingEarlyWarningEngine over events in order, timing each call.

use openquant::streaming_hpc::{
    generate_synthetic_flash_crash_stream, run_streaming_pipeline, AlertThresholds, HhiConfig,
    StreamingPipelineConfig, SyntheticStreamConfig, VpinConfig,
};

// The docs-site example: a crash at event 700 of 1,000.
let events = generate_synthetic_flash_crash_stream(SyntheticStreamConfig {
    events: 1_000,
    crash_start_fraction: 0.7,
    calm_venues: 4,
    shock_venue: 0,
})?;
let cfg = StreamingPipelineConfig {
    vpin: VpinConfig { bucket_volume: 1_000.0, support_buckets: 10, cdf_lookback: 100 },
    hhi: HhiConfig { lookback_events: 50 },
    thresholds: AlertThresholds { vpin_cdf: 0.99, hhi: 0.5 },
};
let report = run_streaming_pipeline(&events, cfg)?;
assert_eq!(report.metrics.processed_events, 1_000);
// Calm flow: VPIN |120 - 130| / 250 = 0.04 in every bucket.
let calm = report.snapshots[699];
assert!((calm.vpin.unwrap() - 0.04).abs() < 1e-9);
assert_eq!(calm.vpin_cdf, Some(0.5)); // a steady stream ties with itself
// 50 events over four venues split 13/13/12/12, so HHI is 626 / 2500, not exactly 1/4.
assert!((calm.hhi.unwrap() - 0.2504).abs() < 1e-9);
// The alert fires from event 723 to 728, then the CDF decays on the VPIN plateau.
let alerts: Vec<usize> = (0..1_000).filter(|&i| report.snapshots[i].is_alert).collect();
assert_eq!(alerts, (723..=728).collect::<Vec<_>>());
assert_eq!(report.alert_count, 6);

ยงErrors

As for StreamingEarlyWarningEngine::new and StreamingEarlyWarningEngine::on_event; the run stops at the first invalid event and returns no partial report.