Skip to content

feat: add akshare data loader for zero-auth A-share OHLCV panel - #42

Merged
initial-d merged 2 commits into
initial-d:mainfrom
redamancy231-create:feat-akshare-loader
Jul 28, 2026
Merged

feat: add akshare data loader for zero-auth A-share OHLCV panel#42
initial-d merged 2 commits into
initial-d:mainfrom
redamancy231-create:feat-akshare-loader

Conversation

@redamancy231-create

Copy link
Copy Markdown
Contributor

做了什么

新增 akshare 数据源加载器,让 ml-quant 支持通过 akshare(东方财富底层)获取 A 股日线 OHLCV 数据,无需注册或 API Key。

改动范围

文件 操作
src/mlquant/data/akshare_loader.py 新建 — akshare → Panel 加载器,148 行
src/mlquant/data/__init__.py 修改 — 导出 + make_panel(source="akshare")
tests/test_akshare.py 新建 — mock 测试,覆盖中文列名解析/去重/VWAP/mask
pyproject.toml 修改 — 加 akshare>=1.18.0

设计决策

完全照搬既有 loader 模式——函数签名、错误处理、宽表转换、mask 构建均与 baostock_loader.py 一致,新增代码不引入新的抽象层。

和 baostock loader 的关键差异

  • 无需 login()/logout()(akshare 零认证)
  • 代码格式为纯数字("600519" 而非 "sh.600000"
  • mask 用 OHLCV 完整性判断(akshare 无显式 tradestatus 字段)
  • VWAP 始终用 (O+C+H+L)/4 代理——与 baostock v0.2.0 修复后的策略一致(akshare 复权后的 amount/volume 与 OHLC 不同基准)

使用方式

from mlquant.data import make_panel

panel = make_panel(
    "akshare",
    tickers=["600519", "000001"],
    start="2023-01-01",
    end="2023-12-31",
    adjust="qfq",              # 可选,默认前复权
)

验收

$ python -m pytest tests/test_akshare.py tests/test_baostock.py -v
5 passed

$ python -m pytest
47 passed

$ ruff check src/mlquant/data/akshare_loader.py tests/test_akshare.py
All checks passed

🤖 Generated with Claude Code

Co-Authored-By: GPT-5.6-Sol (via Codex CLI) noreply@anthropic.com

Add akshare as a new data source alongside baostock/yfinance/synthetic.
The loader follows the same pattern as baostock_loader.py: fetch -> pivot ->
build mask -> Panel.from_tensors(). Key differences from baostock:
- No login/logout (akshare requires zero authentication)
- Plain numeric ticker codes ("600519" instead of "sh.600000")
- Mask based on OHLCV completeness (akshare has no tradestatus field)
- VWAP always uses (O+C+H+L)/4 proxy, aligned with baostock v0.2.0 fix

Also adds make_panel(source="akshare", ...) support and mock tests.

Co-Authored-By: GPT-5.6-Sol (via Codex CLI) <noreply@anthropic.com>

@initial-d initial-d left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this — the loader follows the existing Panel conventions cleanly, and the three Python CI jobs are green.

Before merging, please add the two public-surface pieces that are currently missing:

  1. Add a test that exercises make_panel(source="akshare", ...) through the exported factory, not only load_akshare_panel(). That factory branch is part of the feature and is currently untested.
  2. Document AkShare in the README data-source table and loader usage section. Please mention that it needs no API key, but relies on an upstream public-data interface that may change or rate-limit. Also update the mlquant.data module/factory docstrings so the advertised source list is not stale.

No broader refactor is needed; the implementation itself looks consistent with the existing loaders.

@initial-d initial-d left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completed the requested public-factory test and documentation directly on the PR branch. All Python 3.9, 3.10, and 3.11 CI jobs now pass, including Ruff, the full pytest suite, and the CLI smoke test. The requested changes are resolved.

@initial-d
initial-d merged commit 34a3200 into initial-d:main Jul 28, 2026
3 checks passed
@initial-d

Copy link
Copy Markdown
Owner

Thanks for the contribution — this is a useful public-data addition.

AkShare fills a different niche from Baostock: zero-auth A-share access for quick public-data experiments, while Baostock remains the more explicit login/session-backed path. I like that this PR kept the loader shape aligned with the existing Baostock panel contract instead of adding another abstraction layer.

I'll treat this as part of the public-data validation surface for the next release notes. The main follow-up I would watch is provenance in reports: when a validation run uses akshare, the report should make the source, adjust mode, ticker format, and mask/VWAP policy visible so results are not confused with Baostock or yfinance runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants