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.3.tar.gz (799.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.3-py3-none-any.whl (801.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jiuhuang_pysdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 178b637e90fdb0b7df4c455a201a1a0ed514ae807efa8e2d60038639ff2c43d9
MD5 cf45176712c59358c4c17a12a4669207
BLAKE2b-256 b2624313bcbbec1df2ca9601f3cd6e0f503a23d21b3460c5befb02a85ebb1242

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jiuhuang_pysdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dc2da8953d99aec268acd93cf32d426ae8164a74d85c1d5dfd742c5065b4b45d
MD5 9536afef1acbb71ece7671b0a7ba9cca
BLAKE2b-256 9b3175a11acea712ed458a9d23b8a4058dd1f1629e7264c0ca4f945b38f4a11d

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