Skip to main content

Jiuhuang python sdk

Project description

banner

jiuhuang-pysdk

jiuhuang(韭皇)是一个免费,高性能,简洁易用的金融数据获取和回测框架。

亮点

  • 丰富的数据源:兼容akshare多种数据类型,支持获取A股、基金、宏观等数据
  • 统一的数据接口:通过 DataTypes 枚举类统一管理数据类型,输出字段名标准化为英文字段名
  • 多时间颗粒度支持:支持日、周、月级别数据,以及分钟级实时数据
  • 智能数据搜索:内置中文语义搜索功能,快速找到所需数据类型
  • 多进程并行回测:内置多进程并行计算,回测速度极快
  • 内置多种策略:提供海龟交易、均线交叉、RSI、布林带、动量等 11+ 种经典策略
  • 可视化回测仪表盘:交互式图表展示回测结果,支持交易历史、策略分布、排名对比等
  • 易于扩展:支持自定义策略
  • MCP Server 支持:可作为 MCP 服务器运行,AI Agent 可通过标准协议调用
  • Claude Code Skill 集成:提供 Skill 配置,Claude Code 可直接使用

快速开始

安装

uv安装(推荐)

uv add jiuhuang-pysdk
# 或者uv pip install -U jiuhuang-pysdk

pip安装

pip install -U jiuhuang-pysdk

回测示例

from jiuhuang.data import JiuhuangData, DataTypes
from jiuhuang.strategy import *
from jiuhuang.backtest import backtest
from jiuhuang.dash import display_backtesting
import warnings

warnings.filterwarnings("ignore")

# 方式一:使用环境变量(推荐)
# 设置 API_URL 和 API_KEY 环境变量
# API_KEY申请地址:https://jiuhuang.xyz
jh = JiuhuangData()  
# 方式二:直接传入参数
jh = JiuhuangData(api_url="https://data.jiuhuang.xyz", api_key="你的API KEY")


# 定义策略(可使用内置策略或自定义策略)
strategies = {
    "海龟": StrategyTurtle(entry_window=20, exit_window=10),
    "移动均线交叉": StrategyMovingAverageCrossover(12, 24),
    "买入持有": StrategyBuyAndHold(),
}

# 获取数据
symbols = ["000001", "600036", "600519", "000858", "601318", "000002"]
stock_price = jh.get_data(
    DataTypes.STOCK_ZH_A_HIST_QFQ,
    start="2024-12-25",
    end="2026-03-11",
    symbol=",".join(symbols),
)
stock_info = jh.get_data(DataTypes.STOCK_INDIVIDUAL_INFO_EM)

# 执行回测
trading_history, backtest_perf = backtest(
    strategies,
    stock_price,
    stock_info,
)

# 展示回测仪表盘
display_backtesting(trading_history, backtest_perf)

回测仪表盘预览

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

License

This project is licensed under the BSD 3-Clause 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

jiuhuang_pysdk-0.1.2.tar.gz (798.0 kB view details)

Uploaded Source

Built Distribution

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

jiuhuang_pysdk-0.1.2-py3-none-any.whl (800.2 kB view details)

Uploaded Python 3

File details

Details for the file jiuhuang_pysdk-0.1.2.tar.gz.

File metadata

  • Download URL: jiuhuang_pysdk-0.1.2.tar.gz
  • Upload date:
  • Size: 798.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for jiuhuang_pysdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 53f1786c9acdfc13c8824f50b91264a0c1a57ec9364635a6bb3f065a6e381d19
MD5 173694551af693d15d7005fa5fc37ffb
BLAKE2b-256 d89e8bea1f52e0e407ce17974cee11f21d22ae6dbc6009b48d4269f4f4165b92

See more details on using hashes here.

File details

Details for the file jiuhuang_pysdk-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for jiuhuang_pysdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b0d3210880d25b162d6e256c6f2931fa5cfd0885b966303ced58aba0fbf0634
MD5 5963c062cffc3c536262076174c6767b
BLAKE2b-256 a2c605fc3f3f53f06da42f2316092c2d99387487ffd6b3cf11ce711c5f74ef52

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