akshare 1.12.95__py3-none-any.whl → 1.15.72__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of akshare might be problematic. Click here for more details.
- akshare/__init__.py +446 -139
- akshare/air/air_hebei.py +79 -53
- akshare/air/air_zhenqi.py +29 -43
- akshare/air/sunrise_tad.py +32 -17
- akshare/bank/bank_cbirc_2020.py +12 -9
- akshare/bond/bond_cb_ths.py +17 -9
- akshare/bond/bond_china.py +38 -39
- akshare/bond/bond_china_money.py +75 -48
- akshare/bond/bond_convert.py +40 -16
- akshare/bond/bond_info_cm.py +28 -8
- akshare/bond/bond_issue_cninfo.py +73 -30
- akshare/bond/{bond_zh_cov_sina.py → bond_zh_cov.py} +41 -17
- akshare/bond/bond_zh_sina.py +57 -51
- akshare/cal/__init__.py +0 -0
- akshare/cal/rv.py +170 -0
- akshare/cost/cost_living.py +7 -5
- akshare/currency/currency_safe.py +7 -6
- akshare/data/cninfo.js +15 -0
- akshare/datasets.py +10 -21
- akshare/economic/macro_bank.py +95 -653
- akshare/economic/macro_china.py +772 -1024
- akshare/economic/macro_china_hk.py +65 -243
- akshare/economic/macro_china_nbs.py +24 -7
- akshare/economic/macro_constitute.py +17 -12
- akshare/economic/macro_euro.py +13 -6
- akshare/economic/macro_finance_ths.py +133 -0
- akshare/economic/macro_info_ws.py +100 -0
- akshare/economic/macro_japan.py +5 -4
- akshare/economic/macro_other.py +12 -9
- akshare/economic/macro_usa.py +376 -1940
- akshare/economic/marco_cnbs.py +11 -6
- akshare/energy/energy_carbon.py +94 -125
- akshare/event/migration.py +3 -2
- akshare/exceptions.py +43 -0
- akshare/file_fold/calendar.json +245 -2
- akshare/fortune/fortune_500.py +15 -48
- akshare/fund/fund_amac.py +157 -75
- akshare/fund/fund_em.py +191 -184
- akshare/fund/fund_etf_em.py +20 -19
- akshare/fund/fund_etf_sina.py +71 -23
- akshare/fund/fund_etf_ths.py +93 -0
- akshare/fund/fund_fee_em.py +98 -0
- akshare/fund/fund_lof_em.py +10 -8
- akshare/fund/fund_portfolio_em.py +60 -50
- akshare/fund/fund_rank_em.py +91 -82
- akshare/fund/fund_report_cninfo.py +63 -48
- akshare/fund/fund_scale_sina.py +20 -10
- akshare/fund/fund_xq.py +139 -109
- akshare/futures/cons.py +8 -31
- akshare/futures/cot.py +185 -137
- akshare/futures/futures_basis.py +97 -32
- akshare/futures/futures_comm_ctp.py +37 -0
- akshare/futures/futures_comm_qihuo.py +74 -45
- akshare/futures/futures_daily_bar.py +121 -184
- akshare/futures/futures_hf_em.py +66 -61
- akshare/futures/futures_hq_sina.py +79 -61
- akshare/futures/futures_index_ccidx.py +6 -3
- akshare/futures/futures_inventory_99.py +61 -272
- akshare/futures/futures_news_shmet.py +4 -2
- akshare/futures/futures_roll_yield.py +12 -25
- akshare/futures/futures_spot_stock_em.py +19 -13
- akshare/futures/futures_stock_js.py +14 -12
- akshare/futures/futures_to_spot.py +38 -33
- akshare/futures/futures_warehouse_receipt.py +75 -71
- akshare/futures/futures_zh_sina.py +73 -50
- akshare/futures/symbol_var.py +18 -13
- akshare/futures_derivative/futures_contract_info_czce.py +60 -52
- akshare/futures_derivative/futures_contract_info_ine.py +43 -34
- akshare/futures_derivative/futures_contract_info_shfe.py +46 -35
- akshare/futures_derivative/futures_cot_sina.py +26 -19
- akshare/futures_derivative/futures_spot_sys.py +21 -8
- akshare/fx/currency_investing.py +19 -285
- akshare/index/index_cflp.py +29 -26
- akshare/index/index_cni.py +86 -88
- akshare/index/index_cons.py +26 -10
- akshare/index/index_cx.py +248 -47
- akshare/index/index_drewry.py +17 -16
- akshare/index/index_hog.py +27 -26
- akshare/index/index_option_qvix.py +329 -0
- akshare/index/index_research_fund_sw.py +134 -0
- akshare/index/{index_sw_research.py → index_research_sw.py} +122 -58
- akshare/index/index_spot.py +9 -5
- akshare/index/index_stock_hk.py +35 -16
- akshare/index/index_stock_us_sina.py +1 -1
- akshare/index/index_stock_zh.py +180 -89
- akshare/index/index_stock_zh_csindex.py +15 -369
- akshare/index/index_sw.py +62 -34
- akshare/index/index_yw.py +46 -23
- akshare/index/index_zh_a_scope.py +48 -0
- akshare/index/index_zh_em.py +17 -14
- akshare/interest_rate/interbank_rate_em.py +14 -9
- akshare/movie/artist_yien.py +32 -5
- akshare/movie/movie_yien.py +92 -18
- akshare/movie/video_yien.py +28 -5
- akshare/news/news_baidu.py +78 -44
- akshare/news/news_cctv.py +38 -38
- akshare/news/news_stock.py +6 -3
- akshare/nlp/nlp_interface.py +7 -8
- akshare/option/cons.py +11 -11
- akshare/option/option_comm_qihuo.py +86 -0
- akshare/option/option_commodity.py +178 -51
- akshare/option/option_daily_stats_sse_szse.py +146 -0
- akshare/option/option_em.py +147 -138
- akshare/option/option_finance_sina.py +160 -137
- akshare/option/option_lhb_em.py +62 -56
- akshare/option/option_risk_indicator_sse.py +17 -14
- akshare/other/other_car_cpca.py +934 -0
- akshare/other/{other_car.py → other_car_gasgoo.py} +15 -54
- akshare/qdii/__init__.py +0 -0
- akshare/qdii/qdii_jsl.py +233 -0
- akshare/request.py +117 -0
- akshare/spot/spot_hog_soozhu.py +232 -0
- akshare/spot/spot_price_qh.py +121 -0
- akshare/spot/spot_sge.py +63 -10
- akshare/stock/stock_allotment_cninfo.py +10 -9
- akshare/stock/stock_ask_bid_em.py +27 -3
- akshare/stock/stock_board_concept_em.py +23 -14
- akshare/stock/stock_board_industry_em.py +40 -34
- akshare/stock/stock_cg_equity_mortgage.py +15 -11
- akshare/stock/stock_cg_guarantee.py +41 -51
- akshare/stock/stock_cg_lawsuit.py +36 -35
- akshare/stock/stock_dividend_cninfo.py +12 -6
- akshare/stock/stock_dzjy_em.py +347 -260
- akshare/stock/stock_fund_em.py +332 -84
- akshare/stock/stock_hk_famous.py +108 -0
- akshare/stock/stock_hk_sina.py +8 -7
- akshare/stock/stock_hold_control_cninfo.py +100 -15
- akshare/stock/stock_hold_control_em.py +4 -3
- akshare/stock/stock_hold_num_cninfo.py +18 -12
- akshare/stock/stock_hot_rank_em.py +2 -1
- akshare/stock/stock_hot_search_baidu.py +5 -2
- akshare/stock/stock_industry_cninfo.py +24 -18
- akshare/stock/stock_industry_pe_cninfo.py +45 -31
- akshare/stock/stock_industry_sw.py +9 -10
- akshare/stock/stock_info.py +25 -15
- akshare/stock/stock_info_em.py +5 -2
- akshare/stock/stock_intraday_em.py +5 -2
- akshare/stock/stock_intraday_sina.py +22 -18
- akshare/stock/stock_ipo_summary_cninfo.py +25 -10
- akshare/stock/stock_new_cninfo.py +32 -19
- akshare/stock/stock_news_cx.py +39 -0
- akshare/stock/stock_profile_cninfo.py +9 -8
- akshare/stock/stock_rank_forecast.py +8 -6
- akshare/stock/stock_share_changes_cninfo.py +18 -14
- akshare/stock/stock_share_hold.py +24 -19
- akshare/stock/stock_summary.py +54 -26
- akshare/stock/stock_us_famous.py +15 -6
- akshare/stock/stock_us_pink.py +7 -5
- akshare/stock/stock_us_sina.py +15 -12
- akshare/stock/stock_xq.py +38 -12
- akshare/stock/stock_zh_a_sina.py +53 -78
- akshare/stock/stock_zh_b_sina.py +32 -55
- akshare/stock/stock_zh_kcb_report.py +11 -9
- akshare/stock/stock_zh_kcb_sina.py +67 -64
- akshare/stock_feature/stock_a_below_net_asset_statistics.py +5 -2
- akshare/stock_feature/stock_a_high_low.py +5 -2
- akshare/stock_feature/stock_a_indicator.py +12 -9
- akshare/stock_feature/stock_a_pe_and_pb.py +27 -6
- akshare/stock_feature/stock_account_em.py +58 -40
- akshare/stock_feature/stock_analyst_em.py +36 -27
- akshare/stock_feature/stock_board_industry_ths.py +136 -400
- akshare/stock_feature/stock_comment_em.py +118 -85
- akshare/stock_feature/stock_concept_futu.py +183 -0
- akshare/stock_feature/stock_cyq_em.py +58 -54
- akshare/stock_feature/stock_disclosure_cninfo.py +147 -102
- akshare/stock_feature/stock_esg_sina.py +216 -11
- akshare/stock_feature/stock_fhps_em.py +60 -25
- akshare/stock_feature/stock_fhps_ths.py +25 -6
- akshare/stock_feature/stock_fund_flow.py +38 -25
- akshare/stock_feature/stock_gdfx_em.py +180 -95
- akshare/stock_feature/stock_gdhs.py +73 -49
- akshare/stock_feature/stock_gpzy_em.py +78 -46
- akshare/stock_feature/stock_hist_em.py +164 -111
- akshare/stock_feature/stock_hk_valuation_baidu.py +20 -8
- akshare/stock_feature/stock_hsgt_em.py +184 -452
- akshare/stock_feature/stock_info.py +52 -29
- akshare/stock_feature/stock_inner_trade_xq.py +39 -31
- akshare/stock_feature/stock_irm_cninfo.py +32 -9
- akshare/stock_feature/stock_jgdy_em.py +41 -38
- akshare/stock_feature/stock_lh_yybpm.py +36 -37
- akshare/stock_feature/stock_lhb_em.py +135 -71
- akshare/stock_feature/stock_lhb_sina.py +93 -46
- akshare/stock_feature/stock_margin_em.py +102 -0
- akshare/stock_feature/{stock_sse_margin.py → stock_margin_sse.py} +21 -15
- akshare/stock_feature/{stock_szse_margin.py → stock_margin_szse.py} +23 -19
- akshare/stock_feature/stock_market_legu.py +13 -8
- akshare/stock_feature/stock_pankou_em.py +72 -34
- akshare/stock_feature/stock_report_em.py +244 -54
- akshare/stock_feature/stock_research_report_em.py +48 -19
- akshare/stock_feature/stock_sns_sseinfo.py +15 -12
- akshare/stock_feature/stock_sy_em.py +86 -33
- akshare/stock_feature/stock_technology_ths.py +152 -120
- akshare/stock_feature/stock_tfp_em.py +35 -13
- akshare/stock_feature/stock_three_report_em.py +119 -77
- akshare/stock_feature/stock_ttm_lyr.py +4 -7
- akshare/stock_feature/stock_value_em.py +83 -0
- akshare/stock_feature/stock_wencai.py +21 -9
- akshare/stock_feature/stock_yjyg_em.py +63 -28
- akshare/stock_feature/stock_zf_pg.py +61 -38
- akshare/stock_feature/stock_zh_valuation_baidu.py +3 -2
- akshare/stock_feature/stock_ztb_em.py +62 -40
- akshare/stock_fundamental/stock_finance.py +150 -58
- akshare/stock_fundamental/stock_finance_ths.py +116 -31
- akshare/stock_fundamental/stock_mda_ym.py +5 -3
- akshare/stock_fundamental/stock_notice.py +29 -15
- akshare/stock_fundamental/stock_profit_forecast_em.py +31 -13
- akshare/stock_fundamental/stock_profit_forecast_ths.py +19 -10
- akshare/stock_fundamental/stock_register_em.py +448 -0
- akshare/stock_fundamental/stock_restricted_em.py +79 -32
- akshare/stock_fundamental/stock_zygc.py +10 -8
- akshare/stock_fundamental/stock_zyjs_ths.py +5 -3
- akshare/tool/trade_date_hist.py +4 -3
- akshare/utils/cons.py +10 -0
- akshare/utils/context.py +43 -0
- akshare/utils/demjson.py +2 -2
- akshare/utils/func.py +26 -0
- akshare/utils/tqdm.py +13 -3
- {akshare-1.12.95.dist-info → akshare-1.15.72.dist-info}/METADATA +52 -69
- akshare-1.15.72.dist-info/RECORD +385 -0
- {akshare-1.12.95.dist-info → akshare-1.15.72.dist-info}/WHEEL +1 -1
- tests/test_func.py +3 -5
- akshare/bond/bond_futures.py +0 -50
- akshare/bond/bond_investing.py +0 -139
- akshare/crypto/crypto_hist_investing.py +0 -249
- akshare/fortune/fortune_it_juzi.py +0 -123
- akshare/futures/futures_international.py +0 -170
- akshare/futures/futures_news_baidu.py +0 -54
- akshare/futures/inventory_data.py +0 -100
- akshare/futures_derivative/futures_index_price_nh.py +0 -61
- akshare/futures_derivative/futures_index_return_nh.py +0 -47
- akshare/futures_derivative/futures_index_volatility_nh.py +0 -51
- akshare/futures_derivative/futures_other_index_nh.py +0 -145
- akshare/index/index_fear_greed_funddb.py +0 -71
- akshare/index/index_investing.py +0 -232
- akshare/sport/sport_olympic_winter.py +0 -39
- akshare/stock_feature/stock_board_concept_ths.py +0 -422
- akshare/stock_fundamental/stock_register.py +0 -292
- akshare-1.12.95.dist-info/RECORD +0 -374
- {akshare-1.12.95.dist-info → akshare-1.15.72.dist-info}/LICENSE +0 -0
- {akshare-1.12.95.dist-info → akshare-1.15.72.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding:utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Date: 2024/7/5 15:00
|
|
5
|
+
Desc: 九期网-商品期权手续费
|
|
6
|
+
https://www.9qihuo.com/qiquanshouxufei
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from functools import lru_cache
|
|
10
|
+
from io import StringIO
|
|
11
|
+
|
|
12
|
+
import pandas as pd
|
|
13
|
+
import requests
|
|
14
|
+
from bs4 import BeautifulSoup
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@lru_cache()
|
|
18
|
+
def option_comm_symbol() -> pd.DataFrame:
|
|
19
|
+
import urllib3
|
|
20
|
+
|
|
21
|
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
22
|
+
url = "https://www.9qihuo.com/qiquanshouxufei"
|
|
23
|
+
r = requests.get(url, verify=False)
|
|
24
|
+
soup = BeautifulSoup(r.text, features="lxml")
|
|
25
|
+
name = [
|
|
26
|
+
item.string.strip()
|
|
27
|
+
for item in soup.find(name="div", attrs={"id": "inst_list"}).find_all(name="a")
|
|
28
|
+
]
|
|
29
|
+
code = [
|
|
30
|
+
item["href"].split("?")[1].split("=")[1]
|
|
31
|
+
for item in soup.find(name="div", attrs={"id": "inst_list"}).find_all(name="a")
|
|
32
|
+
]
|
|
33
|
+
temp_df = pd.DataFrame([name, code]).T
|
|
34
|
+
temp_df.columns = ["品种名称", "品种代码"]
|
|
35
|
+
return temp_df
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def option_comm_info(symbol: str = "工业硅期权") -> pd.DataFrame:
|
|
39
|
+
"""
|
|
40
|
+
九期网-商品期权手续费
|
|
41
|
+
https://www.9qihuo.com/qiquanshouxufei
|
|
42
|
+
:param symbol: choice of {"所有", "上海期货交易所", "大连商品交易所", "郑州商品交易所", "上海国际能源交易中心", "广州期货交易所"}
|
|
43
|
+
:type symbol: str
|
|
44
|
+
:return: 期权手续费
|
|
45
|
+
:rtype: pandas.DataFrame
|
|
46
|
+
"""
|
|
47
|
+
import urllib3
|
|
48
|
+
|
|
49
|
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
50
|
+
symbol_df = option_comm_symbol()
|
|
51
|
+
symbol_str = symbol_df[symbol_df["品种名称"].str.contains(symbol)][
|
|
52
|
+
"品种代码"
|
|
53
|
+
].values[0]
|
|
54
|
+
params = {"heyue": symbol_str}
|
|
55
|
+
url = "https://www.9qihuo.com/qiquanshouxufei"
|
|
56
|
+
r = requests.get(url, params=params, verify=False)
|
|
57
|
+
temp_df = pd.read_html(StringIO(r.text))[0]
|
|
58
|
+
market_symbol = temp_df.iloc[0, 0]
|
|
59
|
+
columns = temp_df.iloc[2, :]
|
|
60
|
+
temp_df = temp_df.iloc[3:, :]
|
|
61
|
+
temp_df.columns = columns
|
|
62
|
+
temp_df["交易所"] = market_symbol
|
|
63
|
+
temp_df.reset_index(drop=True, inplace=True)
|
|
64
|
+
temp_df.index.name = None
|
|
65
|
+
temp_df.columns.name = None
|
|
66
|
+
temp_df["现价"] = pd.to_numeric(temp_df["现价"], errors="coerce")
|
|
67
|
+
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
|
|
68
|
+
temp_df["每跳毛利/元"] = pd.to_numeric(temp_df["每跳毛利/元"], errors="coerce")
|
|
69
|
+
temp_df["每跳净利/元"] = pd.to_numeric(temp_df["每跳净利/元"], errors="coerce")
|
|
70
|
+
soup = BeautifulSoup(r.text, features="lxml")
|
|
71
|
+
raw_date_text = soup.find(name="a", attrs={"id": "dlink"}).previous
|
|
72
|
+
comm_update_time = raw_date_text.split(",")[0].strip("(手续费更新时间:")
|
|
73
|
+
price_update_time = (
|
|
74
|
+
raw_date_text.split(",")[1].strip("价格更新时间:").strip("。)")
|
|
75
|
+
)
|
|
76
|
+
temp_df["手续费更新时间"] = comm_update_time
|
|
77
|
+
temp_df["价格更新时间"] = price_update_time
|
|
78
|
+
return temp_df
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
if __name__ == "__main__":
|
|
82
|
+
option_comm_symbol_df = option_comm_symbol()
|
|
83
|
+
print(option_comm_symbol_df)
|
|
84
|
+
|
|
85
|
+
option_comm_info_df = option_comm_info(symbol="工业硅期权")
|
|
86
|
+
print(option_comm_info_df)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding:utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
Date:
|
|
4
|
+
Date: 2024/7/19 14:00
|
|
5
5
|
Desc: 商品期权数据
|
|
6
6
|
说明:
|
|
7
7
|
(1) 价格:自2019年12月02日起,纤维板报价单位由元/张改为元/立方米
|
|
@@ -13,10 +13,11 @@ Desc: 商品期权数据
|
|
|
13
13
|
(7) 合约系列:具有相同月份标的期货合约的所有期权合约的统称
|
|
14
14
|
(8) 隐含波动率:根据期权市场价格,利用期权定价模型计算的标的期货合约价格波动率
|
|
15
15
|
"""
|
|
16
|
+
|
|
16
17
|
import datetime
|
|
17
18
|
import warnings
|
|
18
19
|
from io import StringIO, BytesIO
|
|
19
|
-
from typing import Tuple, Any
|
|
20
|
+
from typing import Tuple, Any, Optional
|
|
20
21
|
|
|
21
22
|
import pandas as pd
|
|
22
23
|
import requests
|
|
@@ -32,14 +33,16 @@ from akshare.option.cons import (
|
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
def option_dce_daily(
|
|
35
|
-
|
|
36
|
-
) -> Tuple[Any, Any]:
|
|
36
|
+
symbol: str = "聚乙烯期权", trade_date: str = "20210728"
|
|
37
|
+
) -> Optional[Tuple[Any, Any]]:
|
|
37
38
|
"""
|
|
38
39
|
大连商品交易所-期权-日频行情数据
|
|
39
40
|
http://www.dce.com.cn/
|
|
40
41
|
:param trade_date: 交易日
|
|
41
42
|
:type trade_date: str
|
|
42
|
-
:param symbol: choice of {"玉米期权", "豆粕期权", "铁矿石期权", "液化石油气期权", "聚乙烯期权", "聚氯乙烯期权",
|
|
43
|
+
:param symbol: choice of {"玉米期权", "豆粕期权", "铁矿石期权", "液化石油气期权", "聚乙烯期权", "聚氯乙烯期权",
|
|
44
|
+
"聚丙烯期权", "棕榈油期权", "黄大豆1号期权", "黄大豆2号期权", "豆油期权", "乙二醇期权", "苯乙烯期权",
|
|
45
|
+
"鸡蛋期权", "玉米淀粉期权", "生猪期权"}
|
|
43
46
|
:type symbol: str
|
|
44
47
|
:return: 日频行情数据
|
|
45
48
|
:rtype: pandas.DataFrame
|
|
@@ -61,12 +64,14 @@ def option_dce_daily(
|
|
|
61
64
|
res = requests.post(url, data=payload)
|
|
62
65
|
table_df = pd.read_excel(BytesIO(res.content), header=1)
|
|
63
66
|
another_df = table_df.iloc[
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
table_df[table_df.iloc[:, 0].str.contains("合约")].iloc[-1].name :,
|
|
68
|
+
[0, 1],
|
|
69
|
+
]
|
|
67
70
|
another_df.reset_index(inplace=True, drop=True)
|
|
68
71
|
another_df.columns = another_df.iloc[0]
|
|
69
72
|
another_df = another_df.iloc[1:, :]
|
|
73
|
+
result_one_df = pd.DataFrame()
|
|
74
|
+
result_two_df = pd.DataFrame()
|
|
70
75
|
if symbol == "豆粕期权":
|
|
71
76
|
result_one_df, result_two_df = (
|
|
72
77
|
table_df[table_df["商品名称"] == "豆粕"],
|
|
@@ -75,7 +80,7 @@ def option_dce_daily(
|
|
|
75
80
|
elif symbol == "玉米期权":
|
|
76
81
|
result_one_df, result_two_df = (
|
|
77
82
|
table_df[table_df["商品名称"] == "玉米"],
|
|
78
|
-
another_df[another_df.iloc[:, 0].str.contains("c")],
|
|
83
|
+
another_df[another_df.iloc[:, 0].str.contains(r"^c\d")],
|
|
79
84
|
)
|
|
80
85
|
elif symbol == "铁矿石期权":
|
|
81
86
|
result_one_df, result_two_df = (
|
|
@@ -132,21 +137,80 @@ def option_dce_daily(
|
|
|
132
137
|
table_df[table_df["商品名称"] == "苯乙烯"],
|
|
133
138
|
another_df[another_df.iloc[:, 0].str.contains("eb")],
|
|
134
139
|
)
|
|
140
|
+
elif symbol == "鸡蛋期权":
|
|
141
|
+
result_one_df, result_two_df = (
|
|
142
|
+
table_df[table_df["商品名称"] == "鸡蛋"],
|
|
143
|
+
another_df[another_df.iloc[:, 0].str.contains("jd")],
|
|
144
|
+
)
|
|
145
|
+
elif symbol == "玉米淀粉期权":
|
|
146
|
+
result_one_df, result_two_df = (
|
|
147
|
+
table_df[table_df["商品名称"] == "玉米淀粉"],
|
|
148
|
+
another_df[another_df.iloc[:, 0].str.contains("cs")],
|
|
149
|
+
)
|
|
150
|
+
elif symbol == "生猪期权":
|
|
151
|
+
result_one_df, result_two_df = (
|
|
152
|
+
table_df[table_df["商品名称"] == "生猪"],
|
|
153
|
+
another_df[another_df.iloc[:, 0].str.contains("lh")],
|
|
154
|
+
)
|
|
155
|
+
elif symbol == "原木期权":
|
|
156
|
+
result_one_df, result_two_df = (
|
|
157
|
+
table_df[table_df["商品名称"] == "原木"],
|
|
158
|
+
another_df[another_df.iloc[:, 0].str.contains("lg")],
|
|
159
|
+
)
|
|
135
160
|
result_one_df.reset_index(inplace=True, drop=True)
|
|
136
161
|
result_two_df.reset_index(inplace=True, drop=True)
|
|
137
162
|
result_two_df.columns.name = None
|
|
138
163
|
return result_one_df, result_two_df
|
|
139
164
|
|
|
140
165
|
|
|
166
|
+
def __option_czce_daily_convert_numeric_columns(df):
|
|
167
|
+
# 定义要处理的列
|
|
168
|
+
columns_to_convert = [
|
|
169
|
+
"昨结算",
|
|
170
|
+
"今开盘",
|
|
171
|
+
"最高价",
|
|
172
|
+
"最低价",
|
|
173
|
+
"今收盘",
|
|
174
|
+
"今结算",
|
|
175
|
+
"涨跌1",
|
|
176
|
+
"涨跌2",
|
|
177
|
+
"成交量(手)",
|
|
178
|
+
"持仓量",
|
|
179
|
+
"增减量",
|
|
180
|
+
"成交额(万元)",
|
|
181
|
+
"DELTA",
|
|
182
|
+
"隐含波动率",
|
|
183
|
+
"行权量",
|
|
184
|
+
]
|
|
185
|
+
|
|
186
|
+
# 转换函数:去除逗号并转换为float
|
|
187
|
+
def convert_to_float(x):
|
|
188
|
+
try:
|
|
189
|
+
return float(str(x).replace(",", ""))
|
|
190
|
+
except: # noqa: E722
|
|
191
|
+
return x
|
|
192
|
+
|
|
193
|
+
# 创建DataFrame的副本以避免SettingWithCopyWarning
|
|
194
|
+
df_copy = df.copy()
|
|
195
|
+
df_copy.columns = [item.strip() for item in df_copy]
|
|
196
|
+
# 应用转换
|
|
197
|
+
for col in columns_to_convert:
|
|
198
|
+
df_copy[col] = df_copy[col].apply(convert_to_float)
|
|
199
|
+
|
|
200
|
+
return df_copy
|
|
201
|
+
|
|
202
|
+
|
|
141
203
|
def option_czce_daily(
|
|
142
|
-
|
|
204
|
+
symbol: str = "白糖期权", trade_date: str = "20191017"
|
|
143
205
|
) -> pd.DataFrame:
|
|
144
206
|
"""
|
|
145
207
|
郑州商品交易所-期权-日频行情数据
|
|
146
|
-
|
|
208
|
+
http://www.czce.com.cn/cn/sspz/dejbqhqq/H770227index_1.htm#tabs-2
|
|
147
209
|
:param trade_date: 交易日
|
|
148
210
|
:type trade_date: str
|
|
149
|
-
:param symbol: choice of {"白糖期权", "棉花期权", "甲醇期权", "PTA期权",
|
|
211
|
+
:param symbol: choice of {"白糖期权", "棉花期权", "甲醇期权", "PTA期权", "菜籽粕期权", "动力煤期权", "短纤期权",
|
|
212
|
+
"菜籽油期权", "花生期权", "纯碱期权", "锰硅期权", "硅铁期权", "尿素期权", "对二甲苯期权", "苹果期权", "红枣期权"
|
|
213
|
+
"烧碱期权", "玻璃期权", "瓶片期权"}
|
|
150
214
|
:type symbol: str
|
|
151
215
|
:return: 日频行情数据
|
|
152
216
|
:rtype: pandas.DataFrame
|
|
@@ -156,7 +220,7 @@ def option_czce_daily(
|
|
|
156
220
|
if day.strftime("%Y%m%d") not in calendar:
|
|
157
221
|
warnings.warn("{}非交易日".format(day.strftime("%Y%m%d")))
|
|
158
222
|
return pd.DataFrame()
|
|
159
|
-
if day > datetime.date(2010, 8, 24):
|
|
223
|
+
if day > datetime.date(year=2010, month=8, day=24):
|
|
160
224
|
url = CZCE_DAILY_OPTION_URL_3.format(day.strftime("%Y"), day.strftime("%Y%m%d"))
|
|
161
225
|
try:
|
|
162
226
|
r = requests.get(url)
|
|
@@ -165,68 +229,127 @@ def option_czce_daily(
|
|
|
165
229
|
if symbol == "白糖期权":
|
|
166
230
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SR")]
|
|
167
231
|
temp_df.reset_index(inplace=True, drop=True)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
232
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
233
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
234
|
+
return new_df
|
|
235
|
+
elif symbol == "棉花期权":
|
|
236
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("CF")]
|
|
171
237
|
temp_df.reset_index(inplace=True, drop=True)
|
|
172
|
-
|
|
238
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
239
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
240
|
+
return new_df
|
|
173
241
|
elif symbol == "甲醇期权":
|
|
174
242
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("MA")]
|
|
175
243
|
temp_df.reset_index(inplace=True, drop=True)
|
|
176
|
-
|
|
244
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
245
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
246
|
+
return new_df
|
|
247
|
+
elif symbol == "PTA期权":
|
|
248
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("TA")]
|
|
249
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
250
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
251
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
252
|
+
return new_df
|
|
177
253
|
elif symbol == "菜籽粕期权":
|
|
178
254
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("RM")]
|
|
179
255
|
temp_df.reset_index(inplace=True, drop=True)
|
|
180
|
-
|
|
256
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
257
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
258
|
+
return new_df
|
|
181
259
|
elif symbol == "动力煤期权":
|
|
182
260
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("ZC")]
|
|
183
261
|
temp_df.reset_index(inplace=True, drop=True)
|
|
184
|
-
|
|
262
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
263
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
264
|
+
return new_df
|
|
265
|
+
elif symbol == "短纤期权":
|
|
266
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("PF")]
|
|
267
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
268
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
269
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
270
|
+
return new_df
|
|
185
271
|
elif symbol == "菜籽油期权":
|
|
186
272
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("OI")]
|
|
187
273
|
temp_df.reset_index(inplace=True, drop=True)
|
|
188
|
-
|
|
274
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
275
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
276
|
+
return new_df
|
|
189
277
|
elif symbol == "花生期权":
|
|
190
278
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("PK")]
|
|
191
279
|
temp_df.reset_index(inplace=True, drop=True)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
temp_df.reset_index(inplace=True, drop=True)
|
|
196
|
-
return temp_df.iloc[:-1, :]
|
|
197
|
-
elif symbol == "短纤期权":
|
|
198
|
-
temp_df = table_df[table_df.iloc[:, 0].str.contains("PF")]
|
|
199
|
-
temp_df.reset_index(inplace=True, drop=True)
|
|
200
|
-
return temp_df.iloc[:-1, :]
|
|
280
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
281
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
282
|
+
return new_df
|
|
201
283
|
elif symbol == "纯碱期权":
|
|
202
284
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SA")]
|
|
203
285
|
temp_df.reset_index(inplace=True, drop=True)
|
|
204
|
-
|
|
286
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
287
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
288
|
+
return new_df
|
|
205
289
|
elif symbol == "锰硅期权":
|
|
206
290
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SM")]
|
|
207
291
|
temp_df.reset_index(inplace=True, drop=True)
|
|
208
|
-
|
|
292
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
293
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
294
|
+
return new_df
|
|
209
295
|
elif symbol == "硅铁期权":
|
|
210
296
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SF")]
|
|
211
297
|
temp_df.reset_index(inplace=True, drop=True)
|
|
212
|
-
|
|
298
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
299
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
300
|
+
return new_df
|
|
213
301
|
elif symbol == "尿素期权":
|
|
214
302
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("UR")]
|
|
215
303
|
temp_df.reset_index(inplace=True, drop=True)
|
|
216
|
-
|
|
217
|
-
|
|
304
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
305
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
306
|
+
return new_df
|
|
307
|
+
elif symbol == "苹果期权":
|
|
218
308
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("AP")]
|
|
219
309
|
temp_df.reset_index(inplace=True, drop=True)
|
|
220
|
-
|
|
221
|
-
|
|
310
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
311
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
312
|
+
return new_df
|
|
313
|
+
elif symbol == "红枣期权":
|
|
314
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("CJ")]
|
|
315
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
316
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
317
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
318
|
+
return new_df
|
|
319
|
+
elif symbol == "对二甲苯期权":
|
|
320
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("PX")]
|
|
321
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
322
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
323
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
324
|
+
return new_df
|
|
325
|
+
elif symbol == "烧碱期权":
|
|
326
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("SH")]
|
|
327
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
328
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
329
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
330
|
+
return new_df
|
|
331
|
+
elif symbol == "玻璃期权":
|
|
332
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("FG")]
|
|
333
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
334
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
335
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
336
|
+
return new_df
|
|
337
|
+
elif symbol == "瓶片期权":
|
|
338
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("FG")]
|
|
339
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
340
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
341
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
342
|
+
return new_df
|
|
343
|
+
except: # noqa: E722
|
|
222
344
|
return pd.DataFrame()
|
|
223
345
|
|
|
224
346
|
|
|
225
347
|
def option_shfe_daily(
|
|
226
|
-
|
|
227
|
-
) -> pd.DataFrame:
|
|
348
|
+
symbol: str = "铝期权", trade_date: str = "20200827"
|
|
349
|
+
) -> Optional[Tuple[pd.DataFrame, pd.DataFrame]]:
|
|
228
350
|
"""
|
|
229
351
|
上海期货交易所-期权-日频行情数据
|
|
352
|
+
https://tsite.shfe.com.cn/statements/dataview.html?paramid=kxQ
|
|
230
353
|
:param trade_date: 交易日
|
|
231
354
|
:type trade_date: str
|
|
232
355
|
:param symbol: choice of {"铜期权", "天胶期权", "黄金期权", "铝期权", "锌期权"}
|
|
@@ -238,7 +361,7 @@ def option_shfe_daily(
|
|
|
238
361
|
day = convert_date(trade_date) if trade_date is not None else datetime.date.today()
|
|
239
362
|
if day.strftime("%Y%m%d") not in calendar:
|
|
240
363
|
warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
|
|
241
|
-
return
|
|
364
|
+
return pd.DataFrame(), pd.DataFrame()
|
|
242
365
|
if day > datetime.date(2010, 8, 24):
|
|
243
366
|
url = SHFE_OPTION_URL.format(day.strftime("%Y%m%d"))
|
|
244
367
|
try:
|
|
@@ -249,14 +372,14 @@ def option_shfe_daily(
|
|
|
249
372
|
row
|
|
250
373
|
for row in json_data["o_curinstrument"]
|
|
251
374
|
if row["INSTRUMENTID"] not in ["小计", "合计"]
|
|
252
|
-
|
|
375
|
+
and row["INSTRUMENTID"] != ""
|
|
253
376
|
]
|
|
254
377
|
)
|
|
255
378
|
contract_df = table_df[table_df["PRODUCTNAME"].str.strip() == symbol]
|
|
256
379
|
volatility_df = pd.DataFrame(json_data["o_cursigma"])
|
|
257
380
|
volatility_df = volatility_df[
|
|
258
381
|
volatility_df["PRODUCTNAME"].str.strip() == symbol
|
|
259
|
-
|
|
382
|
+
]
|
|
260
383
|
contract_df.columns = [
|
|
261
384
|
"_",
|
|
262
385
|
"_",
|
|
@@ -330,7 +453,7 @@ def option_shfe_daily(
|
|
|
330
453
|
contract_df.reset_index(inplace=True, drop=True)
|
|
331
454
|
volatility_df.reset_index(inplace=True, drop=True)
|
|
332
455
|
return contract_df, volatility_df
|
|
333
|
-
except:
|
|
456
|
+
except: # noqa: E722
|
|
334
457
|
return
|
|
335
458
|
|
|
336
459
|
|
|
@@ -364,7 +487,8 @@ def option_gfex_daily(symbol: str = "工业硅", trade_date: str = "20230724"):
|
|
|
364
487
|
"Pragma": "no-cache",
|
|
365
488
|
"Proxy-Connection": "keep-alive",
|
|
366
489
|
"Referer": "http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml",
|
|
367
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
|
|
490
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
491
|
+
"Chrome/108.0.0.0 Safari/537.36",
|
|
368
492
|
"X-Requested-With": "XMLHttpRequest",
|
|
369
493
|
"content-type": "application/x-www-form-urlencoded",
|
|
370
494
|
}
|
|
@@ -415,7 +539,7 @@ def option_gfex_daily(symbol: str = "工业硅", trade_date: str = "20230724"):
|
|
|
415
539
|
"隐含波动率",
|
|
416
540
|
]
|
|
417
541
|
]
|
|
418
|
-
temp_df = temp_df[temp_df[
|
|
542
|
+
temp_df = temp_df[temp_df["商品名称"].str.contains(symbol)]
|
|
419
543
|
temp_df.reset_index(inplace=True, drop=True)
|
|
420
544
|
return temp_df
|
|
421
545
|
|
|
@@ -454,7 +578,8 @@ def option_gfex_vol_daily(symbol: str = "碳酸锂", trade_date: str = "20230724
|
|
|
454
578
|
"Pragma": "no-cache",
|
|
455
579
|
"Proxy-Connection": "keep-alive",
|
|
456
580
|
"Referer": "http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml",
|
|
457
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
|
|
581
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
582
|
+
"Chrome/108.0.0.0 Safari/537.36",
|
|
458
583
|
"X-Requested-With": "XMLHttpRequest",
|
|
459
584
|
"content-type": "application/x-www-form-urlencoded",
|
|
460
585
|
}
|
|
@@ -475,17 +600,17 @@ def option_gfex_vol_daily(symbol: str = "碳酸锂", trade_date: str = "20230724
|
|
|
475
600
|
"隐含波动率",
|
|
476
601
|
]
|
|
477
602
|
]
|
|
478
|
-
temp_df = temp_df[temp_df[
|
|
603
|
+
temp_df = temp_df[temp_df["合约系列"].str.contains(symbol_code_map[symbol])]
|
|
479
604
|
temp_df.reset_index(inplace=True, drop=True)
|
|
480
605
|
return temp_df
|
|
481
606
|
|
|
482
607
|
|
|
483
608
|
if __name__ == "__main__":
|
|
484
|
-
option_czce_daily_df = option_czce_daily(symbol="
|
|
609
|
+
option_czce_daily_df = option_czce_daily(symbol="白糖期权", trade_date="20240711")
|
|
485
610
|
print(option_czce_daily_df)
|
|
486
611
|
|
|
487
612
|
option_dce_daily_one, option_dce_daily_two = option_dce_daily(
|
|
488
|
-
symbol="
|
|
613
|
+
symbol="玉米期权", trade_date="20241121"
|
|
489
614
|
)
|
|
490
615
|
print(option_dce_daily_one)
|
|
491
616
|
print(option_dce_daily_two)
|
|
@@ -511,8 +636,10 @@ if __name__ == "__main__":
|
|
|
511
636
|
option_gfex_daily_df = option_gfex_daily(symbol="工业硅", trade_date="20240102")
|
|
512
637
|
print(option_gfex_daily_df)
|
|
513
638
|
|
|
514
|
-
option_gfex_vol_daily_df = option_gfex_vol_daily(
|
|
639
|
+
option_gfex_vol_daily_df = option_gfex_vol_daily(
|
|
640
|
+
symbol="工业硅", trade_date="20230418"
|
|
641
|
+
)
|
|
515
642
|
print(option_gfex_vol_daily_df)
|
|
516
643
|
|
|
517
|
-
option_czce_daily_df = option_czce_daily(symbol="
|
|
644
|
+
option_czce_daily_df = option_czce_daily(symbol="瓶片期权", trade_date="20250103")
|
|
518
645
|
print(option_czce_daily_df)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# -*- coding:utf-8 -*-
|
|
2
|
+
# !/usr/bin/env python
|
|
3
|
+
"""
|
|
4
|
+
Date: 2024/6/27 22:20
|
|
5
|
+
Desc: 上海证券交易所-产品-股票期权-每日统计
|
|
6
|
+
https://www.sse.com.cn/assortment/options/date/
|
|
7
|
+
深圳证券交易所-市场数据-期权数据-日度概况
|
|
8
|
+
https://investor.szse.cn/market/option/day/index.html
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import pandas as pd
|
|
12
|
+
import requests
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def option_daily_stats_sse(date: str = "20240626") -> pd.DataFrame:
|
|
16
|
+
"""
|
|
17
|
+
上海证券交易所-产品-股票期权-每日统计
|
|
18
|
+
https://www.sse.com.cn/assortment/options/date/
|
|
19
|
+
:param date: 交易日
|
|
20
|
+
:type date: str
|
|
21
|
+
:return: 每日统计
|
|
22
|
+
:rtype: pandas.DataFrame
|
|
23
|
+
"""
|
|
24
|
+
url = "http://query.sse.com.cn/commonQuery.do"
|
|
25
|
+
params = {
|
|
26
|
+
"isPagination": "false",
|
|
27
|
+
"sqlId": "COMMON_SSE_ZQPZ_YSP_QQ_SJTJ_MRTJ_CX",
|
|
28
|
+
"tradeDate": date,
|
|
29
|
+
"_": "1652877575590",
|
|
30
|
+
}
|
|
31
|
+
headers = {
|
|
32
|
+
"Accept": "*/*",
|
|
33
|
+
"Accept-Encoding": "gzip, deflate",
|
|
34
|
+
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
|
35
|
+
"Cache-Control": "no-cache",
|
|
36
|
+
"Connection": "keep-alive",
|
|
37
|
+
"Host": "query.sse.com.cn",
|
|
38
|
+
"Pragma": "no-cache",
|
|
39
|
+
"Referer": "https://www.sse.com.cn/",
|
|
40
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
41
|
+
"Chrome/101.0.4951.67 Safari/537.36",
|
|
42
|
+
}
|
|
43
|
+
r = requests.get(url, params=params, headers=headers)
|
|
44
|
+
data_json = r.json()
|
|
45
|
+
temp_df = pd.DataFrame(data_json["result"])
|
|
46
|
+
temp_df.rename(
|
|
47
|
+
columns={
|
|
48
|
+
"CONTRACT_VOLUME": "合约数量",
|
|
49
|
+
"CALL_VOLUME": "认购成交量",
|
|
50
|
+
"LEAVES_QTY": "未平仓合约总数",
|
|
51
|
+
"CP_RATE": "认沽/认购",
|
|
52
|
+
"PUT_VOLUME": "认沽成交量",
|
|
53
|
+
"TRADE_DATE": "交易日",
|
|
54
|
+
"TOTAL_MONEY": "总成交额",
|
|
55
|
+
"TOTAL_VOLUME": "总成交量",
|
|
56
|
+
"SECURITY_CODE": "合约标的代码",
|
|
57
|
+
"LEAVES_CALL_QTY": "未平仓认购合约数",
|
|
58
|
+
"LEAVES_PUT_QTY": "未平仓认沽合约数",
|
|
59
|
+
"SECURITY_ABBR": "合约标的名称",
|
|
60
|
+
},
|
|
61
|
+
inplace=True,
|
|
62
|
+
)
|
|
63
|
+
temp_df = temp_df[
|
|
64
|
+
[
|
|
65
|
+
"合约标的代码",
|
|
66
|
+
"合约标的名称",
|
|
67
|
+
"合约数量",
|
|
68
|
+
"总成交额",
|
|
69
|
+
"总成交量",
|
|
70
|
+
"认购成交量",
|
|
71
|
+
"认沽成交量",
|
|
72
|
+
"认沽/认购",
|
|
73
|
+
"未平仓合约总数",
|
|
74
|
+
"未平仓认购合约数",
|
|
75
|
+
"未平仓认沽合约数",
|
|
76
|
+
"交易日",
|
|
77
|
+
]
|
|
78
|
+
]
|
|
79
|
+
temp_df["交易日"] = pd.to_datetime(temp_df["交易日"], errors="coerce").dt.date
|
|
80
|
+
for item in temp_df.columns[2:-1]:
|
|
81
|
+
temp_df[item] = temp_df[item].str.replace(",", "")
|
|
82
|
+
temp_df[item] = pd.to_numeric(temp_df[item], errors="coerce")
|
|
83
|
+
return temp_df
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def option_daily_stats_szse(date: str = "20240626") -> pd.DataFrame:
|
|
87
|
+
"""
|
|
88
|
+
深圳证券交易所-市场数据-期权数据-日度概况
|
|
89
|
+
https://investor.szse.cn/market/option/day/index.html
|
|
90
|
+
:param date: 交易日
|
|
91
|
+
:type date: str
|
|
92
|
+
:return: 每日统计
|
|
93
|
+
:rtype: pandas.DataFrame
|
|
94
|
+
"""
|
|
95
|
+
url = "https://investor.szse.cn/api/report/ShowReport/data"
|
|
96
|
+
params = {
|
|
97
|
+
"SHOWTYPE": "JSON",
|
|
98
|
+
"CATALOGID": "ysprdzb",
|
|
99
|
+
"TABKEY": "tab1",
|
|
100
|
+
"txtQueryDate": "-".join([date[:4], date[4:6], date[6:]]),
|
|
101
|
+
"random": "0.0652692406565949",
|
|
102
|
+
}
|
|
103
|
+
r = requests.get(url, params=params)
|
|
104
|
+
data_json = r.json()
|
|
105
|
+
temp_df = pd.DataFrame(data_json[0]["data"])
|
|
106
|
+
temp_df.rename(
|
|
107
|
+
columns={
|
|
108
|
+
"bddm": "合约标的代码",
|
|
109
|
+
"bdmc": "合约标的名称",
|
|
110
|
+
"cjl": "成交量",
|
|
111
|
+
"rccjl": "认购成交量",
|
|
112
|
+
"rpcjl": "认沽成交量",
|
|
113
|
+
"rcrpccb": "认沽/认购持仓比",
|
|
114
|
+
"wpchyzs": "未平仓合约总数",
|
|
115
|
+
"wpcrchys": "未平仓认购合约数",
|
|
116
|
+
"wpcrphys": "未平仓认沽合约数",
|
|
117
|
+
},
|
|
118
|
+
inplace=True,
|
|
119
|
+
)
|
|
120
|
+
temp_df = temp_df[
|
|
121
|
+
[
|
|
122
|
+
"合约标的代码",
|
|
123
|
+
"合约标的名称",
|
|
124
|
+
"成交量",
|
|
125
|
+
"认购成交量",
|
|
126
|
+
"认沽成交量",
|
|
127
|
+
"认沽/认购持仓比",
|
|
128
|
+
"未平仓合约总数",
|
|
129
|
+
"未平仓认购合约数",
|
|
130
|
+
"未平仓认沽合约数",
|
|
131
|
+
]
|
|
132
|
+
]
|
|
133
|
+
temp_df["交易日"] = "-".join([date[:4], date[4:6], date[6:]])
|
|
134
|
+
temp_df["交易日"] = pd.to_datetime(temp_df["交易日"], errors="coerce").dt.date
|
|
135
|
+
for item in temp_df.columns[2:-1]:
|
|
136
|
+
temp_df[item] = temp_df[item].str.replace(",", "")
|
|
137
|
+
temp_df[item] = pd.to_numeric(temp_df[item], errors="coerce")
|
|
138
|
+
return temp_df
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
if __name__ == "__main__":
|
|
142
|
+
option_daily_stats_sse_df = option_daily_stats_sse(date="20240626")
|
|
143
|
+
print(option_daily_stats_sse_df)
|
|
144
|
+
|
|
145
|
+
option_daily_stats_szse_df = option_daily_stats_szse(date="20240626")
|
|
146
|
+
print(option_daily_stats_szse_df)
|