Skip to content

Commit

Permalink
fix(futures_return_index_nh): fix futures_return_index_nh interface
Browse files Browse the repository at this point in the history
fix futures_return_index_nh interface
  • Loading branch information
ak-quant committed Apr 28, 2022
1 parent 355348e commit 6d286de
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 40 deletions.
19 changes: 10 additions & 9 deletions akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@
0.6.68: add: add macro_china_retail_price_index interface
0.6.69: fix: fix box_office_spot interface
0.6.70: fix: fix bond_investing_global interface
0.6.71: fix: fix futures_nh_return_index interface
0.6.71: fix: fix futures_return_index_nh interface
0.6.72: fix: fix get_receipt interface
0.6.73: add: add news_cctv interface
0.6.74: fix: fix macro and acm interface
Expand Down Expand Up @@ -1672,7 +1672,7 @@
1.2.47 fix: fix covid_19_dxy interface
1.2.48 fix: fix covid_19_dxy interface
1.2.49 fix: fix rate_interbank interface
1.2.50 fix: fix futures_nh_price_index interface
1.2.50 fix: fix futures_price_index_nh interface
1.2.51 add: add futures_hq_subscribe_exchange_symbol interface
1.2.52 fix: fix futures_foreign_commodity_realtime interface
1.2.53 add: add get_ine_daily interface
Expand Down Expand Up @@ -1967,9 +1967,10 @@
1.5.45 add: add stock_hot_deal_xq interface
1.5.46 fix: fix stock_yzxdr_em interface
1.5.47 fix: fix macro_china_lpr interface
1.5.48 fix: fix futures_return_index_nh interface
"""

__version__ = "1.5.47"
__version__ = "1.5.48"
__author__ = "AKFamily"

import sys
Expand Down Expand Up @@ -1999,7 +2000,7 @@
南华期货-品种指数涨跌
南华期货-相关系数矩阵
"""
from akshare.futures_derivative.other_index_nh import (
from akshare.futures_derivative.futures_other_index_nh import (
futures_correlation_nh,
futures_board_index_nh,
futures_variety_index_nh,
Expand Down Expand Up @@ -3531,12 +3532,12 @@
"""
南华期货-南华指数
"""
from akshare.futures_derivative.nh_index_return import futures_nh_return_index
from akshare.futures_derivative.nh_index_price import (
futures_nh_price_index,
futures_nh_index_symbol_table,
from akshare.futures_derivative.futures_index_return_nh import futures_return_index_nh
from akshare.futures_derivative.futures_index_price_nh import (
futures_price_index_nh,
futures_index_symbol_table_nh,
)
from akshare.futures_derivative.nh_index_volatility import futures_nh_volatility_index
from akshare.futures_derivative.futures_index_volatility_nh import futures_nh_volatility_index

"""
空气-河北
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2021/12/20 14:52
Date: 2022/4/28 16:25
Desc: 南华期货-商品指数历史走势-价格指数-数值
http://www.nanhua.net/nhzc/varietytrend.html
1000 点开始, 用收益率累计
Expand All @@ -13,7 +13,7 @@
import pandas as pd


def futures_nh_index_symbol_table() -> pd.DataFrame:
def futures_index_symbol_table_nh() -> pd.DataFrame:
"""
南华期货-南华指数所有品种一览表
http://www.nanhua.net/ianalysis/varietyindex/price/A.json?t=1574932974280
Expand All @@ -28,16 +28,16 @@ def futures_nh_index_symbol_table() -> pd.DataFrame:
return temp_df


def futures_nh_price_index(symbol: str = "A") -> pd.DataFrame:
def futures_price_index_nh(symbol: str = "A") -> pd.DataFrame:
"""
南华期货-南华指数单品种-价格-所有历史数据
http://www.nanhua.net/ianalysis/varietyindex/price/A.json?t=1574932974280
:param symbol: 通过 ak.futures_nh_index_symbol_table() 获取
:param symbol: 通过 ak.futures_index_symbol_table_nh() 获取
:type symbol: str
:return: 南华期货-南华指数单品种-价格-所有历史数据
:rtype: pandas.Series
"""
symbol_df = futures_nh_index_symbol_table()
symbol_df = futures_index_symbol_table_nh()
if symbol in symbol_df["code"].tolist():
t = time.time()
url = f"http://www.nanhua.net/ianalysis/varietyindex/price/{symbol}.json?t={int(round(t * 1000))}"
Expand All @@ -50,8 +50,8 @@ def futures_nh_price_index(symbol: str = "A") -> pd.DataFrame:


if __name__ == "__main__":
futures_nh_index_symbol_table_df = futures_nh_index_symbol_table()
print(futures_nh_index_symbol_table_df)
futures_index_symbol_table_nh_df = futures_index_symbol_table_nh()
print(futures_index_symbol_table_nh_df)

futures_nh_price_index_df = futures_nh_price_index(symbol="NHAI")
print(futures_nh_price_index_df)
futures_price_index_nh_df = futures_price_index_nh(symbol="NHAI")
print(futures_price_index_nh_df)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2021/12/20 15:19
Date: 2022/4/28 16:19
Desc: 南华期货-商品指数历史走势-收益率指数-数值-http://www.nanhua.net/nhzc/varietytrend.html
1000 点开始, 用收益率累计
目标地址: http://www.nanhua.net/ianalysis/varietyindex/index/NHCI.json?t=1574932290494
Expand All @@ -11,29 +11,31 @@
import requests
import pandas as pd

from akshare.futures_derivative.nh_index_price import futures_nh_index_symbol_table
from akshare.futures_derivative.futures_index_price_nh import futures_index_symbol_table_nh


def futures_nh_return_index(symbol: str = "Y") -> pd.DataFrame:
def futures_return_index_nh(symbol: str = "Y") -> pd.DataFrame:
"""
南华期货-南华指数单品种-收益率-所有历史数据
:param symbol: 通过 ak.futures_nh_index_symbol_table() 获取
:param symbol: 通过 ak.futures_index_symbol_table_nh() 获取
:type symbol: str
:return: 南华指数单品种-收益率-所有历史数据
:rtype: pandas.Series
"""
symbol_df = futures_nh_index_symbol_table()
if symbol in symbol_df["code"].tolist():
symbol_df = futures_index_symbol_table_nh()
symbol_list = symbol_df["code"].tolist()
if symbol in symbol_list:
t = time.time()
url = f"http://www.nanhua.net/ianalysis/varietyindex/index/{symbol}.json?t={int(round(t * 1000))}"
r = requests.get(url)
data_json = r.json()
temp_df = pd.DataFrame(data_json)
temp_df.columns = ["date", "value"]
temp_df['date'] = pd.to_datetime(temp_df["date"], unit='ms').dt.date
temp_df['value'] = pd.to_numeric(temp_df['value'])
return temp_df


if __name__ == "__main__":
futures_nh_return_index_df = futures_nh_return_index(symbol='NHAI')
print(futures_nh_return_index_df)
futures_return_index_nh_df = futures_return_index_nh(symbol='NHAI')
print(futures_return_index_nh_df)
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
import requests
import pandas as pd

from akshare.futures_derivative.nh_index_price import futures_nh_index_symbol_table
from akshare.futures_derivative.futures_index_price_nh import futures_index_symbol_table_nh


def futures_nh_volatility_index(symbol: str = "NHCI", period: str = '20') -> pd.DataFrame:
"""
南华期货-南华指数单品种-波动率-所有历史数据
http://www.nanhua.net/nhzc/varietytrend.html
:param symbol: 通过 ak.futures_nh_index_symbol_table() 获取
:param symbol: 通过 ak.futures_index_symbol_table_nh() 获取
:type symbol: str
:param period: 波动周期 choice of {'5', '20', '60', '120'}
:type period: str
:return: 波动率-所有历史数据
:rtype: pandas.DataFrame
"""
symbol_df = futures_nh_index_symbol_table()
symbol_df = futures_index_symbol_table_nh()
if symbol in symbol_df["code"].tolist():
t = time.time()
url = f"http://www.nanhua.net/ianalysis/volatility/{period}/{symbol}.json?t={int(round(t * 1000))}"
Expand Down
11 changes: 11 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

| AKShare 版本 | 旧接口名称 | 新接口名称 | 修改日期 |
|------------|-----------------------------------|-----------------------------------|----------|
| 1.5.48 | futures_nh_price_index | futures_price_index_nh | 20220428 |
| 1.5.48 | futures_nh_index_symbol_table | futures_index_symbol_table_nh | 20220428 |
| 1.5.48 | futures_nh_return_index | futures_return_index_nh | 20220428 |
| 1.5.46 | stock_em_yzxdr | stock_yzxdr_em | 20220427 |
| 1.5.34 | stock_em_gpzy_industry_data | stock_gpzy_industry_data_em | 20220420 |
| 1.5.26 | stock_em_comment | stock_comment_em | 20220415 |
Expand All @@ -20,6 +23,12 @@

## 更新说明

1.5.48 fix: fix futures_return_index_nh interface

1. 修复 futures_return_index_nh 接口,重命名接口及规范数据输出格式
2. 修复 futures_index_symbol_table_nh 接口,重名接口
3. 修复 futures_price_index_nh 接口,重名接口

1.5.47 fix: fix macro_china_lpr interface

1. 修复 macro_china_lpr 接口,规范数据的输出格式
Expand Down Expand Up @@ -454,6 +463,8 @@

## 版本更新说明

1.5.48 fix: fix futures_return_index_nh interface

1.5.47 fix: fix macro_china_lpr interface

1.5.46 fix: fix stock_yzxdr_em interface
Expand Down
18 changes: 9 additions & 9 deletions docs/data/futures/futures.md
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@ print(futures_contract_detail_df)

#### 收益率指数

接口: futures_nh_return_index
接口: futures_return_index_nh

目标地址: http://www.nanhua.net/nhzc/varietytrend.html

Expand All @@ -2866,7 +2866,7 @@ print(futures_contract_detail_df)

| 名称 | 类型 | 描述 |
|--------|-----|----------------------------------------------------------------------|
| symbol | str | symbol="Y", 请参考南华指数品种一览表, 可以通过 ak.futures_nh_index_symbol_table() 获取 |
| symbol | str | symbol="Y", 请参考南华指数品种一览表, 可以通过 ak.futures_index_symbol_table_nh() 获取 |

南华指数品种一览表

Expand Down Expand Up @@ -2957,8 +2957,8 @@ print(futures_contract_detail_df)
```python
import akshare as ak

futures_nh_return_index_df = ak.futures_nh_return_index()
print(futures_nh_return_index_df)
futures_return_index_nh_df = ak.futures_return_index_nh()
print(futures_return_index_nh_df)
```

数据示例
Expand All @@ -2980,7 +2980,7 @@ print(futures_nh_return_index_df)

#### 价格指数

接口: futures_nh_price_index
接口: futures_price_index_nh

目标地址: http://www.nanhua.net/nhzc/varietytrend.html

Expand All @@ -2992,7 +2992,7 @@ print(futures_nh_return_index_df)

| 名称 | 类型 | 描述 |
|--------|-----|----------------------------------------------------------------------|
| symbol | str | symbol="Y", 请参考南华指数品种一览表, 可以通过 ak.futures_nh_index_symbol_table() 获取 |
| symbol | str | symbol="Y", 请参考南华指数品种一览表, 可以通过 ak.futures_index_symbol_table_nh() 获取 |

南华指数品种一览表

Expand Down Expand Up @@ -3076,8 +3076,8 @@ print(futures_nh_return_index_df)
```python
import akshare as ak

futures_nh_price_index_df = ak.futures_nh_price_index(symbol="Y")
print(futures_nh_price_index_df)
futures_price_index_nh_df = ak.futures_price_index_nh(symbol="Y")
print(futures_price_index_nh_df)
```

数据示例
Expand Down Expand Up @@ -3111,7 +3111,7 @@ print(futures_nh_price_index_df)

| 名称 | 类型 | 描述 |
|--------|-----|--------------------------------------------------------------------------------------------|
| symbol | str | symbol="Y"; 注意是具体品种(不包含指数); 请参考南华指数品种一览表, 可以通过调用 **ak.futures_nh_index_symbol_table()** 获取 |
| symbol | str | symbol="Y"; 注意是具体品种(不包含指数); 请参考南华指数品种一览表, 可以通过调用 **ak.futures_index_symbol_table_nh()** 获取 |
| period | str | period='20'; 波动周期; choice of {'5', '20', '60', '120'} |

南华指数品种一览表
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@
# 南华期货-南华指数-波动率指数
"futures_nh_volatility_index" # 波动率指数
# 南华期货-南华指数-价格指数
"futures_nh_price_index" # 价格指数
"futures_price_index_nh" # 价格指数
# 南华期货-南华指数-收益率指数
"futures_nh_return_index" # 收益率指数
"futures_return_index_nh" # 收益率指数
# 经济政策不确定性(EPU)指数
"article_epu_index" # 主要国家和地区的经济政策不确定性(EPU)指数
# 微博指数
Expand Down

0 comments on commit 6d286de

Please sign in to comment.