Skip to content
GeneratedGenerated from the built extension by scripts/generate_python_api_reference.py; CI fails if it is stale.

openquant.pipeline

Pure Python. Signatures are as written in the source; descriptions are the docstrings. All Python modules.

Functions

infer_periods_per_year

infer_periods_per_year(timestamps: Sequence[str]) -> float | None

Bars a year implied by the spacing of timestamps.

Thin wrapper over openquant._core.pipeline.infer_periods_per_year: the median gap between consecutive strictly increasing timestamps is mapped with the convention of 252 sessions of 390 minutes a year. Intraday gaps give 252 * 390 / gap_minutes (one-minute bars: 98,280); gaps from 20 hours to under 4 days give 252 (daily bars); longer gaps give 365.25 / gap_days.

Parameters

timestamps : Sequence[str]

Bar timestamps as "%Y-%m-%d %H:%M:%S" strings, oldest first.

Returns

float or None

Bars a year, or None when fewer than two timestamps strictly increase.

run_mid_frequency_pipeline

run_mid_frequency_pipeline(
    timestamps: Sequence[str],
    close: Sequence[float],
    model_probabilities: Sequence[float],
    asset_prices: Sequence[Sequence[float]],
    model_sides: Sequence[float] | None = None,
    asset_names: Sequence[str] | None = None,
    cusum_threshold: float = 0.001,
    num_classes: int = 2,
    step_size: float = 0.1,
    risk_free_rate: float = 0.0,
    confidence_level: float = 0.05,
    periods_per_year: float | None = None,
) -> dict[str, Any]

Run an end-to-end AFML-style research pipeline.

Returns nested dictionaries with stage outputs: events, signals, portfolio, risk, backtest, leakage_checks.

risk_free_rate is an annual rate for both the portfolio stage and realized_sharpe. periods_per_year is the number of bars a year of close and of the rows of asset_prices; it annualises realized_sharpe and the portfolio's return, risk and Sharpe ratio. With the default None it is derived from the spacing of timestamps by infer_periods_per_year (252 for daily bars, 98,280 = 252 * 390 for one-minute bars on a 6.5-hour session; 252 when there is no gap to measure). Pass a number to override it, e.g. for bars that trade around the clock. The value used is returned as out["risk"]["periods_per_year"].

Unlike this wrapper, openquant._core.pipeline.run_mid_frequency_pipeline (and the Rust ResearchPipelineConfig) default to 252 whatever the bar spacing.

leakage_checks["timestamps_increasing"] and ["event_indices_sorted"] are computed from the data. ["inputs_aligned"] (always True) and ["has_forward_look_bias"] (always False) are deprecated constants: mismatched lengths raise instead, and the pipeline does not detect look-ahead in model_probabilities.

run_mid_frequency_pipeline_frames

run_mid_frequency_pipeline_frames(
    timestamps: Sequence[str],
    close: Sequence[float],
    model_probabilities: Sequence[float],
    asset_prices: Sequence[Sequence[float]],
    model_sides: Sequence[float] | None = None,
    asset_names: Sequence[str] | None = None,
    cusum_threshold: float = 0.001,
    num_classes: int = 2,
    step_size: float = 0.1,
    risk_free_rate: float = 0.0,
    confidence_level: float = 0.05,
    periods_per_year: float | None = None,
) -> dict[str, Any]

Run the pipeline and enrich output with polars DataFrames.

Takes the same parameters as run_mid_frequency_pipeline, including the default periods_per_year=None that derives the annualisation factor from timestamps.

summarize_pipeline

summarize_pipeline(out: dict[str, Any]) -> pl.DataFrame

Tabular summary for quick notebook inspection.