Skip to content

Commit

Permalink
fix stock_hk_hist
Browse files Browse the repository at this point in the history
  • Loading branch information
albertandking committed Nov 17, 2023
1 parent 3bb9e8d commit 4729f18
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 45 deletions.
14 changes: 8 additions & 6 deletions akshare/stock_feature/stock_hist_em.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,15 +1426,15 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:


def stock_hk_hist(
symbol: str = "40224",
symbol: str = "00593",
period: str = "daily",
start_date: str = "19700101",
end_date: str = "22220101",
adjust: str = "",
) -> pd.DataFrame:
"""
东方财富网-行情-港股-每日行情
http://quote.eastmoney.com/hk/08367.html
https://quote.eastmoney.com/hk/08367.html
:param symbol: 港股-每日行情
:type symbol: str
:param period: choice of {'daily', 'weekly', 'monthly'}
Expand Down Expand Up @@ -1480,7 +1480,7 @@ def stock_hk_hist(
"涨跌额",
"换手率",
]
temp_df.index = pd.to_datetime(temp_df["日期"])
temp_df.index = pd.to_datetime(temp_df["日期"], errors="coerce")
temp_df = temp_df[start_date:end_date]
if temp_df.empty:
return pd.DataFrame()
Expand All @@ -1495,6 +1495,7 @@ def stock_hk_hist(
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_datetime(temp_df['日期'], errors="coerce").dt.date
return temp_df


Expand Down Expand Up @@ -1904,7 +1905,7 @@ def stock_us_hist_min_em(
print(stock_zh_a_hist_pre_min_em_df)

stock_hk_hist_df = stock_hk_hist(
symbol="01246",
symbol="00593",
period="daily",
start_date="19700101",
end_date="22220101",
Expand All @@ -1914,15 +1915,16 @@ def stock_us_hist_min_em(

stock_hk_hist_qfq_df = stock_hk_hist(
symbol="00593",
period="weekly",
period="daily",
start_date="19700101",
end_date="22220101",
adjust="qfq",
)
print(stock_hk_hist_qfq_df)

stock_hk_hist_hfq_df = stock_hk_hist(
symbol="00326",
symbol="00593",
period="daily",
start_date="19700101",
end_date="22220101",
adjust="hfq",
Expand Down
80 changes: 41 additions & 39 deletions docs/data/stock/stock.md
Original file line number Diff line number Diff line change
Expand Up @@ -3920,7 +3920,7 @@ print(stock_hk_hist_min_em_df)

接口: stock_hk_hist

目标地址: http://quote.eastmoney.com/hk/08367.html
目标地址: https://quote.eastmoney.com/hk/08367.html

描述: 港股-历史行情数据, 可以选择返回复权后数据, 更新频率为日频

Expand Down Expand Up @@ -3964,18 +3964,19 @@ print(stock_hk_hist_df)
数据示例-未复权

```
日期 开盘 收盘 最高 最低 ... 成交额 振幅 涨跌幅 涨跌额 换手率
0 1998-01-02 0.64 0.64 0.67 0.62 ... 805000.0 0.00 0.00 0.00 0.45
1 1998-01-05 0.63 0.59 0.63 0.59 ... 2512000.0 6.25 -7.81 -0.05 1.47
2 1998-01-06 0.60 0.60 0.63 0.60 ... 1199000.0 5.08 1.69 0.01 0.69
3 1998-01-07 0.60 0.58 0.60 0.58 ... 1765000.0 3.33 -3.33 -0.02 1.05
4 1998-01-08 0.59 0.58 0.59 0.56 ... 864000.0 5.17 0.00 0.00 0.53
... ... ... ... ... ... ... ... ... ... ...
4536 2021-03-26 1.53 1.53 1.53 1.53 ... 0.0 0.00 0.00 0.00 0.00
4537 2021-03-29 1.53 1.53 1.53 1.53 ... 765.0 0.00 0.00 0.00 0.00
4538 2021-03-30 1.53 1.51 1.53 1.39 ... 106650.0 9.15 -1.31 -0.02 0.03
4539 2021-03-31 1.51 1.51 1.51 1.51 ... 0.0 0.00 0.00 0.00 0.00
4540 2021-06-18 1.60 2.62 3.80 1.60 ... 7104955.0 145.70 73.51 1.11 0.90
日期 开盘 收盘 最高 最低 ... 成交额 振幅 涨跌幅 涨跌额 换手率
0 1998-01-02 0.64 0.64 0.67 0.62 ... 805000.0 0.00 0.00 0.00 0.45
1 1998-01-05 0.63 0.59 0.63 0.59 ... 2512000.0 6.25 -7.81 -0.05 1.47
2 1998-01-06 0.60 0.60 0.63 0.60 ... 1199000.0 5.08 1.69 0.01 0.69
3 1998-01-07 0.60 0.58 0.60 0.58 ... 1765000.0 3.33 -3.33 -0.02 1.05
4 1998-01-08 0.59 0.58 0.59 0.56 ... 864000.0 5.17 0.00 0.00 0.53
... ... ... ... ... ... ... ... ... ... ...
4770 2023-11-13 1.80 1.39 1.80 1.30 ... 85720.0 31.65 -12.03 -0.19 0.02
4771 2023-11-14 1.31 1.26 1.58 1.10 ... 18368185.0 34.53 -9.35 -0.13 5.09
4772 2023-11-15 1.40 1.35 1.40 1.23 ... 20318650.0 13.49 7.14 0.09 5.35
4773 2023-11-16 1.35 1.38 1.39 1.34 ... 15420060.0 3.70 2.22 0.03 4.00
4774 2023-11-17 1.38 1.47 1.47 1.38 ... 7020800.0 6.52 6.52 0.09 1.74
[4775 rows x 11 columns]
```

输出参数-前复权
Expand Down Expand Up @@ -4006,18 +4007,19 @@ print(stock_hk_hist_qfq_df)
数据示例-前复权

```
日期 开盘 收盘 最高 ... 振幅 涨跌幅 涨跌额 换手率
0 1998-01-02 1.713 1.713 1.863 ... 0.00 0.00 0.00 0.45
1 1998-01-05 1.663 1.463 1.663 ... 11.68 -14.59 -0.25 1.47
2 1998-01-06 1.513 1.513 1.663 ... 10.25 3.42 0.05 0.69
3 1998-01-07 1.513 1.413 1.513 ... 6.61 -6.61 -0.10 1.05
4 1998-01-08 1.463 1.413 1.463 ... 10.62 0.00 0.00 0.53
... ... ... ... ... ... ... ... ...
4536 2021-03-26 1.530 1.530 1.530 ... 0.00 0.00 0.00 0.00
4537 2021-03-29 1.530 1.530 1.530 ... 0.00 0.00 0.00 0.00
4538 2021-03-30 1.530 1.510 1.530 ... 9.15 -1.31 -0.02 0.03
4539 2021-03-31 1.510 1.510 1.510 ... 0.00 0.00 0.00 0.00
4540 2021-06-18 1.600 2.620 3.800 ... 145.70 73.51 1.11 0.90
日期 开盘 收盘 最高 ... 振幅 涨跌幅 涨跌额 换手率
0 1998-01-02 1.713 1.713 1.863 ... 0.00 0.00 0.00 0.45
1 1998-01-05 1.663 1.463 1.663 ... 11.68 -14.59 -0.25 1.47
2 1998-01-06 1.513 1.513 1.663 ... 10.25 3.42 0.05 0.69
3 1998-01-07 1.513 1.413 1.513 ... 6.61 -6.61 -0.10 1.05
4 1998-01-08 1.463 1.413 1.463 ... 10.62 0.00 0.00 0.53
... ... ... ... ... ... ... ... ...
4770 2023-11-13 1.800 1.390 1.800 ... 31.65 -12.03 -0.19 0.02
4771 2023-11-14 1.310 1.260 1.580 ... 34.53 -9.35 -0.13 5.09
4772 2023-11-15 1.400 1.350 1.400 ... 13.49 7.14 0.09 5.35
4773 2023-11-16 1.350 1.380 1.390 ... 3.70 2.22 0.03 4.00
4774 2023-11-17 1.380 1.470 1.470 ... 6.52 6.52 0.09 1.74
[4775 rows x 11 columns]
```

输出参数-后复权
Expand All @@ -4041,26 +4043,26 @@ print(stock_hk_hist_qfq_df)
```python
import akshare as ak

stock_hk_hist_hfq_df = ak.stock_hk_hist(symbol="00593", period="daily", start_date="19700101", end_date="22220101",
adjust="hfq")
stock_hk_hist_hfq_df = ak.stock_hk_hist(symbol="00593", period="daily", start_date="19700101", end_date="22220101", adjust="hfq")
print(stock_hk_hist_hfq_df)
```

数据示例-后复权

```
日期 开盘 收盘 最高 ... 振幅 涨跌幅 涨跌额 换手率
0 1998-01-02 0.715 0.715 0.745 ... 0.00 0.00 0.000 0.45
1 1998-01-05 0.705 0.665 0.705 ... 5.59 -6.99 -0.050 1.47
2 1998-01-06 0.675 0.675 0.705 ... 4.51 1.50 0.010 0.69
3 1998-01-07 0.675 0.655 0.675 ... 2.96 -2.96 -0.020 1.05
4 1998-01-08 0.665 0.655 0.665 ... 4.58 0.00 0.000 0.53
... ... ... ... ... ... ... ... ...
4536 2021-03-26 0.679 0.679 0.679 ... 0.00 0.00 0.000 0.00
4537 2021-03-29 0.679 0.679 0.679 ... 0.00 0.00 0.000 0.00
4538 2021-03-30 0.679 0.675 0.679 ... 4.12 -0.59 -0.004 0.03
4539 2021-03-31 0.675 0.675 0.675 ... 0.00 0.00 0.000 0.00
4540 2021-06-18 0.693 0.897 1.133 ... 65.19 32.89 0.222 0.90
日期 开盘 收盘 最高 ... 振幅 涨跌幅 涨跌额 换手率
0 1998-01-02 0.715 0.715 0.745 ... 0.00 0.00 0.000 0.45
1 1998-01-05 0.705 0.665 0.705 ... 5.59 -6.99 -0.050 1.47
2 1998-01-06 0.675 0.675 0.705 ... 4.51 1.50 0.010 0.69
3 1998-01-07 0.675 0.655 0.675 ... 2.96 -2.96 -0.020 1.05
4 1998-01-08 0.665 0.655 0.665 ... 4.58 0.00 0.000 0.53
... ... ... ... ... ... ... ... ...
4770 2023-11-13 0.733 0.651 0.733 ... 14.51 -5.52 -0.038 0.02
4771 2023-11-14 0.635 0.625 0.689 ... 14.75 -3.99 -0.026 5.09
4772 2023-11-15 0.653 0.643 0.653 ... 5.44 2.88 0.018 5.35
4773 2023-11-16 0.643 0.649 0.651 ... 1.56 0.93 0.006 4.00
4774 2023-11-17 0.649 0.667 0.667 ... 2.77 2.77 0.018 1.74
[4775 rows x 11 columns]
```

#### 历史行情数据-新浪
Expand Down

0 comments on commit 4729f18

Please sign in to comment.