Skip to content

Commit

Permalink
Date (#4594)
Browse files Browse the repository at this point in the history
* add version 1.12.89

* fix bond_china_yield
  • Loading branch information
albertandking authored Mar 12, 2024
1 parent d9825d3 commit 6c477e5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 140 deletions.
12 changes: 4 additions & 8 deletions akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@
0.4.29: feats: add currency interface
0.4.30: fix: futures_roll_yield.py/get_roll_yield: CUefp error
0.4.31: format: format currency.py
0.4.32: fix: china_bond.py
0.4.32: fix: bond_china.py
0.4.33: add: jyfm_tools_futures_arbitrage_matrix for jyfm futures
0.4.34: fix: get_czce_rank_table history-20171228 format
0.4.35: fix: get_czce_rank_table history-20071228 format
Expand Down Expand Up @@ -2701,9 +2701,10 @@
1.12.86 fix: fix fund_etf_spot_em interface
1.12.87 fix: fix fortune_rank interface
1.12.88 fix: fix fund_etf_spot_em interface
1.12.89 fix: fix bond_china_yield interface
"""

__version__ = "1.12.88"
__version__ = "1.12.89"
__author__ = "AKFamily"

import sys
Expand Down Expand Up @@ -4458,11 +4459,6 @@
bond_cb_redeem_jsl,
)

"""
债券质押式回购成交明细数据
"""
from akshare.bond.china_repo import bond_repo_zh_tick

"""
基金数据接口
"""
Expand Down Expand Up @@ -4999,7 +4995,7 @@
"""
债券行情
"""
from akshare.bond.china_bond import (
from akshare.bond.bond_china import (
bond_spot_quote,
bond_spot_deal,
bond_china_yield,
Expand Down
38 changes: 22 additions & 16 deletions akshare/bond/china_bond.py → akshare/bond/bond_china.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2023/4/23 17:24
Date: 2024/3/12 14:00
Desc: 中国外汇交易中心暨全国银行间同业拆借中心
中国外汇交易中心暨全国银行间同业拆借中心-市场数据-债券市场行情-现券市场做市报价
中国外汇交易中心暨全国银行间同业拆借中心-市场数据-债券市场行情-现券市场成交行情
http://www.chinamoney.com.cn/chinese/mkdatabond/
https://www.chinamoney.com.cn/chinese/mkdatabond/
"""
from io import StringIO

import pandas as pd
import requests

from akshare.bond.bond_china_money import bond_china_close_return_map


def bond_spot_quote() -> pd.DataFrame:
"""
中国外汇交易中心暨全国银行间同业拆借中心-市场数据-债券市场行情-现券市场做市报价
http://www.chinamoney.com.cn/chinese/mkdatabond/
https://www.chinamoney.com.cn/chinese/mkdatabond/
:return: 现券市场做市报价
:rtype: pandas.DataFrame
"""
url = "http://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbMktMakQuot"
bond_china_close_return_map()
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbMktMakQuot"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
}
Expand Down Expand Up @@ -62,21 +67,21 @@ def bond_spot_quote() -> pd.DataFrame:
temp_df["卖出收益率"] = temp_df["买入/卖出收益率"].str.split("/", expand=True).iloc[:, 1]
del temp_df["买入/卖出净价"]
del temp_df["买入/卖出收益率"]
temp_df['买入净价'] = pd.to_numeric(temp_df['买入净价'])
temp_df['卖出净价'] = pd.to_numeric(temp_df['卖出净价'])
temp_df['买入收益率'] = pd.to_numeric(temp_df['买入收益率'])
temp_df['卖出收益率'] = pd.to_numeric(temp_df['卖出收益率'])
temp_df['买入净价'] = pd.to_numeric(temp_df['买入净价'], errors="coerce")
temp_df['卖出净价'] = pd.to_numeric(temp_df['卖出净价'], errors="coerce")
temp_df['买入收益率'] = pd.to_numeric(temp_df['买入收益率'], errors="coerce")
temp_df['卖出收益率'] = pd.to_numeric(temp_df['卖出收益率'], errors="coerce")
return temp_df


def bond_spot_deal() -> pd.DataFrame:
"""
中国外汇交易中心暨全国银行间同业拆借中心-市场数据-债券市场行情-现券市场成交行情
http://www.chinamoney.com.cn/chinese/mkdatabond/
https://www.chinamoney.com.cn/chinese/mkdatabond/
:return: 现券市场成交行情
:rtype: pandas.DataFrame
"""
url = "http://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbtPri"
url = "https://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbtPri"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
}
Expand Down Expand Up @@ -110,6 +115,7 @@ def bond_spot_deal() -> pd.DataFrame:
"_",
"_",
"_",
"_",
]
temp_df = temp_df[
[
Expand All @@ -130,12 +136,12 @@ def bond_spot_deal() -> pd.DataFrame:


def bond_china_yield(
start_date: str = "20200204", end_date: str = "20210124"
start_date: str = "20200204", end_date: str = "20210124"
) -> pd.DataFrame:
"""
中国债券信息网-国债及其他债券收益率曲线
https://www.chinabond.com.cn/
http://yield.chinabond.com.cn/cbweb-pbc-web/pbc/historyQuery?startDate=2019-02-07&endDate=2020-02-04&gjqx=0&qxId=ycqx&locale=cn_ZH
https://yield.chinabond.com.cn/cbweb-pbc-web/pbc/historyQuery?startDate=2019-02-07&endDate=2020-02-04&gjqx=0&qxId=ycqx&locale=cn_ZH
注意: end_date - start_date 应该小于一年
:param start_date: 需要查询的日期, 返回在该日期之后一年内的数据
:type start_date: str
Expand All @@ -144,7 +150,7 @@ def bond_china_yield(
:return: 返回在指定日期之间之前一年内的数据
:rtype: pandas.DataFrame
"""
url = "http://yield.chinabond.com.cn/cbweb-pbc-web/pbc/historyQuery"
url = "https://yield.chinabond.com.cn/cbweb-pbc-web/pbc/historyQuery"
params = {
"startDate": '-'.join([start_date[:4], start_date[4:6], start_date[6:]]),
"endDate": '-'.join([end_date[:4], end_date[4:6], end_date[6:]]),
Expand All @@ -157,8 +163,8 @@ def bond_china_yield(
}
res = requests.get(url, params=params, headers=headers)
data_text = res.text.replace("&nbsp", "")
data_df = pd.read_html(data_text, header=0)[1]
data_df['日期'] = pd.to_datetime(data_df['日期']).dt.date
data_df = pd.read_html(StringIO(data_text), header=0)[1]
data_df['日期'] = pd.to_datetime(data_df['日期'], errors="coerce").dt.date
data_df['3月'] = pd.to_numeric(data_df['3月'], errors="coerce")
data_df['6月'] = pd.to_numeric(data_df['6月'], errors="coerce")
data_df['1年'] = pd.to_numeric(data_df['1年'], errors="coerce")
Expand All @@ -167,7 +173,7 @@ def bond_china_yield(
data_df['7年'] = pd.to_numeric(data_df['7年'], errors="coerce")
data_df['10年'] = pd.to_numeric(data_df['10年'], errors="coerce")
data_df['30年'] = pd.to_numeric(data_df['30年'], errors="coerce")
data_df.sort_values('日期', inplace=True)
data_df.sort_values(by='日期', inplace=True)
data_df.reset_index(inplace=True, drop=True)
return data_df

Expand Down
47 changes: 0 additions & 47 deletions akshare/bond/china_repo.py

This file was deleted.

6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@

## 更新说明详情

1.12.89 fix: fix bond_china_yield interface

1. 修复 bond_china_yield 接口

1.12.88 fix: fix fund_etf_spot_em interface

1. 修复 fund_etf_spot_em 接口
Expand Down Expand Up @@ -3684,6 +3688,8 @@

## 版本更新说明

1.12.89 fix: fix bond_china_yield interface

1.12.88 fix: fix fund_etf_spot_em interface

1.12.87 fix: fix fortune_rank interface
Expand Down
86 changes: 17 additions & 69 deletions docs/data/bond/bond.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ print(get_bond_bank_df)

接口: bond_spot_quote

目标地址: http://www.chinamoney.com.cn/chinese/mkdatabond/
目标地址: https://www.chinamoney.com.cn/chinese/mkdatabond/

描述: 中国外汇交易中心暨全国银行间同业拆借中心-市场数据-市场行情-债券市场行情-现券市场做市报价

Expand Down Expand Up @@ -374,7 +374,7 @@ print(bond_spot_quote_df)

接口: bond_spot_deal

目标地址: http://www.chinamoney.com.cn/chinese/mkdatabond/
目标地址: https://www.chinamoney.com.cn/chinese/mkdatabond/

描述: 中国外汇交易中心暨全国银行间同业拆借中心-市场数据-市场行情-债券市场行情-现券市场成交行情

Expand Down Expand Up @@ -409,25 +409,26 @@ print(bond_spot_deal_df)
数据示例

```
债券简称 成交净价 最新收益率 涨跌 加权收益率 交易量
0 21国开15 99.97 3.1220 -0.20 3.1211 1860.0000
1 21附息国债17 100.42 2.8404 0.04 2.8354 328.0649
2 22国开05 99.34 3.0775 -1.18 3.0846 284.2000
3 21国开08 100.00 2.8275 0.25 2.8200 263.0018
4 21国开10 101.57 3.2099 0.74 3.2008 218.3000
... ... ... ... ... ...
2129 21历下控股PPN002 100.98 3.5297 7.37 3.5297 0.0200
2130 20国开20 105.62 3.4800 -0.10 3.4800 0.0130
2131 19赣高速MTN001 102.62 2.8287 -0.65 2.8287 0.0110
2132 21苏交通MTN003(权益出资) 101.35 2.8250 -0.65 2.8250 0.0110
2133 19汇金MTN012 101.96 2.8006 -0.65 2.8006 0.0110
债券简称 成交净价 最新收益率 涨跌 加权收益率 交易量
0 23附息国债26 103.20 2.3000 -0.80 2.3168 NaN
1 23附息国债18 101.31 2.3650 -0.80 2.3733 NaN
2 20人民财险 101.15 4.1810 -0.23 4.1810 NaN
3 23无锡建投MTN003 100.87 2.7369 NaN 2.7369 NaN
4 22国新控股MTN005(能源保供特别债) 100.88 2.5900 NaN 2.5900 NaN
... ... ... ... ... ...
1775 22滨江房产MTN001 100.64 3.2700 -0.01 3.2700 NaN
1776 23建设银行CD059 97.44 1.8492 1.00 1.8492 NaN
1777 23华夏银行CD085 97.43 1.8505 1.00 1.8505 NaN
1778 24招商银行CD015 97.84 2.2099 NaN 2.2100 NaN
1779 24贴现国债13 99.88 1.7497 65.65 1.7497 NaN
[1780 rows x 6 columns]
```

#### 国债及其他债券收益率曲线

接口: bond_china_yield

目标地址: http://yield.chinabond.com.cn/cbweb-pbc-web/pbc/historyQuery?startDate=2019-02-07&endDate=2020-02-04&gjqx=0&qxId=ycqx&locale=cn_ZH
目标地址: https://yield.chinabond.com.cn/cbweb-pbc-web/pbc/historyQuery?startDate=2019-02-07&endDate=2020-02-04&gjqx=0&qxId=ycqx&locale=cn_ZH

描述: 中国债券信息网-国债及其他债券收益率曲线

Expand Down Expand Up @@ -479,60 +480,7 @@ print(bond_china_yield_df)
750 中债中短期票据收益率曲线(AAA) 2022-01-30 2.4486 ... 3.4477 3.6091 NaN
751 中债商业银行普通债收益率曲线(AAA) 2022-01-30 2.2908 ... 3.3122 3.4541 3.8209
752 中债国债收益率曲线 2022-01-30 1.7756 ... 2.6555 2.6997 3.2718
```

#### 质押式回购-成交明细

接口: bond_repo_zh_tick

目标地址: http://stockhtm.finance.qq.com/sstock/ggcx/131802.shtml

描述: 债券-质押式回购-实时行情-成交明细; 该接口暂不可用

限量: 单次返回所有指定日期的成交明细数据

输入参数

| 名称 | 类型 | 描述 |
|------------|-----|-----------------------------|
| code | str | code="sz131802"; 指定质押式回购 |
| trade_date | str | trade_date="20210120"; 指定日期 |

输出参数

| 名称 | 类型 | 描述 |
|--------|-------|---------------|
| 成交时间 | str | 时间: 09:25:04; |
| 成交价格 | float | |
| 价格变动 | float | |
| 成交量(手) | float | |
| 成交额(元) | float | |
| 性质 | str | 买卖盘标记 |

接口示例

```python
import akshare as ak

bond_repo_zh_tick_df = ak.bond_repo_zh_tick(code="sz131802", trade_date="20210120")
print(bond_repo_zh_tick_df)
```

数据示例

```
成交时间 成交价格 价格变动 成交量(手) 成交额(元) 性质
0 09:25:04 2.40 1.17 284 284000 卖盘
1 09:30:05 2.70 0.30 985 985000 卖盘
2 09:30:27 2.70 0.00 1030 1030000 卖盘
3 09:30:30 2.70 0.00 200 200000 卖盘
4 09:30:57 2.50 -0.20 500 500000 卖盘
... ... ... ... ... ..
1101 15:23:28 1.45 0.00 38 38000 卖盘
1102 15:24:55 1.45 0.00 25 25000 卖盘
1103 15:26:06 1.45 0.00 34 34000 卖盘
1104 15:26:54 1.45 0.00 59 59000 卖盘
1105 15:30:05 1.45 0.00 80 80000 卖盘
[753 rows x 10 columns]
```

### 沪深债券
Expand Down

0 comments on commit 6c477e5

Please sign in to comment.