Skip to main content

Blazingly Fast Polars Quant Tool

Project description

polars_quant

polars_quant is a Rust-backed Python extension exposing a small set of real APIs implemented in this repository:

  • polars_quant.history(stock_code: str, scale: int = 240, datalen: int = 3650, timeout: int = 10)

    • Fetch historical OHLCV from the remote source. Returns a list of records (each having keys: day, open, close, high, low, volume) or None.
  • class polars_quant.Backtrade

    • Backtrade.run(data, entries, exits, init_cash=100000.0, fee=0.0, slip=0.0, size=1.0)
    • Backtrade.portfolio(data, entries, exits, init_cash=100000.0, fee=0.0, slip=0.0, size=1.0)
    • Instance attributes/methods: results, trades, summary(), speed

Quick usage examples

  1. Fetch history
import polars as pl
import polars_quant

items = polars_quant.history("sh600519", scale=240, datalen=365, timeout=10)
if items is None:
    print("No data")
else:
    df = pl.DataFrame(items)
    print(df.head())
  1. Backtest (single symbol)
import polars as pl
import polars_quant as plqt

data = pl.DataFrame({
    "date": ["2024-01-01","2024-01-02","2024-01-03"],
    "SYM": [100.0, 101.5, 99.0],
})
entries = pl.DataFrame({"date": data["date"], "SYM": [False, True, False]})
exits = pl.DataFrame({"date": data["date"], "SYM": [False, False, True]})

bt = plqt.Backtrade.run(data, entries, exits, init_cash=100000.0, fee=0.0005)
print(bt.summary())
if getattr(bt, "results", None) is not None:
    print(bt.results.head())

Notes

  • Keep data, entries, exits aligned: column 0 = date, columns 1..N = symbols (one column per symbol).
  • entries/exits columns accept booleans or integers as flags.
  • GitHub repository README is static; no automatic locale switching. Use this pattern to maintain parallel language files.

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

polars_quant-0.2.0.tar.gz (222.8 kB view details)

Uploaded Source

Built Distribution

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

polars_quant-0.2.0-cp39-abi3-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

File details

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

File metadata

  • Download URL: polars_quant-0.2.0.tar.gz
  • Upload date:
  • Size: 222.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.3

File hashes

Hashes for polars_quant-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4056079ed196ff684851ab9838e4586b4027c73340614a1b1f468e85d8daa1dd
MD5 3eeee3e44d75c6426e494ae32be07622
BLAKE2b-256 b62ff379392d6341ff40542611040e47091ebee8f62edbb59291b999e15e3f36

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_quant-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b15a4dc13e52bc15fcf5fbe78de34430a83f5528ef0fec5351d8f0e79fe89111
MD5 4ca655c70fb4e0959f11d6c5cd634624
BLAKE2b-256 c368e99166e2d2ec3eaef7f36a5f87aa99605a083b883047ae523a8dd6a9ce62

See more details on using hashes here.

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