adapters
Concept Overview
Section titled “Concept Overview”The Rust core returns results as plain dicts and lists. The adapters module converts these into typed Polars DataFrames with proper datetime parsing, column naming, and validation. This is the standard way to move data between the Rust computation engine and Python analysis/visualization code.
SignalStreamBuffer provides an incremental append interface for streaming workflows where signals arrive in chunks — common in live research notebooks or paper-trading loops.
When to Use
Section titled “When to Use”Use adapters whenever you receive output from the Rust core or pipeline module and need DataFrames for analysis, visualization, or further processing. The pipeline module’s _frames variant calls these adapters internally.
Alternatives: Manual Polars DataFrame construction from dicts, but you lose validation and timestamp parsing.
Usage Examples
Section titled “Usage Examples”Python
Section titled “Python”Convert pipeline outputs to typed DataFrames
Section titled “Convert pipeline outputs to typed DataFrames”from openquant.adapters import ( to_polars_signal_frame, to_polars_weights_frame, SignalStreamBuffer,)
# Signal frame from raw timestamps + valuessignals = to_polars_signal_frame( timestamps=["2024-01-02T09:30:00", "2024-01-02T09:31:00"], signal=[0.5, -0.3], side=[1.0, -1.0], symbol="CL",)
# Streaming buffer for incremental signal updatesbuf = SignalStreamBuffer()buf.append(timestamps=["2024-01-02T09:32:00"], signal=[0.1])buf.append(timestamps=["2024-01-02T09:33:00"], signal=[-0.2])all_signals = buf.frame() # concat into single DataFrameAPI Reference
Section titled “API Reference”Python API
Section titled “Python API”adapters.to_polars_signal_frameadapters.to_polars_event_frameadapters.to_polars_backtest_frameadapters.to_polars_weights_frameadapters.to_polars_indicator_matrixadapters.to_polars_frontier_frameadapters.SignalStreamBufferadapters.to_pandas
Key Functions
Section titled “Key Functions”to_polars_signal_frameto_polars_event_frameto_polars_backtest_frameto_polars_weights_frameSignalStreamBuffer
Implementation Notes
Section titled “Implementation Notes”- All adapter functions validate input length alignment before constructing frames.
- SignalStreamBuffer supports incremental append for streaming research notebooks.
- to_pandas() is available for downstream tools that require pandas; requires pandas to be installed.