Skip to main content

Kepler Wind

优雅的量化数据访问接口,基于 Wind 金融终端数据库。

安装

pip install kepler-wind

快速开始

from kepler.wind import Wind

w = Wind()

API 设计

按资产分类,每个资产提供截面和时序查询方法。

股票池

# 当前成分股
w.universe.members("HS300")

# 历史成分股
w.universe.at("HS300", "20240101")

# 完整变更历史
w.universe.history("HS300")

# 支持的指数
w.universe.members("A")        # 全A股
w.universe.members("ZZ500")    # 中证500
w.universe.members("MSCI")     # MSCI

指数

# 历史数据(自动识别指数类型)
w.index.history("000001.SH")                    # 普通指数
w.index.history("801010.SI")                    # 申万指数
w.index.history("CI005001.WI")                  # 中信指数
w.index.history("884001.WI")                    # Wind行业指数
w.index.history(["000001.SH", "801010.SI"])     # 混合查询

收益率

# 截面:某日所有股票收益率
w.returns.on("20240101")

# 时序:日收益率
w.returns.daily("000001.SZ")
w.returns.daily(["000001.SZ", "000002.SZ"])

行业

# A股行业(中信分类)
w.industry.on("20240101")                   # 截面:某日所有股票行业
w.industry.on("20240101", level=2)          # 二级行业
w.industry.of("000001.SZ")                  # 单股行业
w.industry.of("000001.SZ", date="20240101")

# 港股行业
w.industry_hk.on("20240101")                          # 港股中信行业(默认)
w.industry_hk.on("20240101", source="wind")           # 港股Wind一级行业
w.industry_hk.on("20240101", source="wind", level=2)  # 港股Wind二级行业
w.industry_hk.of("0001.HK", date="20240101")

基金

# 筛选基金
w.fund.filter(type="股票型")

迁移指南

从旧版本迁移到新版本的 API 对照:

股票池

旧 API 新 API
universe_A() w.universe.members("A")
universe_A(cur_sign=False) w.universe.history("A")
universe_normal("HS300") w.universe.members("HS300")
universe_normal("HS300", cur_sign=False) w.universe.at("HS300", date)
universe_msci() w.universe.members("MSCI")
Universe("HS300") w.universe.members("HS300")
get_all_normal_index("HS300") w.universe.members("HS300")
get_all_msci() w.universe.members("MSCI")
get_all_stk() w.universe.members("A")
get_all_hk("HS300") w.universe.members("HK")

指数

旧 API 新 API
get_index_data("000001.SH") w.index.history("000001.SH")
get_index_data(["000001.SH", "801010.SI"]) w.index.history(["000001.SH", "801010.SI"])
get_index_data_tmp(codes, "zx") w.index.history(codes) (自动识别)

收益率

旧 API 新 API
get_daily_ret("000001.SZ") w.returns.daily("000001.SZ")
get_daily_ret(["000001.SZ", "000002.SZ"]) w.returns.daily(["000001.SZ", "000002.SZ"])

行业

旧 API 新 API
get_industry("20240101") w.industry.on("20240101")
get_industry("20240101", sid="000001.SZ") w.industry.of("000001.SZ", date="20240101")
get_industry("20240101", level=2) w.industry.on("20240101", level=2)
get_industry_hk("20240101") w.industry_hk.on("20240101")
get_industry_windhk("20240101", level=2) w.industry_hk.on("20240101", source="wind", level=2)

基金

旧 API 新 API
get_fund_list() w.fund.filter()
get_fund_filter("股票型") w.fund.filter(type="股票型")

配置

方式一:配置文件

配置文件位于 ~/.kepler/wind/wind.toml

[wind]
engine = "mysql+pymysql://user:pass@host:3306/db"
schema = ""  # MySQL 留空,PostgreSQL 填 "public"

方式二:代码传入

from kepler.wind import Wind

# MySQL
w = Wind(url="mysql+pymysql://user:pass@host:3306/wind")

# PostgreSQL
w = Wind(url="postgresql://user:pass@host:5432/db", schema="public")

依赖

  • kepler-atlas >= 0.1.5
  • kepler-pulse >= 0.1.8
  • pandas
  • sqlalchemy

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kepler_wind-0.2.7.tar.gz (32.4 kB view details)

Uploaded Source

Built Distribution

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

kepler_wind-0.2.7-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file kepler_wind-0.2.7.tar.gz.

File metadata

  • Download URL: kepler_wind-0.2.7.tar.gz
  • Upload date:
  • Size: 32.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for kepler_wind-0.2.7.tar.gz
Algorithm Hash digest
SHA256 61585a04bd6a52dbbde1b1d6c1a11b80429fa9d51042b3059882282446c2b162
MD5 f9f089c727b0803a07080aa735f2b748
BLAKE2b-256 786f433f81ab20d95fd4050ebcb82648a2841b3ecf98371bf517077e39f4d5c3

See more details on using hashes here.

File details

Details for the file kepler_wind-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: kepler_wind-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for kepler_wind-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8d1a8081c7525328439aadb1b74a4cd7e17048dc644f583abb16e05e145e14cb
MD5 61b30bed9e77371d6cfab3b268234c52
BLAKE2b-256 a01f64e0bdec0dc0897cfd85401611f59d02db1fd21674a8dc55c741e36ffa99

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

0.2.9

2 files

0.2.8

2 files

This release

0.2.7 This release

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.0

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page