shape_runtime/simulation/mod.rs
1//! Generic Simulation Engine
2//!
3//! This module provides a domain-agnostic simulation engine that can be used
4//! for any kind of event-driven processing over time series data.
5//!
6//! The engine is designed to be:
7//! - Domain-agnostic: No knowledge of finance, IoT, or any specific domain
8//! - Composable: Can be wrapped by domain-specific engines
9//! - Efficient: Supports batch and streaming modes
10//!
11//! Finance-specific features like position tracking, fill simulation, and
12//! P&L calculation should be implemented in Shape stdlib, not here.
13//!
14//! # High-Performance Mode (TypedObject)
15//!
16//! For maximum performance (>10M ticks/sec), simulation state should be a
17//! TypedObject - a fixed-layout object created from a type declaration.
18//! Use `require_typed_state()` to enforce this at runtime.
19//!
20//! ```shape
21//! type BacktestState {
22//! cash: f64,
23//! position: f64,
24//! entry_price: f64
25//! }
26//!
27//! let state = BacktestState { cash: 100000.0, position: 0.0, entry_price: 0.0 }
28//! simulate(data, state, strategy) // state will use TypedObject optimization
29//! ```
30
31// Module declarations
32pub mod correlated_kernel;
33pub mod dense_kernel;
34pub mod engine;
35pub mod event_scheduler;
36pub mod hybrid_kernel;
37pub mod parallel;
38pub mod validation;
39
40// Re-export all public types for backward compatibility
41pub use validation::{require_typed_state_with_schema, validate_typed_state};
42
43pub use engine::{
44 SimulationEngine, SimulationEngineConfig, SimulationEngineResult, SimulationEvent,
45 SimulationMode, StepHandler, StepResult,
46};
47
48pub use dense_kernel::{
49 DenseKernel, DenseKernelConfig, DenseKernelResult, KernelCompileConfig, KernelCompiler,
50 SimulationKernelFn, simulate,
51};
52
53pub use correlated_kernel::{
54 CorrelatedKernel, CorrelatedKernelConfig, CorrelatedKernelFn, CorrelatedKernelResult,
55 TableSchema, simulate_correlated,
56};
57
58pub use event_scheduler::{EventQueue, ScheduledEvent};
59
60pub use hybrid_kernel::{
61 EventHandlerFn, HybridKernel, HybridKernelConfig, HybridKernelResult, simulate_hybrid,
62};
63
64pub use parallel::{ParallelSweepResult, par_run, par_run_with_config, param_grid, param_grid3};