Skip to main content

Blazingly Fast Polars Quant Tool

Project description

polars_quant

Choose your language / 选择语言:

🌐 Languages: English | 简体中文

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
from polars_quant import Backtrade

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 = 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.1.1.tar.gz (211.4 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.1.1-cp39-abi3-win_amd64.whl (5.1 MB view details)

Uploaded CPython 3.9+Windows x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_quant-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0ee52e9083801771181a2e97e7b7588f5046a4b99ecaddf798cfc793ab6340d4
MD5 537a72bb553b4a8b24ee0daac4f872e8
BLAKE2b-256 4eca215b2b8fa7291c724b0f98fd810efd602dc81aaeab56c12f734d40bce75c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_quant-0.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c7bf25770ed648ef23b563c60b58189b14ee844b2c11dcd05fabe42485b296cd
MD5 2407c0c6be6fe8dec906a1cf990f1926
BLAKE2b-256 1bd35161e837fb9a1c483e63f49ee0adbd687343a11828c8409f4de509b79328

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