Skip to main content

Python bindings for the yuzu backtest engine and the lemon strategy DSL.

Project description

yuzu — Python bindings

Python bindings for the citrusinvest backtest engine: the yuzu backtest core plus the lemon strategy DSL, compiled from Rust. The engine boundary is pure data — (strategy, panels, config) → report — so the bindings are thin and fast.

import yuzu

report = yuzu.run_backtest(
    "close > sma(close, 20)",          # lemon source (or a JSON Expr dict/string)
    panels={
        "close": df_close,             # DataFrame (dates × symbols), or a
                                       # {"dates": [...], "symbols": [...], "data": [[...]]} dict
    },
    config={"fee_ratio": 0.001, "benchmark_key": "spy"},
)
report["equity"]                        # NAV curve, base 1.0
report["metrics"]["sharpe"]             # headline metrics
report["monthly_returns"]               # calendar tables, trades, bootstrap bands, ...

The report is the same JSON contract the engine's WASM and server boundaries emit — see docs/backtest-engine.md in the repository for the full schema and the BacktestConfig knobs (fees, slippage, square-root market impact, liquidity cap, delisting handling, benchmark comparison, bootstrap bands).

DSL tooling is included:

yuzu.parse("close > sma(close, 20)")   # -> Expr tree as a dict
yuzu.format(tree)                       # -> canonical lemon source
yuzu.lint("clsoe > 1", ["close", "pe"]) # -> [{"line": 1, "col": 1, "message": "unknown series `clsoe` — did you mean `close`?"}]

Panels

A panel is a dense dates × symbols matrix of floats (None/NaN = missing):

  • DataFrame (pandas/polars duck-type): index = dates (int YYYYMMDD, strings, or anything with strftime), columns = symbols.
  • dict: {"dates": [20240102, ...], "symbols": ["AAPL", ...], "data": [[...], ...]}.

Series names are the engine's (close, high, low, volume, pe, …); a volume panel is required for the liquidity cap / market-impact features, and high/low enable per-trade MAE/MFE.

Install

pip install yuzu-backtest          # from PyPI (distribution name), imports as `yuzu`

Build from source

pip install maturin
pip install ./crates/yuzu-py       # or: maturin develop -m crates/yuzu-py/Cargo.toml

Wheels are abi3 (Python ≥ 3.9). License: MIT.

Versioning: major.minor mirrors the engine workspace version (a 0.2.x wheel is built from the 0.2 engine series); the patch segment is the bindings' own, so binding-only fixes can ship without an engine release. Each wheel is a snapshot of the whole repository at its release tag.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yuzu_backtest-0.2.0.tar.gz (101.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

yuzu_backtest-0.2.0-cp39-abi3-win_amd64.whl (593.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

yuzu_backtest-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (703.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

yuzu_backtest-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (674.4 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

yuzu_backtest-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (620.9 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

yuzu_backtest-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (658.8 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file yuzu_backtest-0.2.0.tar.gz.

File metadata

  • Download URL: yuzu_backtest-0.2.0.tar.gz
  • Upload date:
  • Size: 101.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for yuzu_backtest-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0452a7dc27cb7723bdd3ce752652293a0203e3d28d86e64e9ca2ac52f605822f
MD5 96ac02731bb6e1111d5382d1908c754a
BLAKE2b-256 d81030eeafd30070fed20fedf2c69b0f50fcffd81fa6e5571b953fa964003a0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for yuzu_backtest-0.2.0.tar.gz:

Publisher: release-python.yml on imgarylai/citrusinvest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yuzu_backtest-0.2.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: yuzu_backtest-0.2.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 593.6 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for yuzu_backtest-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 773155529ec9e795cc702c63399335ed2c819dee9648bdc8b5160440a9075bf9
MD5 f1beac3418ba380959fca4fc89aa0973
BLAKE2b-256 48f0637f4bc50d9cb07a59e6f4023118fafd92e23e3a948d680d89773359ad09

See more details on using hashes here.

Provenance

The following attestation bundles were made for yuzu_backtest-0.2.0-cp39-abi3-win_amd64.whl:

Publisher: release-python.yml on imgarylai/citrusinvest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yuzu_backtest-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for yuzu_backtest-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 590fcb5a3af2e788a62c821f014b57287d56c6732048d9aa335f96f6f8868bad
MD5 f0bae22e62e3756cb2857356428cbde2
BLAKE2b-256 e73ce6ce8ac4c480c7ffec0166a23df09ddff50934ea8c8b57dae4b408f3568c

See more details on using hashes here.

Provenance

The following attestation bundles were made for yuzu_backtest-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on imgarylai/citrusinvest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yuzu_backtest-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for yuzu_backtest-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ad7f70ff894e542a2140fcceb0a07c89469054675231e5c44bef58f6e3656407
MD5 27c11e55b8808cd5442a995dc0c42a15
BLAKE2b-256 8fcd777fa1cbcef2aea19418a5391c387288d96b35dd4aaa0cdc02a641f1bd4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for yuzu_backtest-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-python.yml on imgarylai/citrusinvest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yuzu_backtest-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for yuzu_backtest-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7aca2d9ec9e48bf24ce516cf12f3f3722f44a165ade27638200b7e334771bf9c
MD5 fde4025b60329ce390eee8ffcb43e138
BLAKE2b-256 90004e1c57a27a554d05c78206e9d10e658b4e63e25870c97ca3164483a953f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for yuzu_backtest-0.2.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on imgarylai/citrusinvest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yuzu_backtest-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for yuzu_backtest-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 11780643c22256e66fd853794acb6673134a476c353f7fbfd82f6e145ed136ea
MD5 6af4f5fa633fff9893c3b41f1e7cb947
BLAKE2b-256 afb2e19d7ec9539c77ceb585cfee4a94ce9bb9b2802f4015cbfca4104925b7dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for yuzu_backtest-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on imgarylai/citrusinvest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page