akshare 1.14.49__py3-none-any.whl → 1.17.99__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.
- akshare/__init__.py +595 -129
- akshare/air/air_hebei.py +77 -54
- akshare/air/air_zhenqi.py +0 -4
- akshare/air/cons.py +1 -0
- akshare/air/crypto.js +1 -1
- akshare/air/outcrypto.js +1 -1
- akshare/article/cons.py +1 -0
- akshare/article/epu_index.py +4 -3
- akshare/article/ff_factor.py +19 -8
- akshare/article/fred_md.py +4 -1
- akshare/article/risk_rv.py +3 -8
- akshare/bank/bank_cbirc_2020.py +11 -11
- akshare/bank/cons.py +7 -6
- akshare/bond/bond_buy_back_em.py +228 -0
- akshare/bond/bond_cb_sina.py +1 -0
- akshare/bond/bond_cb_ths.py +17 -9
- akshare/bond/bond_cbond.py +19 -14
- akshare/bond/bond_china.py +38 -39
- akshare/bond/bond_china_money.py +1 -1
- akshare/bond/bond_convert.py +10 -9
- akshare/bond/bond_em.py +37 -17
- akshare/bond/bond_summary.py +38 -37
- akshare/bond/bond_zh_cov.py +31 -40
- akshare/bond/bond_zh_sina.py +4 -0
- akshare/bond/cons.py +14 -11
- akshare/cal/__init__.py +0 -0
- akshare/cal/rv.py +170 -0
- akshare/cost/cost_living.py +7 -5
- akshare/crypto/__init__.py +1 -1
- akshare/crypto/crypto_bitcoin_cme.py +9 -7
- akshare/crypto/crypto_hold.py +4 -2
- akshare/currency/currency.py +1 -0
- akshare/currency/currency_china_bank_sina.py +11 -6
- akshare/data/__init__.py +1 -1
- akshare/data/cninfo.js +1 -1
- akshare/datasets.py +10 -21
- akshare/economic/cons.py +10 -3
- akshare/economic/macro_australia.py +74 -69
- akshare/economic/macro_bank.py +95 -653
- akshare/economic/macro_canada.py +92 -81
- akshare/economic/macro_china.py +97 -105
- akshare/economic/macro_china_hk.py +0 -1
- akshare/economic/macro_euro.py +103 -56
- akshare/economic/macro_finance_ths.py +7 -5
- akshare/economic/macro_germany.py +1 -1
- akshare/economic/macro_japan.py +0 -1
- akshare/economic/macro_other.py +1 -6
- akshare/economic/macro_swiss.py +2 -3
- akshare/economic/macro_uk.py +1 -1
- akshare/economic/macro_usa.py +7 -9
- akshare/economic/marco_cnbs.py +11 -6
- akshare/energy/energy_carbon.py +0 -1
- akshare/energy/energy_oil_em.py +1 -2
- akshare/event/cons.py +1 -0
- akshare/exceptions.py +43 -0
- akshare/file_fold/calendar.json +245 -2
- akshare/forex/__init__.py +0 -0
- akshare/forex/cons.py +192 -0
- akshare/forex/forex_em.py +149 -0
- akshare/fortune/fortune_500.py +1 -37
- akshare/fortune/fortune_bloomberg.py +6 -3
- akshare/fortune/fortune_forbes_500.py +3 -6
- akshare/fortune/fortune_hurun.py +2 -1
- akshare/fortune/fortune_xincaifu_500.py +17 -14
- akshare/fund/fund_announcement_em.py +145 -0
- akshare/fund/fund_aum_em.py +49 -35
- akshare/fund/fund_em.py +251 -220
- akshare/fund/fund_etf_em.py +44 -35
- akshare/fund/fund_etf_sina.py +75 -27
- akshare/fund/fund_etf_ths.py +2 -0
- akshare/fund/fund_fee_em.py +172 -0
- akshare/fund/fund_fhsp_em.py +42 -32
- akshare/fund/fund_init_em.py +8 -5
- akshare/fund/fund_lof_em.py +12 -19
- akshare/fund/fund_manager.py +25 -11
- akshare/fund/fund_overview_em.py +42 -0
- akshare/fund/fund_portfolio_em.py +23 -21
- akshare/fund/fund_position_lg.py +19 -8
- akshare/fund/fund_rank_em.py +2 -5
- akshare/fund/fund_rating.py +33 -12
- akshare/fund/fund_scale_em.py +24 -13
- akshare/fund/fund_scale_sina.py +20 -10
- akshare/fund/fund_xq.py +3 -2
- akshare/futures/cons.py +135 -39
- akshare/futures/cot.py +55 -56
- akshare/futures/futures_basis.py +49 -11
- akshare/futures/futures_comex_em.py +1 -0
- akshare/futures/futures_comm_ctp.py +1 -1
- akshare/futures/futures_contract_detail.py +59 -9
- akshare/futures/futures_daily_bar.py +66 -59
- akshare/futures/futures_foreign.py +14 -8
- akshare/futures/futures_hf_em.py +215 -61
- akshare/futures/futures_hist_em.py +191 -0
- akshare/futures/futures_hq_sina.py +5 -3
- akshare/futures/futures_index_ccidx.py +24 -82
- akshare/futures/futures_inventory_99.py +70 -272
- akshare/futures/futures_inventory_em.py +14 -11
- akshare/futures/futures_news_shmet.py +2 -2
- akshare/futures/futures_roll_yield.py +11 -24
- akshare/futures/futures_rule.py +7 -3
- akshare/futures/futures_rule_em.py +38 -0
- akshare/futures/futures_settlement_price_sgx.py +21 -6
- akshare/futures/futures_stock_js.py +0 -1
- akshare/futures/futures_to_spot.py +5 -6
- akshare/futures/futures_warehouse_receipt.py +48 -47
- akshare/futures/futures_zh_sina.py +3 -3
- akshare/futures/receipt.py +298 -165
- akshare/futures/requests_fun.py +16 -3
- akshare/futures/symbol_var.py +32 -13
- akshare/futures_derivative/cons.py +100 -103
- akshare/futures_derivative/futures_contract_info_cffex.py +55 -39
- akshare/futures_derivative/futures_contract_info_czce.py +2 -0
- akshare/futures_derivative/futures_contract_info_dce.py +43 -17
- akshare/futures_derivative/futures_contract_info_gfex.py +43 -31
- akshare/futures_derivative/futures_contract_info_ine.py +43 -34
- akshare/futures_derivative/futures_contract_info_shfe.py +3 -4
- akshare/futures_derivative/futures_cot_sina.py +8 -6
- akshare/futures_derivative/futures_index_sina.py +25 -13
- akshare/fx/cons.py +12 -7
- akshare/fx/fx_c_swap_cm.py +62 -0
- akshare/fx/fx_quote.py +3 -2
- akshare/fx/fx_quote_baidu.py +2 -1
- akshare/hf/__init__.py +1 -1
- akshare/hf/hf_sp500.py +8 -7
- akshare/index/cons.py +132 -28
- akshare/index/index_cni.py +7 -7
- akshare/index/index_cons.py +2 -2
- akshare/index/index_csindex.py +68 -0
- akshare/index/index_cx.py +20 -20
- akshare/index/index_drewry.py +17 -16
- akshare/index/index_eri.py +1 -0
- akshare/index/index_global_em.py +167 -0
- akshare/index/index_global_sina.py +82 -0
- akshare/index/index_kq_fz.py +17 -14
- akshare/index/index_kq_ss.py +1 -0
- akshare/index/index_option_qvix.py +351 -16
- akshare/index/index_research_sw.py +21 -21
- akshare/index/index_spot.py +9 -5
- akshare/index/index_stock_hk.py +5 -9
- akshare/index/index_stock_zh.py +111 -24
- akshare/index/index_stock_zh_csindex.py +3 -367
- akshare/index/index_sugar.py +18 -4
- akshare/index/index_sw.py +10 -2
- akshare/index/index_yw.py +53 -75
- akshare/index/index_zh_em.py +15 -82
- akshare/interest_rate/interbank_rate_em.py +0 -1
- akshare/movie/jm.js +0 -1
- akshare/news/__init__.py +1 -1
- akshare/news/news_baidu.py +395 -222
- akshare/news/news_stock.py +49 -16
- akshare/option/cons.py +2 -2
- akshare/option/option_commodity.py +341 -220
- akshare/option/option_commodity_sina.py +22 -26
- akshare/option/option_contract_info_ctp.py +63 -0
- akshare/option/option_current_sse.py +61 -0
- akshare/option/option_current_szse.py +84 -0
- akshare/option/option_czce.py +37 -9
- akshare/option/option_daily_stats_sse_szse.py +0 -1
- akshare/option/option_em.py +4 -8
- akshare/option/option_finance.py +60 -12
- akshare/option/option_finance_sina.py +7 -7
- akshare/option/option_lhb_em.py +0 -1
- akshare/option/option_margin.py +62 -0
- akshare/option/option_premium_analysis_em.py +58 -53
- akshare/option/option_risk_analysis_em.py +11 -8
- akshare/option/option_risk_indicator_sse.py +3 -4
- akshare/option/option_value_analysis_em.py +62 -55
- akshare/other/__init__.py +1 -1
- akshare/pro/__init__.py +0 -1
- akshare/pro/client.py +6 -4
- akshare/pro/cons.py +3 -2
- akshare/pro/data_pro.py +6 -5
- akshare/qdii/__init__.py +0 -0
- akshare/qdii/qdii_jsl.py +233 -0
- akshare/qhkc/__init__.py +1 -6
- akshare/qhkc/qhkc_api.py +64 -22
- akshare/qhkc_web/__init__.py +1 -6
- akshare/qhkc_web/qhkc_fund.py +10 -6
- akshare/qhkc_web/qhkc_index.py +28 -14
- akshare/qhkc_web/qhkc_tool.py +62 -59
- akshare/rate/__init__.py +1 -1
- akshare/rate/repo_rate.py +36 -32
- akshare/reits/__init__.py +1 -1
- akshare/reits/reits_basic.py +149 -13
- akshare/request.py +117 -0
- akshare/spot/__init__.py +1 -1
- akshare/spot/spot_hog_soozhu.py +165 -3
- akshare/spot/spot_sge.py +70 -9
- akshare/stock/cons.py +60 -23
- akshare/stock/stock_allotment_cninfo.py +8 -8
- akshare/stock/stock_ask_bid_em.py +3 -78
- akshare/stock/stock_board_concept_em.py +160 -35
- akshare/stock/stock_board_industry_em.py +163 -70
- akshare/stock/stock_dividend_cninfo.py +31 -17
- akshare/stock/stock_dzjy_em.py +347 -260
- akshare/stock/stock_fund_em.py +72 -64
- akshare/stock/stock_fund_hold.py +1 -2
- akshare/stock/stock_gsrl_em.py +1 -0
- akshare/stock/stock_hk_comparison_em.py +175 -0
- akshare/stock/stock_hk_famous.py +4 -5
- akshare/stock/stock_hk_fhpx_ths.py +2 -1
- akshare/stock/stock_hk_hot_rank_em.py +1 -0
- akshare/stock/stock_hk_sina.py +84 -36
- akshare/stock/stock_hold_control_cninfo.py +82 -0
- akshare/stock/stock_hold_control_em.py +0 -2
- akshare/stock/stock_hot_rank_em.py +4 -1
- akshare/stock/stock_hot_search_baidu.py +32 -19
- akshare/stock/stock_hot_up_em.py +4 -1
- akshare/stock/stock_hsgt_em.py +155 -0
- akshare/stock/stock_industry.py +1 -0
- akshare/stock/stock_industry_cninfo.py +1 -2
- akshare/stock/stock_info.py +6 -4
- akshare/stock/stock_info_em.py +17 -11
- akshare/stock/stock_intraday_em.py +4 -78
- akshare/stock/stock_intraday_sina.py +2 -2
- akshare/stock/stock_news_cx.py +39 -0
- akshare/stock/stock_profile_cninfo.py +7 -7
- akshare/stock/stock_profile_em.py +302 -0
- akshare/stock/stock_rank_forecast.py +6 -5
- akshare/stock/stock_repurchase_em.py +7 -2
- akshare/stock/stock_share_changes_cninfo.py +7 -5
- akshare/stock/stock_share_hold.py +24 -20
- akshare/stock/stock_stop.py +6 -6
- akshare/stock/stock_summary.py +153 -417
- akshare/stock/stock_us_famous.py +5 -6
- akshare/stock/stock_us_js.py +3 -2
- akshare/stock/stock_us_pink.py +38 -27
- akshare/stock/stock_us_sina.py +7 -3
- akshare/stock/stock_weibo_nlp.py +18 -20
- akshare/stock/stock_xq.py +24 -22
- akshare/stock/stock_zh_a_sina.py +8 -5
- akshare/stock/stock_zh_a_special.py +240 -243
- akshare/stock/stock_zh_a_tick_tx.py +11 -3
- akshare/stock/stock_zh_ah_tx.py +23 -26
- akshare/stock/stock_zh_b_sina.py +2 -2
- akshare/stock/stock_zh_comparison_em.py +250 -0
- akshare/stock/stock_zh_kcb_sina.py +67 -64
- akshare/stock_a/__init__.py +0 -0
- akshare/stock_a/stock_board_concept_name_em.py +170 -0
- akshare/stock_a/stock_individual_fund_flow_rank.py +258 -0
- akshare/stock_a/stock_zh_a_spot.py +212 -0
- akshare/stock_feature/cons.py +1 -0
- akshare/stock_feature/stock_a_indicator.py +9 -54
- akshare/stock_feature/stock_a_pe_and_pb.py +23 -5
- akshare/stock_feature/stock_account_em.py +0 -1
- akshare/stock_feature/stock_all_pb.py +2 -1
- akshare/stock_feature/stock_analyst_em.py +36 -30
- akshare/stock_feature/stock_board_concept_ths.py +328 -0
- akshare/stock_feature/stock_board_industry_ths.py +57 -2
- akshare/stock_feature/stock_buffett_index_lg.py +10 -8
- akshare/stock_feature/stock_classify_sina.py +3 -6
- akshare/stock_feature/stock_comment_em.py +81 -144
- akshare/stock_feature/stock_congestion_lg.py +2 -1
- akshare/stock_feature/stock_cyq_em.py +5 -11
- akshare/stock_feature/stock_disclosure_cninfo.py +6 -6
- akshare/stock_feature/stock_dxsyl_em.py +121 -74
- akshare/stock_feature/stock_ebs_lg.py +5 -4
- akshare/stock_feature/stock_esg_sina.py +29 -7
- akshare/stock_feature/stock_fhps_em.py +2 -1
- akshare/stock_feature/stock_fhps_ths.py +15 -7
- akshare/stock_feature/stock_fund_flow.py +30 -22
- akshare/stock_feature/stock_gddh_em.py +19 -11
- akshare/stock_feature/stock_gdfx_em.py +226 -113
- akshare/stock_feature/stock_gdhs.py +75 -50
- akshare/stock_feature/stock_gdzjc_em.py +21 -10
- akshare/stock_feature/stock_gpzy_em.py +78 -46
- akshare/stock_feature/stock_gxl_lg.py +3 -2
- akshare/stock_feature/stock_hist_em.py +137 -234
- akshare/stock_feature/stock_hist_tx.py +13 -10
- akshare/stock_feature/stock_hk_valuation_baidu.py +20 -8
- akshare/stock_feature/stock_hot_xq.py +4 -6
- akshare/stock_feature/stock_hsgt_em.py +269 -97
- akshare/stock_feature/stock_hsgt_exchange_rate.py +115 -87
- akshare/stock_feature/stock_hsgt_min_em.py +13 -16
- akshare/stock_feature/stock_info.py +7 -80
- akshare/stock_feature/stock_inner_trade_xq.py +38 -31
- akshare/stock_feature/stock_jgdy_em.py +43 -40
- akshare/stock_feature/stock_lhb_em.py +119 -3
- akshare/stock_feature/stock_margin_em.py +0 -1
- akshare/stock_feature/stock_margin_sse.py +0 -2
- akshare/stock_feature/stock_pankou_em.py +71 -35
- akshare/stock_feature/stock_qsjy_em.py +13 -4
- akshare/stock_feature/stock_report_em.py +151 -7
- akshare/stock_feature/stock_research_report_em.py +55 -20
- akshare/stock_feature/stock_sy_em.py +20 -15
- akshare/stock_feature/stock_technology_ths.py +122 -77
- akshare/stock_feature/stock_tfp_em.py +2 -1
- akshare/stock_feature/stock_three_report_em.py +21 -5
- akshare/stock_feature/stock_ttm_lyr.py +18 -9
- akshare/stock_feature/stock_value_em.py +83 -0
- akshare/stock_feature/stock_yjbb_em.py +58 -32
- akshare/stock_feature/stock_yjyg_cninfo.py +6 -2
- akshare/stock_feature/stock_yjyg_em.py +1 -1
- akshare/stock_feature/stock_yzxdr_em.py +24 -22
- akshare/stock_feature/stock_zdhtmx_em.py +20 -6
- akshare/stock_feature/stock_zh_vote_baidu.py +4 -1
- akshare/stock_feature/stock_ztb_em.py +39 -24
- akshare/stock_fundamental/__init__.py +1 -1
- akshare/stock_fundamental/stock_basic_info_xq.py +119 -0
- akshare/stock_fundamental/{stock_finance_hk.py → stock_finance_hk_em.py} +23 -16
- akshare/stock_fundamental/{stock_finance.py → stock_finance_sina.py} +60 -7
- akshare/stock_fundamental/stock_finance_ths.py +524 -57
- akshare/stock_fundamental/stock_finance_us_em.py +268 -0
- akshare/stock_fundamental/stock_gbjg_em.py +80 -0
- akshare/stock_fundamental/stock_hold.py +26 -17
- akshare/stock_fundamental/stock_ipo_declare.py +1 -0
- akshare/stock_fundamental/stock_kcb_detail_sse.py +10 -10
- akshare/stock_fundamental/stock_kcb_sse.py +26 -25
- akshare/stock_fundamental/stock_notice.py +12 -3
- akshare/stock_fundamental/stock_profit_forecast_em.py +31 -13
- akshare/stock_fundamental/stock_profit_forecast_hk_etnet.py +64 -41
- akshare/stock_fundamental/stock_profit_forecast_ths.py +86 -35
- akshare/stock_fundamental/stock_recommend.py +20 -4
- akshare/stock_fundamental/stock_zygc.py +5 -62
- akshare/utils/context.py +43 -0
- akshare/utils/demjson.py +2009 -1338
- akshare/utils/func.py +49 -2
- akshare/utils/multi_decrypt.py +53 -0
- akshare/utils/token_process.py +6 -5
- {akshare-1.14.49.dist-info → akshare-1.17.99.dist-info}/METADATA +54 -80
- akshare-1.17.99.dist-info/RECORD +409 -0
- {akshare-1.14.49.dist-info → akshare-1.17.99.dist-info}/WHEEL +1 -1
- {akshare-1.14.49.dist-info → akshare-1.17.99.dist-info/licenses}/LICENSE +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/fund/fund_announcement.py +0 -56
- 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 -53
- akshare/futures_derivative/futures_other_index_nh.py +0 -145
- akshare/index/index_fear_greed_funddb.py +0 -78
- akshare/index/index_investing.py +0 -232
- akshare/sport/__init__.py +0 -6
- akshare/sport/sport_olympic.py +0 -27
- akshare/stock_feature/stock_wencai.py +0 -104
- akshare/stock_fundamental/stock_mda_ym.py +0 -40
- akshare-1.14.49.dist-info/RECORD +0 -387
- {akshare-1.14.49.dist-info → akshare-1.17.99.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding:utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
Date:
|
|
4
|
+
Date: 2025/10/17 21:00
|
|
5
5
|
Desc: 商品期权数据
|
|
6
6
|
说明:
|
|
7
7
|
(1) 价格:自2019年12月02日起,纤维板报价单位由元/张改为元/立方米
|
|
@@ -16,8 +16,7 @@ Desc: 商品期权数据
|
|
|
16
16
|
|
|
17
17
|
import datetime
|
|
18
18
|
import warnings
|
|
19
|
-
from io import StringIO
|
|
20
|
-
from typing import Tuple, Any, Optional
|
|
19
|
+
from io import StringIO
|
|
21
20
|
|
|
22
21
|
import pandas as pd
|
|
23
22
|
import requests
|
|
@@ -25,121 +24,163 @@ import requests
|
|
|
25
24
|
from akshare.option.cons import (
|
|
26
25
|
get_calendar,
|
|
27
26
|
convert_date,
|
|
28
|
-
DCE_DAILY_OPTION_URL,
|
|
29
|
-
SHFE_OPTION_URL,
|
|
30
27
|
CZCE_DAILY_OPTION_URL_3,
|
|
31
28
|
SHFE_HEADERS,
|
|
32
29
|
)
|
|
33
30
|
|
|
34
31
|
|
|
35
|
-
def
|
|
36
|
-
symbol: str = "
|
|
37
|
-
) ->
|
|
32
|
+
def option_hist_dce(
|
|
33
|
+
symbol: str = "聚丙烯期权", trade_date: str = "20251016"
|
|
34
|
+
) -> pd.DataFrame:
|
|
38
35
|
"""
|
|
39
36
|
大连商品交易所-期权-日频行情数据
|
|
40
37
|
http://www.dce.com.cn/
|
|
41
38
|
:param trade_date: 交易日
|
|
42
39
|
:type trade_date: str
|
|
43
|
-
:param symbol: choice of {"玉米期权", "豆粕期权", "铁矿石期权", "液化石油气期权", "聚乙烯期权", "聚氯乙烯期权",
|
|
40
|
+
:param symbol: choice of {"玉米期权", "豆粕期权", "铁矿石期权", "液化石油气期权", "聚乙烯期权", "聚氯乙烯期权",
|
|
41
|
+
"聚丙烯期权", "棕榈油期权", "黄大豆1号期权", "黄大豆2号期权", "豆油期权", "乙二醇期权", "苯乙烯期权",
|
|
42
|
+
"鸡蛋期权", "玉米淀粉期权", "生猪期权", "原木期权"}
|
|
44
43
|
:type symbol: str
|
|
45
44
|
:return: 日频行情数据
|
|
46
45
|
:rtype: pandas.DataFrame
|
|
47
46
|
"""
|
|
47
|
+
option_code_map = {
|
|
48
|
+
"玉米期权": "c",
|
|
49
|
+
"豆粕期权": "m",
|
|
50
|
+
"铁矿石期权": "i",
|
|
51
|
+
"液化石油气期权": "pg",
|
|
52
|
+
"聚乙烯期权": "l",
|
|
53
|
+
"聚氯乙烯期权": "v",
|
|
54
|
+
"聚丙烯期权": "pp",
|
|
55
|
+
"棕榈油期权": "p",
|
|
56
|
+
"黄大豆1号期权": "a",
|
|
57
|
+
"黄大豆2号期权": "b",
|
|
58
|
+
"豆油期权": "y",
|
|
59
|
+
"乙二醇期权": "eg",
|
|
60
|
+
"苯乙烯期权": "eb",
|
|
61
|
+
"鸡蛋期权": "jd",
|
|
62
|
+
"玉米淀粉期权": "cs",
|
|
63
|
+
"生猪期权": "lh",
|
|
64
|
+
"原木期权": "lg"
|
|
65
|
+
}
|
|
48
66
|
calendar = get_calendar()
|
|
49
67
|
day = convert_date(trade_date) if trade_date is not None else datetime.date.today()
|
|
50
68
|
if day.strftime("%Y%m%d") not in calendar:
|
|
51
69
|
warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
|
|
52
|
-
return
|
|
53
|
-
url =
|
|
70
|
+
return pd.DataFrame()
|
|
71
|
+
url = "http://www.dce.com.cn/dcereport/publicweb/dailystat/dayQuotes"
|
|
54
72
|
payload = {
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
73
|
+
"contractId": "",
|
|
74
|
+
"lang": "zh",
|
|
75
|
+
"optionSeries": "",
|
|
76
|
+
"statisticsType": 0,
|
|
77
|
+
"tradeDate": f"{trade_date}",
|
|
78
|
+
"tradeType": "2",
|
|
79
|
+
"varietyId": f"{option_code_map[symbol]}",
|
|
61
80
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
table_df[table_df["商品名称"] == "豆油"],
|
|
124
|
-
another_df[another_df.iloc[:, 0].str.contains("y")],
|
|
125
|
-
)
|
|
126
|
-
elif symbol == "乙二醇期权":
|
|
127
|
-
result_one_df, result_two_df = (
|
|
128
|
-
table_df[table_df["商品名称"] == "乙二醇"],
|
|
129
|
-
another_df[another_df.iloc[:, 0].str.contains("eg")],
|
|
130
|
-
)
|
|
131
|
-
elif symbol == "苯乙烯期权":
|
|
132
|
-
result_one_df, result_two_df = (
|
|
133
|
-
table_df[table_df["商品名称"] == "苯乙烯"],
|
|
134
|
-
another_df[another_df.iloc[:, 0].str.contains("eb")],
|
|
81
|
+
r = requests.post(url, json=payload)
|
|
82
|
+
data_json = r.json()
|
|
83
|
+
temp_df = pd.DataFrame(data_json["data"])
|
|
84
|
+
temp_df.rename(
|
|
85
|
+
columns={
|
|
86
|
+
'variety': '品种名称',
|
|
87
|
+
'contractId': '合约',
|
|
88
|
+
'open': '开盘价',
|
|
89
|
+
'high': '最高价',
|
|
90
|
+
'low': '最低价',
|
|
91
|
+
'close': '收盘价',
|
|
92
|
+
'lastClear': '前结算价',
|
|
93
|
+
'clearPrice': '结算价',
|
|
94
|
+
'diff': '涨跌',
|
|
95
|
+
'diff1': '涨跌1',
|
|
96
|
+
'delta': 'Delta',
|
|
97
|
+
'volumn': '成交量', # 注意:你写的是“volumn”,可能是拼写错误,应为“volume”
|
|
98
|
+
'openInterest': '持仓量',
|
|
99
|
+
'diffI': '持仓量变化',
|
|
100
|
+
'turnover': '成交额',
|
|
101
|
+
'matchQtySum': '行权量',
|
|
102
|
+
'impliedVolatility': '隐含波动率(%)',
|
|
103
|
+
}, inplace=True
|
|
104
|
+
)
|
|
105
|
+
temp_df = temp_df[[
|
|
106
|
+
'品种名称',
|
|
107
|
+
'合约',
|
|
108
|
+
'开盘价',
|
|
109
|
+
'最高价',
|
|
110
|
+
'最低价',
|
|
111
|
+
'收盘价',
|
|
112
|
+
'前结算价',
|
|
113
|
+
'结算价',
|
|
114
|
+
'涨跌',
|
|
115
|
+
'涨跌1',
|
|
116
|
+
'Delta',
|
|
117
|
+
'隐含波动率(%)',
|
|
118
|
+
'成交量',
|
|
119
|
+
'持仓量',
|
|
120
|
+
'持仓量变化',
|
|
121
|
+
'成交额',
|
|
122
|
+
'行权量'
|
|
123
|
+
]]
|
|
124
|
+
comma_cols = ['开盘价',
|
|
125
|
+
'最高价',
|
|
126
|
+
'最低价',
|
|
127
|
+
'收盘价',
|
|
128
|
+
'前结算价',
|
|
129
|
+
'结算价',
|
|
130
|
+
'涨跌',
|
|
131
|
+
'涨跌1',
|
|
132
|
+
'Delta',
|
|
133
|
+
'隐含波动率(%)',
|
|
134
|
+
'成交额',
|
|
135
|
+
] # 需要处理的列
|
|
136
|
+
for col in comma_cols:
|
|
137
|
+
temp_df[col] = (
|
|
138
|
+
temp_df[col]
|
|
139
|
+
.astype(str)
|
|
140
|
+
.str.replace(',', '')
|
|
141
|
+
.pipe(pd.to_numeric, errors='coerce')
|
|
135
142
|
)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
return temp_df
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def __option_czce_daily_convert_numeric_columns(df):
|
|
147
|
+
# 定义要处理的列
|
|
148
|
+
columns_to_convert = [
|
|
149
|
+
"昨结算",
|
|
150
|
+
"今开盘",
|
|
151
|
+
"最高价",
|
|
152
|
+
"最低价",
|
|
153
|
+
"今收盘",
|
|
154
|
+
"今结算",
|
|
155
|
+
"涨跌1",
|
|
156
|
+
"涨跌2",
|
|
157
|
+
"成交量(手)",
|
|
158
|
+
"持仓量",
|
|
159
|
+
"增减量",
|
|
160
|
+
"成交额(万元)",
|
|
161
|
+
"DELTA",
|
|
162
|
+
"隐含波动率",
|
|
163
|
+
"行权量",
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
# 转换函数:去除逗号并转换为float
|
|
167
|
+
def convert_to_float(x):
|
|
168
|
+
try:
|
|
169
|
+
return float(str(x).replace(",", ""))
|
|
170
|
+
except: # noqa: E722
|
|
171
|
+
return x
|
|
140
172
|
|
|
173
|
+
# 创建 DataFrame 的副本以避免 SettingWithCopyWarning
|
|
174
|
+
df_copy = df.copy()
|
|
175
|
+
df_copy.columns = [item.strip() for item in df_copy]
|
|
176
|
+
# 应用转换
|
|
177
|
+
for col in columns_to_convert:
|
|
178
|
+
df_copy[col] = df_copy[col].apply(convert_to_float)
|
|
141
179
|
|
|
142
|
-
|
|
180
|
+
return df_copy
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def option_hist_czce(
|
|
143
184
|
symbol: str = "白糖期权", trade_date: str = "20191017"
|
|
144
185
|
) -> pd.DataFrame:
|
|
145
186
|
"""
|
|
@@ -147,8 +188,9 @@ def option_czce_daily(
|
|
|
147
188
|
http://www.czce.com.cn/cn/sspz/dejbqhqq/H770227index_1.htm#tabs-2
|
|
148
189
|
:param trade_date: 交易日
|
|
149
190
|
:type trade_date: str
|
|
150
|
-
:param symbol: choice of {"白糖期权", "棉花期权", "甲醇期权", "PTA期权",
|
|
151
|
-
"
|
|
191
|
+
:param symbol: choice of {"白糖期权", "棉花期权", "甲醇期权", "PTA期权", "动力煤期权", "菜籽粕期权", "菜籽油期权",
|
|
192
|
+
"花生期权", "对二甲苯期权", "烧碱期权", "纯碱期权", "短纤期权", "锰硅期权", "硅铁期权", "尿素期权", "苹果期权", "红枣期权",
|
|
193
|
+
"玻璃期权", "瓶片期权", "丙烯期货"}
|
|
152
194
|
:type symbol: str
|
|
153
195
|
:return: 日频行情数据
|
|
154
196
|
:rtype: pandas.DataFrame
|
|
@@ -164,91 +206,168 @@ def option_czce_daily(
|
|
|
164
206
|
r = requests.get(url)
|
|
165
207
|
f = StringIO(r.text)
|
|
166
208
|
table_df = pd.read_table(f, encoding="utf-8", skiprows=1, sep="|")
|
|
209
|
+
table_df.columns = [
|
|
210
|
+
"合约代码",
|
|
211
|
+
"昨结算",
|
|
212
|
+
"今开盘",
|
|
213
|
+
"最高价",
|
|
214
|
+
"最低价",
|
|
215
|
+
"今收盘",
|
|
216
|
+
"今结算",
|
|
217
|
+
"涨跌1",
|
|
218
|
+
"涨跌2",
|
|
219
|
+
"成交量(手)",
|
|
220
|
+
"持仓量",
|
|
221
|
+
"增减量",
|
|
222
|
+
"成交额(万元)",
|
|
223
|
+
"DELTA",
|
|
224
|
+
"隐含波动率",
|
|
225
|
+
"行权量",
|
|
226
|
+
]
|
|
167
227
|
if symbol == "白糖期权":
|
|
168
228
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SR")]
|
|
169
229
|
temp_df.reset_index(inplace=True, drop=True)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
230
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
231
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
232
|
+
return new_df
|
|
233
|
+
elif symbol == "棉花期权":
|
|
234
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("CF")]
|
|
173
235
|
temp_df.reset_index(inplace=True, drop=True)
|
|
174
|
-
|
|
236
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
237
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
238
|
+
return new_df
|
|
175
239
|
elif symbol == "甲醇期权":
|
|
176
240
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("MA")]
|
|
177
241
|
temp_df.reset_index(inplace=True, drop=True)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
242
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
243
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
244
|
+
return new_df
|
|
245
|
+
elif symbol == "PTA期权":
|
|
246
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("TA")]
|
|
181
247
|
temp_df.reset_index(inplace=True, drop=True)
|
|
182
|
-
|
|
248
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
249
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
250
|
+
return new_df
|
|
183
251
|
elif symbol == "动力煤期权":
|
|
184
252
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("ZC")]
|
|
185
253
|
temp_df.reset_index(inplace=True, drop=True)
|
|
186
|
-
|
|
254
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
255
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
256
|
+
return new_df
|
|
257
|
+
elif symbol == "菜籽粕期权":
|
|
258
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("RM")]
|
|
259
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
260
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
261
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
262
|
+
return new_df
|
|
187
263
|
elif symbol == "菜籽油期权":
|
|
188
264
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("OI")]
|
|
189
265
|
temp_df.reset_index(inplace=True, drop=True)
|
|
190
|
-
|
|
266
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
267
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
268
|
+
return new_df
|
|
191
269
|
elif symbol == "花生期权":
|
|
192
270
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("PK")]
|
|
193
271
|
temp_df.reset_index(inplace=True, drop=True)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
temp_df.reset_index(inplace=True, drop=True)
|
|
198
|
-
return temp_df.iloc[:-1, :]
|
|
272
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
273
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
274
|
+
return new_df
|
|
199
275
|
elif symbol == "短纤期权":
|
|
200
276
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("PF")]
|
|
201
277
|
temp_df.reset_index(inplace=True, drop=True)
|
|
202
|
-
|
|
278
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
279
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
280
|
+
return new_df
|
|
281
|
+
elif symbol == "对二甲苯期权":
|
|
282
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("PX")]
|
|
283
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
284
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
285
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
286
|
+
return new_df
|
|
287
|
+
elif symbol == "烧碱期权":
|
|
288
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("SH")]
|
|
289
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
290
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
291
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
292
|
+
return new_df
|
|
203
293
|
elif symbol == "纯碱期权":
|
|
204
294
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SA")]
|
|
205
295
|
temp_df.reset_index(inplace=True, drop=True)
|
|
206
|
-
|
|
296
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
297
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
298
|
+
return new_df
|
|
299
|
+
elif symbol == "短纤期权":
|
|
300
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("PF")]
|
|
301
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
302
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
303
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
304
|
+
return new_df
|
|
207
305
|
elif symbol == "锰硅期权":
|
|
208
306
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SM")]
|
|
209
307
|
temp_df.reset_index(inplace=True, drop=True)
|
|
210
|
-
|
|
308
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
309
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
310
|
+
return new_df
|
|
211
311
|
elif symbol == "硅铁期权":
|
|
212
312
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SF")]
|
|
213
313
|
temp_df.reset_index(inplace=True, drop=True)
|
|
214
|
-
|
|
314
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
315
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
316
|
+
return new_df
|
|
215
317
|
elif symbol == "尿素期权":
|
|
216
318
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("UR")]
|
|
217
319
|
temp_df.reset_index(inplace=True, drop=True)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
320
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
321
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
322
|
+
return new_df
|
|
323
|
+
elif symbol == "苹果期权":
|
|
324
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("AP")]
|
|
221
325
|
temp_df.reset_index(inplace=True, drop=True)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
326
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
327
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
328
|
+
return new_df
|
|
329
|
+
elif symbol == "红枣期权":
|
|
330
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("CJ")]
|
|
225
331
|
temp_df.reset_index(inplace=True, drop=True)
|
|
226
|
-
|
|
332
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
333
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
334
|
+
return new_df
|
|
227
335
|
elif symbol == "玻璃期权":
|
|
228
336
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("FG")]
|
|
229
337
|
temp_df.reset_index(inplace=True, drop=True)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
338
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
339
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
340
|
+
return new_df
|
|
341
|
+
elif symbol == "瓶片期权":
|
|
342
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("PR")]
|
|
233
343
|
temp_df.reset_index(inplace=True, drop=True)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
344
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
345
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
346
|
+
return new_df
|
|
347
|
+
elif symbol == "丙烯期权":
|
|
348
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("PL")]
|
|
237
349
|
temp_df.reset_index(inplace=True, drop=True)
|
|
238
|
-
|
|
350
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
351
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
352
|
+
return new_df
|
|
353
|
+
else:
|
|
354
|
+
return pd.DataFrame()
|
|
239
355
|
except: # noqa: E722
|
|
240
356
|
return pd.DataFrame()
|
|
357
|
+
else:
|
|
358
|
+
return pd.DataFrame()
|
|
241
359
|
|
|
242
360
|
|
|
243
|
-
def
|
|
244
|
-
symbol: str = "铝期权", trade_date: str = "
|
|
245
|
-
) ->
|
|
361
|
+
def option_hist_shfe(
|
|
362
|
+
symbol: str = "铝期权", trade_date: str = "20250418"
|
|
363
|
+
) -> pd.DataFrame:
|
|
246
364
|
"""
|
|
247
365
|
上海期货交易所-期权-日频行情数据
|
|
248
|
-
https://
|
|
366
|
+
https://www.shfe.com.cn/reports/tradedata/dailyandweeklydata/
|
|
249
367
|
:param trade_date: 交易日
|
|
250
368
|
:type trade_date: str
|
|
251
|
-
:param symbol: choice of {
|
|
369
|
+
:param symbol: choice of {'原油期权', '铜期权', '铝期权', '锌期权', '铅期权', '螺纹钢期权', '镍期权', '锡期权', '氧化铝期权',
|
|
370
|
+
'黄金期权', '白银期权', '丁二烯橡胶期权', '天胶期权'}
|
|
252
371
|
:type symbol: str
|
|
253
372
|
:return: 日频行情数据
|
|
254
373
|
:rtype: pandas.DataFrame
|
|
@@ -258,8 +377,8 @@ def option_shfe_daily(
|
|
|
258
377
|
if day.strftime("%Y%m%d") not in calendar:
|
|
259
378
|
warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
|
|
260
379
|
return pd.DataFrame()
|
|
261
|
-
if day > datetime.date(2010, 8, 24):
|
|
262
|
-
url =
|
|
380
|
+
if day > datetime.date(year=2010, month=8, day=24):
|
|
381
|
+
url = f"""https://www.shfe.com.cn/data/tradedata/option/dailydata/kx{day.strftime("%Y%m%d")}.dat"""
|
|
263
382
|
try:
|
|
264
383
|
r = requests.get(url, headers=SHFE_HEADERS)
|
|
265
384
|
json_data = r.json()
|
|
@@ -268,39 +387,29 @@ def option_shfe_daily(
|
|
|
268
387
|
row
|
|
269
388
|
for row in json_data["o_curinstrument"]
|
|
270
389
|
if row["INSTRUMENTID"] not in ["小计", "合计"]
|
|
271
|
-
|
|
390
|
+
and row["INSTRUMENTID"] != ""
|
|
272
391
|
]
|
|
273
392
|
)
|
|
274
393
|
contract_df = table_df[table_df["PRODUCTNAME"].str.strip() == symbol]
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
"持仓量变化",
|
|
295
|
-
"_",
|
|
296
|
-
"行权量",
|
|
297
|
-
"成交额",
|
|
298
|
-
"德尔塔",
|
|
299
|
-
"_",
|
|
300
|
-
"_",
|
|
301
|
-
"_",
|
|
302
|
-
"_",
|
|
303
|
-
]
|
|
394
|
+
contract_df.rename(
|
|
395
|
+
columns={
|
|
396
|
+
"INSTRUMENTID": "合约代码",
|
|
397
|
+
"OPENPRICE": "开盘价",
|
|
398
|
+
"HIGHESTPRICE": "最高价",
|
|
399
|
+
"LOWESTPRICE": "最低价",
|
|
400
|
+
"CLOSEPRICE": "收盘价",
|
|
401
|
+
"PRESETTLEMENTPRICE": "前结算价",
|
|
402
|
+
"SETTLEMENTPRICE": "结算价",
|
|
403
|
+
"ZD1_CHG": "涨跌1",
|
|
404
|
+
"ZD2_CHG": "涨跌2",
|
|
405
|
+
"VOLUME": "成交量",
|
|
406
|
+
"OPENINTEREST": "持仓量",
|
|
407
|
+
"OPENINTERESTCHG": "持仓量变化",
|
|
408
|
+
"TURNOVER": "成交额",
|
|
409
|
+
"DELTA": "德尔塔",
|
|
410
|
+
"EXECVOLUME": "行权量"
|
|
411
|
+
}, inplace=True
|
|
412
|
+
)
|
|
304
413
|
contract_df = contract_df[
|
|
305
414
|
[
|
|
306
415
|
"合约代码",
|
|
@@ -320,21 +429,51 @@ def option_shfe_daily(
|
|
|
320
429
|
"行权量",
|
|
321
430
|
]
|
|
322
431
|
]
|
|
432
|
+
contract_df.reset_index(inplace=True, drop=True)
|
|
433
|
+
return contract_df
|
|
434
|
+
except: # noqa: E722
|
|
435
|
+
return pd.DataFrame()
|
|
436
|
+
else:
|
|
437
|
+
return pd.DataFrame()
|
|
323
438
|
|
|
324
|
-
volatility_df.columns = [
|
|
325
|
-
"_",
|
|
326
|
-
"_",
|
|
327
|
-
"_",
|
|
328
|
-
"合约系列",
|
|
329
|
-
"成交量",
|
|
330
|
-
"持仓量",
|
|
331
|
-
"持仓量变化",
|
|
332
|
-
"行权量",
|
|
333
|
-
"成交额",
|
|
334
|
-
"隐含波动率",
|
|
335
|
-
"_",
|
|
336
|
-
]
|
|
337
439
|
|
|
440
|
+
def option_vol_shfe(
|
|
441
|
+
symbol: str = "铝期权", trade_date: str = "20250418"
|
|
442
|
+
) -> pd.DataFrame:
|
|
443
|
+
"""
|
|
444
|
+
上海期货交易所-期权-日频行情数据
|
|
445
|
+
https://www.shfe.com.cn/reports/tradedata/dailyandweeklydata/
|
|
446
|
+
:param trade_date: 交易日
|
|
447
|
+
:type trade_date: str
|
|
448
|
+
:param symbol: choice of {'原油期权', '铜期权', '铝期权', '锌期权', '铅期权', '螺纹钢期权', '镍期权', '锡期权', '氧化铝期权',
|
|
449
|
+
'黄金期权', '白银期权', '丁二烯橡胶期权', '天胶期权'}
|
|
450
|
+
:type symbol: str
|
|
451
|
+
:return: 日频行情数据
|
|
452
|
+
:rtype: pandas.DataFrame
|
|
453
|
+
"""
|
|
454
|
+
calendar = get_calendar()
|
|
455
|
+
day = convert_date(trade_date) if trade_date is not None else datetime.date.today()
|
|
456
|
+
if day.strftime("%Y%m%d") not in calendar:
|
|
457
|
+
warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
|
|
458
|
+
return pd.DataFrame()
|
|
459
|
+
if day > datetime.date(year=2010, month=8, day=24):
|
|
460
|
+
url = f"""https://www.shfe.com.cn/data/tradedata/option/dailydata/kx{day.strftime("%Y%m%d")}.dat"""
|
|
461
|
+
try:
|
|
462
|
+
r = requests.get(url, headers=SHFE_HEADERS)
|
|
463
|
+
json_data = r.json()
|
|
464
|
+
volatility_df = pd.DataFrame(json_data["o_cursigma"])
|
|
465
|
+
volatility_df = volatility_df[
|
|
466
|
+
volatility_df["PRODUCTNAME"].str.strip() == symbol
|
|
467
|
+
]
|
|
468
|
+
volatility_df.rename(columns={
|
|
469
|
+
"INSTRUMENTID": "合约系列",
|
|
470
|
+
"VOLUME": "成交量",
|
|
471
|
+
"OPENINTEREST": "持仓量",
|
|
472
|
+
"OPENINTERESTCHG": "持仓量变化",
|
|
473
|
+
"TURNOVER": "成交额",
|
|
474
|
+
"EXECVOLUME": "行权量",
|
|
475
|
+
"SIGMA": "隐含波动率"
|
|
476
|
+
}, inplace=True)
|
|
338
477
|
volatility_df = volatility_df[
|
|
339
478
|
[
|
|
340
479
|
"合约系列",
|
|
@@ -346,14 +485,15 @@ def option_shfe_daily(
|
|
|
346
485
|
"隐含波动率",
|
|
347
486
|
]
|
|
348
487
|
]
|
|
349
|
-
contract_df.reset_index(inplace=True, drop=True)
|
|
350
488
|
volatility_df.reset_index(inplace=True, drop=True)
|
|
351
|
-
return
|
|
489
|
+
return volatility_df
|
|
352
490
|
except: # noqa: E722
|
|
353
|
-
return
|
|
491
|
+
return pd.DataFrame()
|
|
492
|
+
else:
|
|
493
|
+
return pd.DataFrame()
|
|
354
494
|
|
|
355
495
|
|
|
356
|
-
def
|
|
496
|
+
def option_hist_gfex(symbol: str = "工业硅", trade_date: str = "20230724") -> pd.DataFrame:
|
|
357
497
|
"""
|
|
358
498
|
广州期货交易所-日频率-量价数据
|
|
359
499
|
http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml
|
|
@@ -368,7 +508,7 @@ def option_gfex_daily(symbol: str = "工业硅", trade_date: str = "20230724"):
|
|
|
368
508
|
day = convert_date(trade_date) if trade_date is not None else datetime.date.today()
|
|
369
509
|
if day.strftime("%Y%m%d") not in calendar:
|
|
370
510
|
warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
|
|
371
|
-
return
|
|
511
|
+
return pd.DataFrame()
|
|
372
512
|
url = "http://www.gfex.com.cn/u/interfacesWebTiDayQuotes/loadList"
|
|
373
513
|
payload = {"trade_date": day.strftime("%Y%m%d"), "trade_type": "1"}
|
|
374
514
|
headers = {
|
|
@@ -384,7 +524,7 @@ def option_gfex_daily(symbol: str = "工业硅", trade_date: str = "20230724"):
|
|
|
384
524
|
"Proxy-Connection": "keep-alive",
|
|
385
525
|
"Referer": "http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml",
|
|
386
526
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
387
|
-
|
|
527
|
+
"Chrome/108.0.0.0 Safari/537.36",
|
|
388
528
|
"X-Requested-With": "XMLHttpRequest",
|
|
389
529
|
"content-type": "application/x-www-form-urlencoded",
|
|
390
530
|
}
|
|
@@ -440,7 +580,7 @@ def option_gfex_daily(symbol: str = "工业硅", trade_date: str = "20230724"):
|
|
|
440
580
|
return temp_df
|
|
441
581
|
|
|
442
582
|
|
|
443
|
-
def
|
|
583
|
+
def option_vol_gfex(symbol: str = "碳酸锂", trade_date: str = "20230724"):
|
|
444
584
|
"""
|
|
445
585
|
广州期货交易所-日频率-合约隐含波动率
|
|
446
586
|
http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml
|
|
@@ -454,6 +594,7 @@ def option_gfex_vol_daily(symbol: str = "碳酸锂", trade_date: str = "20230724
|
|
|
454
594
|
symbol_code_map = {
|
|
455
595
|
"工业硅": "si",
|
|
456
596
|
"碳酸锂": "lc",
|
|
597
|
+
"多晶硅": "ps",
|
|
457
598
|
}
|
|
458
599
|
calendar = get_calendar()
|
|
459
600
|
day = convert_date(trade_date) if trade_date is not None else datetime.date.today()
|
|
@@ -475,7 +616,7 @@ def option_gfex_vol_daily(symbol: str = "碳酸锂", trade_date: str = "20230724
|
|
|
475
616
|
"Proxy-Connection": "keep-alive",
|
|
476
617
|
"Referer": "http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml",
|
|
477
618
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
478
|
-
|
|
619
|
+
"Chrome/108.0.0.0 Safari/537.36",
|
|
479
620
|
"X-Requested-With": "XMLHttpRequest",
|
|
480
621
|
"content-type": "application/x-www-form-urlencoded",
|
|
481
622
|
}
|
|
@@ -502,40 +643,20 @@ def option_gfex_vol_daily(symbol: str = "碳酸锂", trade_date: str = "20230724
|
|
|
502
643
|
|
|
503
644
|
|
|
504
645
|
if __name__ == "__main__":
|
|
505
|
-
|
|
506
|
-
print(
|
|
507
|
-
|
|
508
|
-
option_dce_daily_one, option_dce_daily_two = option_dce_daily(
|
|
509
|
-
symbol="黄大豆2号期权", trade_date="20220808"
|
|
510
|
-
)
|
|
511
|
-
print(option_dce_daily_one)
|
|
512
|
-
print(option_dce_daily_two)
|
|
513
|
-
|
|
514
|
-
option_dce_daily_one, option_dce_daily_two = option_dce_daily(
|
|
515
|
-
symbol="苯乙烯期权", trade_date="20230516"
|
|
516
|
-
)
|
|
517
|
-
print(option_dce_daily_one)
|
|
518
|
-
print(option_dce_daily_two)
|
|
646
|
+
option_hist_czce_df = option_hist_czce(symbol="白糖期权", trade_date="20250812")
|
|
647
|
+
print(option_hist_czce_df)
|
|
519
648
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
)
|
|
523
|
-
print(option_dce_daily_one)
|
|
524
|
-
print(option_dce_daily_two)
|
|
649
|
+
option_hist_dce_df = option_hist_dce(symbol="聚丙烯期权", trade_date="20250812")
|
|
650
|
+
print(option_hist_dce_df)
|
|
525
651
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
)
|
|
529
|
-
print(option_shfe_daily_one)
|
|
530
|
-
print(option_shfe_daily_two)
|
|
652
|
+
option_hist_shfe_df = option_hist_shfe(symbol="天胶期权", trade_date="20250418")
|
|
653
|
+
print(option_hist_shfe_df)
|
|
531
654
|
|
|
532
|
-
|
|
533
|
-
print(
|
|
655
|
+
option_vol_shfe_df = option_vol_shfe(symbol="天胶期权", trade_date="20250418")
|
|
656
|
+
print(option_vol_shfe_df)
|
|
534
657
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
)
|
|
538
|
-
print(option_gfex_vol_daily_df)
|
|
658
|
+
option_hist_gfex_df = option_hist_gfex(symbol="工业硅", trade_date="20250801")
|
|
659
|
+
print(option_hist_gfex_df)
|
|
539
660
|
|
|
540
|
-
|
|
541
|
-
print(
|
|
661
|
+
option_vol_gfex_df = option_vol_gfex(symbol="多晶硅", trade_date="20250123")
|
|
662
|
+
print(option_vol_gfex_df)
|