Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Avhz RustQuant Python Bindings

From Leeroopedia


Knowledge Sources
Domains Python_Integration, Quantitative_Finance
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete tool for exposing RustQuant functionality to Python via PyO3 bindings provided by the RustQuant library.

Description

The bindings module uses the PyO3 framework to expose RustQuant's Rust-native functionality as a Python package. A top-level #[pymodule] function named RustQuant registers three sub-modules using helper functions: register_data_module exposes the data sub-module containing Curve, CurveType, and InterpolationMethod classes; register_instruments_module creates the instruments sub-module (currently a stub with no classes registered); register_time_module exposes the time sub-module containing Calendar and Market classes. Each registration function creates a PyModule, adds the relevant Rust types as Python classes via add_class::<T>(), registers the module as a sub-module of the parent, and inserts it into Python's sys.modules dictionary for proper import resolution (e.g., import RustQuant.data works in Python).

Usage

Use these bindings when you want to leverage RustQuant's high-performance Rust implementations from Python code, particularly for curve operations (Curve, CurveType, InterpolationMethod), calendar computations (Calendar, Market), and future instrument functionality.

Code Reference

Source Location

Signature

#[pymodule]
fn RustQuant(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()>;

fn register_data_module(py: Python, parent_module: &Bound<'_, PyModule>) -> PyResult<()>;
fn register_instruments_module(py: Python, parent_module: &Bound<'_, PyModule>) -> PyResult<()>;
fn register_time_module(py: Python, parent_module: &Bound<'_, PyModule>) -> PyResult<()>;

Import

// From Python:
// import RustQuant
// from RustQuant.data import Curve, CurveType, InterpolationMethod
// from RustQuant.time import Calendar, Market

I/O Contract

Inputs

Name Type Required Description
py Python Yes PyO3 Python GIL token (provided by the runtime)
m &Bound<'_, PyModule> Yes Parent module reference for sub-module registration

Outputs

Name Type Description
PyResult<()> Result Ok(()) on successful module registration, or PyErr on failure
RustQuant.data Python module Exposes Curve, CurveType, InterpolationMethod
RustQuant.instruments Python module Stub module for future instrument classes
RustQuant.time Python module Exposes Calendar and Market

Usage Examples

// Python usage example:
//
// import RustQuant
// from RustQuant.data import Curve, CurveType, InterpolationMethod
// from RustQuant.time import Calendar, Market
//
// # Create a curve
// curve = Curve(...)
//
// # Access calendar functionality
// calendar = Calendar(...)
// market = Market(...)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment