Skip to content

Commit

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

* fix fund_manager_em

* fix futures_main_sina

* fix futures_main_sina
  • Loading branch information
albertandking authored Nov 5, 2023
1 parent 21f36cf commit d6ba2de
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 97 deletions.
5 changes: 3 additions & 2 deletions akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2574,9 +2574,10 @@
1.11.58 fix: fix bond_china_close_return interface
1.11.59 fix: fix fund_portfolio_change_em interface
1.11.60 fix: fix bond_china_close_return interface
1.11.61 fix: fix fund_manager_em interface
"""

__version__ = "1.11.60"
__version__ = "1.11.61"
__author__ = "AKFamily"

import sys
Expand Down Expand Up @@ -3712,7 +3713,7 @@
"""
基金经理
"""
from akshare.fund.fund_manager import fund_manager
from akshare.fund.fund_manager import fund_manager_em

"""
基金评级
Expand Down
45 changes: 15 additions & 30 deletions akshare/fund/fund_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2023/5/4 18:10
Date: 2023/11/5 20:00
Desc: 基金经理大全
http://fund.eastmoney.com/manager/default.html
https://fund.eastmoney.com/manager/default.html
"""
import pandas as pd
import requests
Expand All @@ -12,22 +12,20 @@
from akshare.utils import demjson


def fund_manager(adjust: str = "0") -> pd.DataFrame:
def fund_manager_em() -> pd.DataFrame:
"""
天天基金网-基金数据-基金经理大全
http://fund.eastmoney.com/manager/default.html
:param adjust: 默认 adjust='0', 返回目标地址相同格式; adjust='1', 返回根据 `现任基金` 打散后的数据
:type adjust: str
https://fund.eastmoney.com/manager/default.html
:return: 基金经理大全
:rtype: pandas.DataFrame
"""
big_df = pd.DataFrame()
url = "http://fund.eastmoney.com/Data/FundDataPortfolio_Interface.aspx"
url = "https://fund.eastmoney.com/Data/FundDataPortfolio_Interface.aspx"
params = {
"dt": "14",
"mc": "returnjson",
"ft": "all",
"pn": "50",
"pn": "500",
"pi": "1",
"sc": "abbname",
"st": "asc",
Expand All @@ -37,22 +35,14 @@ def fund_manager(adjust: str = "0") -> pd.DataFrame:
data_json = demjson.decode(data_text.strip("var returnjson= "))
total_page = data_json["pages"]
for page in tqdm(range(1, total_page + 1), leave=False):
url = "http://fund.eastmoney.com/Data/FundDataPortfolio_Interface.aspx"
params = {
"dt": "14",
"mc": "returnjson",
"ft": "all",
"pn": "50",
"pi": str(page),
"sc": "abbname",
"st": "asc",
}
params.update({
"pi": page,
})
r = requests.get(url, params=params)
data_text = r.text
data_json = demjson.decode(data_text.strip("var returnjson= "))
temp_df = pd.DataFrame(data_json["data"])
big_df = pd.concat([big_df, temp_df], ignore_index=True)

big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
big_df.reset_index(inplace=True)
big_df["index"] = range(1, len(big_df) + 1)
big_df.columns = [
Expand Down Expand Up @@ -86,17 +76,12 @@ def fund_manager(adjust: str = "0") -> pd.DataFrame:
big_df["累计从业时间"] = pd.to_numeric(big_df["累计从业时间"], errors="coerce")
big_df["现任基金最佳回报"] = pd.to_numeric(big_df["现任基金最佳回报"], errors="coerce")
big_df["现任基金资产总规模"] = pd.to_numeric(big_df["现任基金资产总规模"], errors="coerce")
if adjust == "1":
big_df["现任基金"] = big_df["现任基金"].apply(lambda x: x.split(","))
big_df = big_df.explode(column="现任基金")
big_df.reset_index(drop=True, inplace=True)
return big_df
big_df["现任基金"] = big_df["现任基金"].apply(lambda x: x.split(","))
big_df = big_df.explode(column="现任基金")
big_df.reset_index(drop=True, inplace=True)
return big_df


if __name__ == "__main__":
fund_manager_df = fund_manager(adjust="0")
print(fund_manager_df)

fund_manager_df = fund_manager(adjust="1")
print(fund_manager_df)
fund_manager_em_df = fund_manager_em()
print(fund_manager_em_df)
30 changes: 15 additions & 15 deletions akshare/futures_derivative/futures_index_sina.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2023/9/15 17:41
Date: 2023/11/5 20:00
Desc: 新浪财经-期货的主力合约数据
https://finance.sina.com.cn/futuremarket/index.shtml
"""
Expand Down Expand Up @@ -29,7 +29,7 @@ def zh_subscribe_exchange_symbol(symbol: str = "dce") -> pd.DataFrame:
"""
r = requests.get(zh_subscribe_exchange_symbol_url)
r.encoding = "gb2312"
data_json = demjson.decode(r.text[r.text.find("{") : r.text.find("};") + 1])
data_json = demjson.decode(r.text[r.text.find("{"): r.text.find("};") + 1])
if symbol == "czce":
data_json["czce"].remove("郑州商品交易所")
return pd.DataFrame(data_json["czce"])
Expand Down Expand Up @@ -67,12 +67,12 @@ def match_main_contract(symbol: str = "shfe") -> pd.DataFrame:
data_df = pd.DataFrame(data_json)
try:
main_contract = data_df[
data_df["name"].str.contains("连续")
& data_df["symbol"]
.str.extract(r"([\w])(\d)")
.iloc[:, 1]
.str.contains("0")
].iloc[0, :3]
data_df["name"].str.contains("连续")
& data_df["symbol"]
.str.extract(r"([\w])(\d)")
.iloc[:, 1]
.str.contains("0")
].iloc[0, :3]
subscribe_list.append(main_contract)
except:
# print(item, "无主力连续合约")
Expand All @@ -97,13 +97,13 @@ def futures_display_main_sina() -> pd.DataFrame:


def futures_main_sina(
symbol: str = "V0",
start_date: str = "19900101",
end_date: str = "22220101",
symbol: str = "V0",
start_date: str = "19900101",
end_date: str = "22220101",
) -> pd.DataFrame:
"""
新浪财经-期货-主力连续日数据
http://vip.stock.finance.sina.com.cn/quotes_service/view/qihuohangqing.html#titlePos_1
https://vip.stock.finance.sina.com.cn/quotes_service/view/qihuohangqing.html#titlePos_1
:param symbol: 通过 ak.futures_display_main_sina() 函数获取 symbol
:type symbol: str
:param start_date: 开始时间
Expand All @@ -118,11 +118,11 @@ def futures_main_sina(
url = f"https://stock2.finance.sina.com.cn/futures/api/jsonp.php/var%20_{symbol}{trade_date}=/InnerFuturesNewService.getDailyKLine?symbol={symbol}&_={trade_date}"
r = requests.get(url)
data_text = r.text
data_json = data_text[data_text.find("([") + 1 : data_text.rfind("])") + 1]
data_json = data_text[data_text.find("([") + 1: data_text.rfind("])") + 1]
temp_df = pd.read_json(StringIO(data_json))
temp_df.columns = ["日期", "开盘价", "最高价", "最低价", "收盘价", "成交量", "持仓量", "动态结算价"]
temp_df["日期"] = pd.to_datetime(temp_df["日期"]).dt.date
temp_df.set_index(["日期"], inplace=True)
temp_df.set_index(keys=["日期"], inplace=True)
temp_df.index = pd.to_datetime(temp_df.index)
temp_df = temp_df[start_date:end_date]
temp_df.reset_index(inplace=True)
Expand All @@ -132,7 +132,7 @@ def futures_main_sina(
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["持仓量"])
temp_df["持仓量"] = pd.to_numeric(temp_df["持仓量"], errors="coerce")
temp_df["动态结算价"] = pd.to_numeric(temp_df["动态结算价"], errors="coerce")
return temp_df

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

| AKShare 版本 | 旧接口名称 | 新接口名称 | 修改日期 |
|------------|---------------------------------------------|---------------------------------------------|----------|
| 1.11.61 | fund_manager | fund_manager_em | 20231105 |
| 1.11.41 | weibo_index | index_weibo_sina | 20231020 |
| 1.11.39 | option_300etf_min_qvix | index_option_300etf_min_qvix | 20231019 |
| 1.11.39 | option_300etf_qvix | index_option_300etf_qvix | 20231019 |
Expand Down Expand Up @@ -68,6 +69,10 @@

## 更新说明详情

1.11.61 fix: fix fund_manager_em interface

1. 修复 fund_manager_em 接口

1.11.60 fix: fix bond_china_close_return interface

1. 修复 bond_china_close_return 接口
Expand Down Expand Up @@ -3083,6 +3088,8 @@

## 版本更新说明

1.11.61 fix: fix fund_manager_em interface

1.11.60 fix: fix bond_china_close_return interface

1.11.59 fix: fix fund_portfolio_change_em interface
Expand Down
71 changes: 23 additions & 48 deletions docs/data/fund/fund_public.md
Original file line number Diff line number Diff line change
Expand Up @@ -2849,82 +2849,57 @@ print(fund_rating_ja_df)

### 基金经理

接口: fund_manager
接口: fund_manager_em

目标地址: http://fund.eastmoney.com/manager/default.html
目标地址: https://fund.eastmoney.com/manager/default.html

描述: 天天基金网-基金数据-基金经理大全

限量: 单次返回所有基金经理数据

输入参数

| 名称 | 类型 | 描述 |
|--------|-----|-----------------------------------------------------------|
| adjust | str | 默认 adjust='0', 返回目标地址相同格式; adjust='1', 返回根据 `现任基金` 打散后的数据 |
| 名称 | 类型 | 描述 |
|----|----|----|
| - | - | - |

输出参数

| 名称 | 类型 | 描述 |
|-----------|---------|----------|
| 序号 | int32 | - |
| 序号 | int64 | - |
| 姓名 | object | - |
| 所属公司 | object | - |
| 现任基金 | object | - |
| 累计从业时间 | int64 | 注意单位: 天 |
| 现任基金资产总规模 | float64 | 注意单位: 亿元 |
| 现任基金最佳回报 | float64 | 注意单位: % |

接口示例-adjust='0'

```python
import akshare as ak

fund_manager_df = ak.fund_manager(adjust='0')
print(fund_manager_df)
```

数据示例-adjust='0'

```
序号 姓名 所属公司 ... 累计从业时间 现任基金资产总规模 现任基金最佳回报
0 1 艾定飞 华商基金 ... 1094 4.55 106.64
1 2 艾小军 国泰基金 ... 2872 735.45 222.26
2 3 安昀 长信基金 ... 2772 41.64 148.20
3 4 彬彬 人保资产 ... 1044 0.55 56.13
4 5 包兵华 鹏华基金 ... 949 62.48 135.83
... ... ... ... ... ... ...
2733 2734 赵治烨 上银基金 ... 2387 13.75 113.12
2734 2735 张子炎 富国基金 ... 908 24.09 24.43
2735 2736 梁策 红土创新基金 ... 170 NaN NaN
2736 2737 宋鑫 中航基金 ... 170 NaN NaN
2737 2738 孙少鹏 华夏基金 ... 40 NaN NaN
```

接口示例-adjust='1'
接口示例

```python
import akshare as ak

fund_manager_df = ak.fund_manager(adjust='1')
print(fund_manager_df)
fund_manager_em_df = ak.fund_manager_em()
print(fund_manager_em_df)
```

数据示例-adjust='1'
数据示例

```
序号 姓名 所属公司 现任基金 累计从业时间 现任基金资产总规模 现任基金最佳回报
0 1 艾定飞 华商基金 华商电子行业量化股票 1094 4.55 106.64
1 1 艾定飞 华商基金 华商计算机行业量化股票 1094 4.55 106.64
2 2 艾小军 国泰基金 国泰黄金ETF联接A 2872 735.45 222.26
3 2 艾小军 国泰基金 国泰黄金ETF联接C 2872 735.45 222.26
4 2 艾小军 国泰基金 国泰量化成长优选混合A 2872 735.45 222.26
... ... ... ... ... ... ...
18328 2735 张子炎 富国基金 富国智鑫行业精选一年封闭股票(FOF-LOF)C 908 24.09 24.43
18329 2735 张子炎 富国基金 富国智鑫行业精选一年封闭股票(FOF-LOF)A 908 24.09 24.43
18330 2736 梁策 红土创新基金 盐港REIT 170 NaN NaN
18331 2737 宋鑫 中航基金 首钢绿能 170 NaN NaN
18332 2738 孙少鹏 华夏基金 华夏越秀高速REIT 40 NaN NaN
序号 姓名 所属公司 现任基金 累计从业时间 现任基金资产总规模 现任基金最佳回报
0 1 安安 中金公司 中金恒瑞债券A 704 34.61 6.19
1 1 安安 中金公司 中金安心回报灵活配置混合A 704 34.61 6.19
2 1 安安 中金公司 中金安心回报灵活配置混合C 704 34.61 6.19
3 1 安安 中金公司 中金恒瑞债券C 704 34.61 6.19
4 2 艾邦妮 华夏基金 华夏红利混合 431 54.88 -12.57
... ... ... ... ... ... ...
25460 3589 祝祯哲 富国基金 富国利享回报12个月持有混合A 216 46.98 -1.67
25461 3589 祝祯哲 富国基金 富国利享回报12个月持有混合C 216 46.98 -1.67
25462 3589 祝祯哲 富国基金 富国可转换债券E 216 46.98 -1.67
25463 3589 祝祯哲 富国基金 富国可转债A 216 46.98 -1.67
25464 3590 周宗舟 汇丰晋信基金 汇丰晋信创新先锋 176 0.68 -1.74
[25465 rows x 7 columns]
```

### 新发基金
Expand Down
2 changes: 1 addition & 1 deletion docs/data/futures/futures.md
Original file line number Diff line number Diff line change
Expand Up @@ -2613,7 +2613,7 @@ print(futures_sgx_daily_df)

接口: futures_main_sina

目标地址: http://vip.stock.finance.sina.com.cn/quotes_service/view/qihuohangqing.html#titlePos_0
目标地址: https://vip.stock.finance.sina.com.cn/quotes_service/view/qihuohangqing.html#titlePos_0

描述: 新浪财经-期货-主力连续合约历史数据

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
"fund_rating_zs" # 基金评级-招商证券评级
"fund_rating_ja" # 基金评级-济安金信评级
# 基金经理
"fund_manager" # 基金经理-基金经理大全
"fund_manager_em" # 基金经理-基金经理大全
# 盈利预测
"stock_profit_forecast_em" # 盈利预测-东财
"stock_profit_forecast_ths" # 盈利预测-同花顺
Expand Down

0 comments on commit d6ba2de

Please sign in to comment.