Comprehensive Python library for financial data acquisition providing access to Chinese and global market data.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
AKShare provides comprehensive market index data with 95 functions covering domestic Chinese indices, international market indices, commodity indices, and volatility indicators. This includes major stock market benchmarks, sector indices, commodity price indices, and market sentiment indicators.
import akshare as ak
def stock_zh_index_spot_em() -> pd.DataFrame:
"""
Real-time Chinese market index quotes from East Money
Returns:
pd.DataFrame: Index real-time data with columns:
- 序号 (Index): Row number
- 代码 (Code): Index code
- 名称 (Name): Index name
- 最新价 (Latest): Current value
- 涨跌额 (Change): Point change
- 涨跌幅 (Pct_change): Percentage change
- 成交量 (Volume): Trading volume
- 成交额 (Amount): Trading amount
- 换手率 (Turnover): Turnover rate
- 最高 (High): Highest value
- 最低 (Low): Lowest value
- 今开 (Open): Opening value
- 昨收 (Prev_close): Previous close
"""
# Get real-time index data
index_realtime = ak.stock_zh_index_spot_em()
print(index_realtime.head())
# 序号 代码 名称 最新价 涨跌额 涨跌幅 成交量 成交额
# 0 1 000001 上证指数 3234.56 12.45 0.39 456789012 1234567890123
# 1 2 399001 深证成指 10567.89 23.78 0.23 234567890 876543210987
# 2 3 399006 创业板指 2134.56 -5.67 -0.27 123456789 543210987654import akshare as ak
def stock_zh_index_daily(symbol: str = "000001",
start_date: str = "19700101",
end_date: str = "20500101") -> pd.DataFrame:
"""
Chinese market index historical data
Parameters:
symbol: Index code (e.g., "000001" for Shanghai Composite)
start_date: Start date in YYYYMMDD format
end_date: End date in YYYYMMDD format
Returns:
pd.DataFrame: Historical index data with columns:
- 日期 (Date): Trading date
- 开盘 (Open): Opening value
- 收盘 (Close): Closing value
- 最高 (High): Highest value
- 最低 (Low): Lowest value
- 成交量 (Volume): Trading volume
- 成交额 (Amount): Trading amount
"""
# Get Shanghai Composite historical data
sh_composite = ak.stock_zh_index_daily(
symbol="000001",
start_date="20240101",
end_date="20241201"
)
print(sh_composite.head())
# 日期 开盘 收盘 最高 最低 成交量 成交额
# 0 2024-01-02 2987.45 3034.56 3045.12 2978.34 456789012 234567890123
# 1 2024-01-03 3034.56 3021.78 3056.89 3012.45 398765432 198765432109import akshare as ak
def stock_board_industry_index_em() -> pd.DataFrame:
"""
Industry sector index data
Returns:
pd.DataFrame: Industry sector performance with columns:
- 排名 (Rank): Sector ranking
- 板块名称 (Sector): Industry sector name
- 板块代码 (Code): Sector code
- 最新价 (Price): Current index value
- 涨跌额 (Change): Point change
- 涨跌幅 (Pct_change): Percentage change
- 总市值 (Market_cap): Total market capitalization
- 换手率 (Turnover): Average turnover rate
"""
# Get industry sector indices
industry_indices = ak.stock_board_industry_index_em()
print(industry_indices.head())
# 排名 板块名称 板块代码 最新价 涨跌额 涨跌幅 总市值 换手率
# 0 1 电子信息 BK0727 1234.56 23.45 1.94 987654321 2.45
# 1 2 生物医药 BK0456 2345.67 -12.34 -0.52 876543210 1.87import akshare as ak
def stock_board_concept_index_em() -> pd.DataFrame:
"""
Concept theme index data
Returns:
pd.DataFrame: Concept theme performance
"""
# Get concept theme indices
concept_indices = ak.stock_board_concept_index_em()import akshare as ak
def index_zh_a_hist(symbol: str = "000852", period: str = "daily",
start_date: str = "19700101",
end_date: str = "20500101") -> pd.DataFrame:
"""
A-share market cap segment indices
Parameters:
symbol: Index code (e.g., "000852" for CSI 1000)
period: Data frequency ("daily", "weekly", "monthly")
start_date: Start date
end_date: End date
Returns:
pd.DataFrame: Market cap index data
"""
# Get CSI 1000 (small cap) historical data
csi1000 = ak.index_zh_a_hist(
symbol="000852", # CSI 1000
start_date="20240101"
)
# Get CSI 300 (large cap) historical data
csi300 = ak.index_zh_a_hist(
symbol="000300", # CSI 300
start_date="20240101"
)import akshare as ak
def index_investing_global(country: str = "美国",
indicator: str = "道琼斯") -> pd.DataFrame:
"""
Global market indices from Investing.com
Parameters:
country: Country/region name
indicator: Index name
Returns:
pd.DataFrame: International index data with columns:
- 日期 (Date): Date
- 收盘 (Close): Closing value
- 开盘 (Open): Opening value
- 高 (High): High value
- 低 (Low): Low value
- 交易量 (Volume): Volume
- 涨跌幅 (Change): Percentage change
"""
# Get Dow Jones historical data
dow_jones = ak.index_investing_global(country="美国", indicator="道琼斯")
# Get S&P 500 data
sp500 = ak.index_investing_global(country="美国", indicator="标普500")
# Get NASDAQ data
nasdaq = ak.index_investing_global(country="美国", indicator="纳斯达克")
print(dow_jones.head())
# 日期 收盘 开盘 高 低 交易量 涨跌幅
# 0 2024-12-01 35234.56 35123.45 35345.67 35098.76 123456789 0.34
# 1 2024-11-29 35112.34 35087.65 35187.98 35034.21 109876543 -0.12import akshare as ak
def index_investing_global_country_name() -> list:
"""
Available countries for global index data
Returns:
list: List of available countries/regions
"""
def index_investing_global_indicator_name(country: str) -> list:
"""
Available indices for specific country
Parameters:
country: Country name
Returns:
list: List of available indices
"""
# Get available countries
countries = ak.index_investing_global_country_name()
# Get European indices
dax = ak.index_investing_global(country="德国", indicator="德国DAX30")
ftse = ak.index_investing_global(country="英国", indicator="英国富时100")
cac = ak.index_investing_global(country="法国", indicator="法国CAC40")import akshare as ak
# Get major Asian indices
nikkei = ak.index_investing_global(country="日本", indicator="日经225")
hang_seng = ak.index_investing_global(country="香港", indicator="恒生指数")
kospi = ak.index_investing_global(country="韩国", indicator="韩国KOSPI")
asx = ak.index_investing_global(country="澳大利亚", indicator="澳洲标普200")import akshare as ak
def index_cx_commodity() -> pd.DataFrame:
"""
Commodity price indices from cx.com
Returns:
pd.DataFrame: Commodity index data with columns:
- 指数名称 (Index_name): Commodity index name
- 最新价 (Latest): Current value
- 涨跌 (Change): Point change
- 涨跌幅 (Pct_change): Percentage change
- 昨收 (Prev_close): Previous close
- 今开 (Open): Opening value
- 最高 (High): Highest value
- 最低 (Low): Lowest value
"""
def index_cx_energy() -> pd.DataFrame:
"""
Energy commodity indices
Returns:
pd.DataFrame: Energy price indices
"""
def index_cx_metal() -> pd.DataFrame:
"""
Metal commodity indices
Returns:
pd.DataFrame: Metal price indices
"""
# Get comprehensive commodity data
commodity_indices = ak.index_cx_commodity()
energy_indices = ak.index_cx_energy()
metal_indices = ak.index_cx_metal()
print(commodity_indices.head())
# 指数名称 最新价 涨跌 涨跌幅 昨收 今开 最高 最低
# 0 原油指数 234.56 2.34 1.01 232.22 232.45 235.67 231.89
# 1 黄金指数 1987.65 -5.43 -0.27 1993.08 1992.34 1995.21 1985.76import akshare as ak
def index_cx_agriculture() -> pd.DataFrame:
"""
Agricultural commodity price indices
Returns:
pd.DataFrame: Agricultural price data
"""
# Get agricultural commodity indices
agri_indices = ak.index_cx_agriculture()import akshare as ak
def index_economic_leading() -> pd.DataFrame:
"""
Economic leading indicators index
Returns:
pd.DataFrame: Leading economic indicators
"""
def index_economic_coincident() -> pd.DataFrame:
"""
Economic coincident indicators
Returns:
pd.DataFrame: Coincident economic measures
"""
# Get economic indicator indices
leading_indicators = ak.index_economic_leading()
coincident_indicators = ak.index_economic_coincident()import akshare as ak
def index_vix() -> pd.DataFrame:
"""
VIX (CBOE Volatility Index) historical data
Returns:
pd.DataFrame: VIX data with columns:
- 日期 (Date): Date
- 收盘价 (Close): Closing VIX value
- 开盘价 (Open): Opening VIX value
- 最高价 (High): Highest VIX value
- 最低价 (Low): Lowest VIX value
- 成交量 (Volume): Trading volume
"""
def index_vix_hist(start_date: str = "19700101",
end_date: str = "20500101") -> pd.DataFrame:
"""
Historical VIX data with date range
Parameters:
start_date: Start date (YYYYMMDD)
end_date: End date (YYYYMMDD)
Returns:
pd.DataFrame: VIX historical data
"""
# Get VIX data
vix_data = ak.index_vix()
vix_hist = ak.index_vix_hist(start_date="20240101")
print(vix_data.head())
# 日期 收盘价 开盘价 最高价 最低价 成交量
# 0 2024-12-01 18.45 18.23 18.87 18.12 1234567
# 1 2024-11-29 17.89 18.01 18.34 17.76 1098765import akshare as ak
def index_option_qvix(trade_date: str) -> pd.DataFrame:
"""
Chinese volatility index (iVIX equivalent)
Parameters:
trade_date: Trading date (YYYY-MM-DD)
Returns:
pd.DataFrame: Chinese market volatility data
"""
# Get Chinese volatility index
china_vix = ak.index_option_qvix(trade_date="2024-12-01")import akshare as ak
def index_market_breadth() -> pd.DataFrame:
"""
Market breadth indicators and statistics
Returns:
pd.DataFrame: Market breadth data including:
- 上涨家数 (Advancing): Number of advancing stocks
- 下跌家数 (Declining): Number of declining stocks
- 平盘家数 (Unchanged): Number of unchanged stocks
- 涨停家数 (Limit_up): Number of limit-up stocks
- 跌停家数 (Limit_down): Number of limit-down stocks
"""
# Get market breadth data
market_breadth = ak.index_market_breadth()import akshare as ak
def index_esg_em() -> pd.DataFrame:
"""
ESG (Environmental, Social, Governance) indices
Returns:
pd.DataFrame: ESG index performance data
"""
def index_green_energy() -> pd.DataFrame:
"""
Green energy and renewable sector indices
Returns:
pd.DataFrame: Clean energy index data
"""
# Get ESG and thematic indices
esg_indices = ak.index_esg_em()
green_indices = ak.index_green_energy()import akshare as ak
def index_factor_value() -> pd.DataFrame:
"""
Value factor index performance
Returns:
pd.DataFrame: Value-based index data
"""
def index_factor_growth() -> pd.DataFrame:
"""
Growth factor index performance
Returns:
pd.DataFrame: Growth-based index data
"""
def index_factor_momentum() -> pd.DataFrame:
"""
Momentum factor index data
Returns:
pd.DataFrame: Momentum-based indices
"""
# Get factor indices
value_indices = ak.index_factor_value()
growth_indices = ak.index_factor_growth()
momentum_indices = ak.index_factor_momentum()import akshare as ak
import pandas as pd
def create_global_index_dashboard() -> dict:
"""Create comprehensive global index monitoring dashboard"""
dashboard = {
# Chinese indices
'china_major': ak.stock_zh_index_spot_em(),
'china_sectors': ak.stock_board_industry_index_em(),
# US indices
'us_dow': ak.index_investing_global(country="美国", indicator="道琼斯"),
'us_sp500': ak.index_investing_global(country="美国", indicator="标普500"),
'us_nasdaq': ak.index_investing_global(country="美国", indicator="纳斯达克"),
# Volatility
'vix': ak.index_vix(),
# Commodities
'commodities': ak.index_cx_commodity()
}
return dashboard
def analyze_market_correlation() -> pd.DataFrame:
"""Analyze correlations between different market indices"""
# Get multiple index data
sh_composite = ak.stock_zh_index_daily(symbol="000001", start_date="20240101")
sp500 = ak.index_investing_global(country="美国", indicator="标普500")
# Correlation analysis would be performed here
return correlation_matrix
# Usage
global_dashboard = create_global_index_dashboard()
correlation_data = analyze_market_correlation()import akshare as ak
def monitor_market_risk() -> dict:
"""Comprehensive market risk monitoring using indices"""
risk_metrics = {}
# Market level risk (VIX)
vix_data = ak.index_vix()
risk_metrics['volatility'] = vix_data
# Sector concentration risk
sector_data = ak.stock_board_industry_index_em()
risk_metrics['sector_performance'] = sector_data
# International correlation risk
global_indices = {
'us_sp500': ak.index_investing_global(country="美国", indicator="标普500"),
'eu_dax': ak.index_investing_global(country="德国", indicator="德国DAX30"),
'asia_nikkei': ak.index_investing_global(country="日本", indicator="日经225")
}
risk_metrics['global_indices'] = global_indices
# Commodity risk
commodity_data = ak.index_cx_commodity()
risk_metrics['commodities'] = commodity_data
return risk_metrics
def benchmark_performance(portfolio_returns: pd.Series,
benchmark_symbol: str = "000300") -> dict:
"""Benchmark portfolio performance against market indices"""
# Get benchmark data
benchmark_data = ak.stock_zh_index_daily(
symbol=benchmark_symbol,
start_date="20240101"
)
# Performance comparison analysis
performance_metrics = {
'benchmark_returns': benchmark_data,
'tracking_error': None, # Would calculate tracking error
'information_ratio': None, # Would calculate information ratio
'beta': None, # Would calculate portfolio beta
'alpha': None # Would calculate portfolio alpha
}
return performance_metrics
# Usage
market_risk = monitor_market_risk()
# benchmark_perf = benchmark_performance(portfolio_returns, "000300")The market index capabilities in AKShare provide comprehensive tools for market analysis, benchmarking, and risk management across domestic and international markets.
Install with Tessl CLI
npx tessl i tessl/pypi-akshare