Skip to main content

Jiuhuang quant python sdk

Project description

JH_QUANT

banner 量化交易研究与执行平台。支持:免费数据获取回测因子计算模拟交易组合优化可视化仪表盘

模块

模块 说明 文档
data 多种数据获取,兼容akshare和tushare数据类型及调用风格 README
trading 交易运行层,模拟(实时)交易与会话编排 README
backtest 回测引擎,快速策略验证,多种内置策略 README
factors 因子计算,内置多种因子模型 README
dashboard PyWebView可视化仪表盘 README

快速开始

安装

pip install jh_quant

数据获取

import os
from jh_quant.data import JHData, DataTypes

jh = JHData(apt_key=os.getenv("JIUHUANG_API_KEY"))
stock_price = jh.get_data(
    DataTypes.AK_STOCK_ZH_A_HIST_QFQ,  #akshare日线前复权数据
    symbol="000001",
    start="2025-01-01",
    end="2025-12-10",
)

重要

jh_quant 仅做了对 akshare 数据类型的兼容,数据真实来源为:JiuHuang API

策略回测

from jh_quant.data import JHData, DataTypes
from jh_quant.backtest import (
    backtest,
    StrategyTurtle,
    StrategyMovingAverageCrossover,
    StrategyBuyAndHold,
)
from jh_quant.dashboard import display_backtesting
# 1. 准备数据
jh = JHData()
stock_price = jh.get_data(
    DataTypes.AK_STOCK_ZH_A_HIST_QFQ,
    symbol="000001,600519,300750",
    start="2025-01-01",
    end="2026-05-07",
)
stock_info = jh.get_data(DataTypes.AK_STOCK_INDIVIDUAL_INFO_EM)

# 2. 定义策略
strategies = {
    "海龟策略": StrategyTurtle(entry_window=20, exit_window=10),
    "均线交叉": StrategyMovingAverageCrossover(short_window=12, long_window=24),
    "买入持有": StrategyBuyAndHold(),
}

# 3. 执行回测
trading_hist, backtest_perf = backtest(
    strategies=strategies,
    price_data=stock_price,
    stock_info=stock_info,
)

display_backtesting( trading_hist, backtest_perf)

回测仪表盘预览

策略对比 策略分布
策略对比 策略分布
交易历史 策略排名
交易历史 策略排名

实时模拟交易

jh_quant支持同时开启多个模拟交易会话,每个会话对应一个模拟账户, 下面是示例运行:

python run_paper.py

run_paper.py的完整代码参考本repo根目录的run_paper.py

在回填模式下(可以通过enable_backfill=False关闭),会完成历史交易模拟,并在本地开启服务

开启控制台仪表盘 开启本地服务之后, 可以通过如下代码开启控制台仪表盘

from jh_quant.dashboard import display_trading

display_trading()

dashboard

License

This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.

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

jh_quant-0.1.4.tar.gz (7.6 MB view details)

Uploaded Source

Built Distribution

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

jh_quant-0.1.4-py3-none-any.whl (2.6 MB view details)

Uploaded Python 3

File details

Details for the file jh_quant-0.1.4.tar.gz.

File metadata

  • Download URL: jh_quant-0.1.4.tar.gz
  • Upload date:
  • Size: 7.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.26

File hashes

Hashes for jh_quant-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ab6db6cee60b170fece8da0154e3062e346bf4d0cce22754106fb9bd22fdc024
MD5 6633d14a64c22529378af8eeaaea3fe7
BLAKE2b-256 1799a97160e62d275a7440f109f19c4d9ca4df17ac48175da2839a8876dd3d7a

See more details on using hashes here.

File details

Details for the file jh_quant-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: jh_quant-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.26

File hashes

Hashes for jh_quant-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fd29c5f6b96292a523e51b0ffd647c1263a43212d7bc79054c8cd35b233c3a79
MD5 309f7d98d6df29ccb5fd0eb7c7113038
BLAKE2b-256 5ea46367f8a699e7a7f107c6cce4cba4d96b52e0a57303934658701000cb7670

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