akshare 1.13.46__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 +757 -161
- akshare/air/air_hebei.py +79 -53
- akshare/air/air_zhenqi.py +3 -7
- akshare/air/cons.py +1 -0
- akshare/air/crypto.js +1 -1
- akshare/air/outcrypto.js +1 -1
- akshare/air/sunrise_tad.py +32 -17
- 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 +75 -48
- akshare/bond/bond_convert.py +10 -9
- akshare/bond/bond_em.py +37 -17
- akshare/bond/bond_info_cm.py +28 -8
- akshare/bond/bond_issue_cninfo.py +73 -30
- akshare/bond/bond_summary.py +38 -37
- akshare/bond/bond_zh_cov.py +31 -40
- akshare/bond/bond_zh_sina.py +61 -51
- 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/currency/currency_safe.py +7 -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 +163 -117
- akshare/economic/macro_china_hk.py +0 -1
- akshare/economic/macro_china_nbs.py +24 -7
- akshare/economic/macro_euro.py +103 -56
- akshare/economic/macro_finance_ths.py +135 -0
- akshare/economic/macro_germany.py +1 -1
- akshare/economic/macro_info_ws.py +100 -0
- 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 +94 -126
- akshare/energy/energy_oil_em.py +1 -2
- akshare/event/cons.py +1 -0
- akshare/event/migration.py +3 -2
- 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 +15 -48
- 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_amac.py +38 -15
- 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 +76 -27
- akshare/fund/fund_etf_ths.py +95 -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 +78 -66
- akshare/fund/fund_position_lg.py +19 -8
- akshare/fund/fund_rank_em.py +90 -84
- akshare/fund/fund_rating.py +33 -12
- akshare/fund/fund_report_cninfo.py +63 -48
- 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 +141 -46
- akshare/futures/cot.py +89 -88
- akshare/futures/futures_basis.py +99 -33
- akshare/futures/futures_comex_em.py +1 -0
- akshare/futures/futures_comm_ctp.py +13 -2
- akshare/futures/futures_contract_detail.py +59 -9
- akshare/futures/futures_daily_bar.py +75 -62
- 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 +79 -61
- 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 +1 -2
- akshare/futures/futures_to_spot.py +43 -39
- akshare/futures/futures_warehouse_receipt.py +53 -48
- akshare/futures/futures_zh_sina.py +4 -4
- 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 +7 -8
- akshare/futures_derivative/futures_cot_sina.py +28 -19
- akshare/futures_derivative/futures_index_sina.py +25 -13
- akshare/fx/cons.py +12 -7
- akshare/fx/currency_investing.py +19 -285
- 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_cflp.py +29 -26
- akshare/index/index_cni.py +89 -91
- akshare/index/index_cons.py +26 -10
- akshare/index/index_csindex.py +68 -0
- akshare/index/index_cx.py +263 -62
- 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 +38 -38
- akshare/index/index_spot.py +9 -5
- akshare/index/index_stock_hk.py +6 -10
- akshare/index/index_stock_us_sina.py +1 -1
- akshare/index/index_stock_zh.py +193 -101
- akshare/index/index_stock_zh_csindex.py +15 -369
- akshare/index/index_sugar.py +18 -4
- akshare/index/index_sw.py +62 -34
- akshare/index/index_yw.py +53 -75
- akshare/index/index_zh_em.py +15 -82
- akshare/interest_rate/interbank_rate_em.py +14 -10
- akshare/movie/artist_yien.py +32 -5
- akshare/movie/jm.js +0 -1
- akshare/movie/movie_yien.py +92 -18
- akshare/movie/video_yien.py +28 -5
- akshare/news/__init__.py +1 -1
- akshare/news/news_baidu.py +395 -220
- akshare/news/news_cctv.py +38 -38
- akshare/news/news_stock.py +49 -13
- akshare/nlp/nlp_interface.py +7 -8
- akshare/option/cons.py +12 -12
- akshare/option/option_comm_qihuo.py +86 -0
- akshare/option/option_commodity.py +355 -211
- 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 +145 -0
- akshare/option/option_em.py +4 -8
- akshare/option/option_finance.py +60 -12
- akshare/option/option_finance_sina.py +28 -26
- akshare/option/option_lhb_em.py +62 -57
- 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 +18 -16
- akshare/option/option_value_analysis_em.py +62 -55
- akshare/other/__init__.py +1 -1
- akshare/other/other_car_cpca.py +20 -20
- 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 +232 -0
- akshare/spot/spot_price_qh.py +121 -0
- akshare/spot/spot_sge.py +70 -9
- akshare/stock/cons.py +60 -23
- akshare/stock/stock_allotment_cninfo.py +10 -9
- 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_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 +36 -16
- akshare/stock/stock_dzjy_em.py +347 -260
- akshare/stock/stock_fund_em.py +73 -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 +107 -0
- 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 +91 -42
- akshare/stock/stock_hold_control_cninfo.py +100 -15
- akshare/stock/stock_hold_control_em.py +4 -5
- akshare/stock/stock_hold_num_cninfo.py +18 -12
- 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 +25 -20
- akshare/stock/stock_industry_pe_cninfo.py +45 -31
- akshare/stock/stock_industry_sw.py +5 -9
- akshare/stock/stock_info.py +31 -19
- akshare/stock/stock_info_em.py +17 -11
- akshare/stock/stock_intraday_em.py +9 -80
- akshare/stock/stock_intraday_sina.py +2 -2
- 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_profile_em.py +302 -0
- akshare/stock/stock_rank_forecast.py +8 -6
- akshare/stock/stock_repurchase_em.py +7 -2
- akshare/stock/stock_share_changes_cninfo.py +18 -14
- 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 +19 -11
- akshare/stock/stock_us_js.py +3 -2
- akshare/stock/stock_us_pink.py +38 -27
- akshare/stock/stock_us_sina.py +15 -12
- akshare/stock/stock_weibo_nlp.py +18 -20
- akshare/stock/stock_xq.py +36 -9
- akshare/stock/stock_zh_a_sina.py +58 -80
- 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 +32 -55
- akshare/stock/stock_zh_comparison_em.py +250 -0
- akshare/stock/stock_zh_kcb_report.py +11 -9
- 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_below_net_asset_statistics.py +5 -2
- akshare/stock_feature/stock_a_high_low.py +5 -2
- akshare/stock_feature/stock_a_indicator.py +15 -57
- akshare/stock_feature/stock_a_pe_and_pb.py +39 -9
- 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 +144 -252
- akshare/stock_feature/stock_board_industry_ths.py +137 -401
- 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_concept_futu.py +183 -0
- 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 +20 -10
- 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 +33 -15
- akshare/stock_feature/stock_fhps_em.py +62 -26
- akshare/stock_feature/stock_fhps_ths.py +34 -7
- akshare/stock_feature/stock_fund_flow.py +38 -25
- 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 +158 -237
- 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 +8 -81
- akshare/stock_feature/stock_inner_trade_xq.py +38 -31
- akshare/stock_feature/stock_irm_cninfo.py +32 -9
- akshare/stock_feature/stock_jgdy_em.py +43 -40
- akshare/stock_feature/stock_lh_yybpm.py +36 -37
- akshare/stock_feature/stock_lhb_em.py +165 -35
- akshare/stock_feature/stock_lhb_sina.py +93 -46
- akshare/stock_feature/stock_margin_em.py +101 -0
- akshare/stock_feature/{stock_sse_margin.py → stock_margin_sse.py} +21 -17
- akshare/stock_feature/{stock_szse_margin.py → stock_margin_szse.py} +7 -7
- akshare/stock_feature/stock_market_legu.py +4 -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 +152 -8
- akshare/stock_feature/stock_research_report_em.py +55 -20
- akshare/stock_feature/stock_sns_sseinfo.py +15 -12
- akshare/stock_feature/stock_sy_em.py +20 -15
- akshare/stock_feature/stock_technology_ths.py +152 -120
- akshare/stock_feature/stock_tfp_em.py +37 -14
- akshare/stock_feature/stock_three_report_em.py +120 -78
- 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_valuation_baidu.py +3 -2
- 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} +203 -59
- 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 +41 -18
- 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_register_em.py +448 -0
- akshare/stock_fundamental/stock_zygc.py +5 -62
- akshare/tool/trade_date_hist.py +1 -1
- 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/utils/tqdm.py +13 -3
- {akshare-1.13.46.dist-info → akshare-1.17.99.dist-info}/METADATA +56 -86
- akshare-1.17.99.dist-info/RECORD +409 -0
- {akshare-1.13.46.dist-info → akshare-1.17.99.dist-info}/WHEEL +1 -1
- {akshare-1.13.46.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/fortune/fortune_it_juzi.py +0 -123
- 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 -51
- 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/sport/sport_olympic_winter.py +0 -39
- akshare/stock_feature/stock_wencai.py +0 -104
- akshare/stock_fundamental/stock_mda_ym.py +0 -40
- akshare/stock_fundamental/stock_register.py +0 -292
- akshare-1.13.46.dist-info/RECORD +0 -380
- {akshare-1.13.46.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日起,纤维板报价单位由元/张改为元/立方米
|
|
@@ -13,10 +13,10 @@ Desc: 商品期权数据
|
|
|
13
13
|
(7) 合约系列:具有相同月份标的期货合约的所有期权合约的统称
|
|
14
14
|
(8) 隐含波动率:根据期权市场价格,利用期权定价模型计算的标的期货合约价格波动率
|
|
15
15
|
"""
|
|
16
|
+
|
|
16
17
|
import datetime
|
|
17
18
|
import warnings
|
|
18
|
-
from io import StringIO
|
|
19
|
-
from typing import Tuple, Any
|
|
19
|
+
from io import StringIO
|
|
20
20
|
|
|
21
21
|
import pandas as pd
|
|
22
22
|
import requests
|
|
@@ -24,129 +24,173 @@ import requests
|
|
|
24
24
|
from akshare.option.cons import (
|
|
25
25
|
get_calendar,
|
|
26
26
|
convert_date,
|
|
27
|
-
DCE_DAILY_OPTION_URL,
|
|
28
|
-
SHFE_OPTION_URL,
|
|
29
27
|
CZCE_DAILY_OPTION_URL_3,
|
|
30
28
|
SHFE_HEADERS,
|
|
31
29
|
)
|
|
32
30
|
|
|
33
31
|
|
|
34
|
-
def
|
|
35
|
-
|
|
36
|
-
) ->
|
|
32
|
+
def option_hist_dce(
|
|
33
|
+
symbol: str = "聚丙烯期权", trade_date: str = "20251016"
|
|
34
|
+
) -> pd.DataFrame:
|
|
37
35
|
"""
|
|
38
36
|
大连商品交易所-期权-日频行情数据
|
|
39
37
|
http://www.dce.com.cn/
|
|
40
38
|
:param trade_date: 交易日
|
|
41
39
|
:type trade_date: str
|
|
42
|
-
:param symbol: choice of {"玉米期权", "豆粕期权", "铁矿石期权", "液化石油气期权", "聚乙烯期权", "聚氯乙烯期权",
|
|
40
|
+
:param symbol: choice of {"玉米期权", "豆粕期权", "铁矿石期权", "液化石油气期权", "聚乙烯期权", "聚氯乙烯期权",
|
|
41
|
+
"聚丙烯期权", "棕榈油期权", "黄大豆1号期权", "黄大豆2号期权", "豆油期权", "乙二醇期权", "苯乙烯期权",
|
|
42
|
+
"鸡蛋期权", "玉米淀粉期权", "生猪期权", "原木期权"}
|
|
43
43
|
:type symbol: str
|
|
44
44
|
:return: 日频行情数据
|
|
45
45
|
:rtype: pandas.DataFrame
|
|
46
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
|
+
}
|
|
47
66
|
calendar = get_calendar()
|
|
48
67
|
day = convert_date(trade_date) if trade_date is not None else datetime.date.today()
|
|
49
68
|
if day.strftime("%Y%m%d") not in calendar:
|
|
50
69
|
warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
|
|
51
|
-
return
|
|
52
|
-
url =
|
|
70
|
+
return pd.DataFrame()
|
|
71
|
+
url = "http://www.dce.com.cn/dcereport/publicweb/dailystat/dayQuotes"
|
|
53
72
|
payload = {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
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]}",
|
|
60
80
|
}
|
|
61
|
-
|
|
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
|
-
table_df[table_df["商品名称"] == "豆油"],
|
|
123
|
-
another_df[another_df.iloc[:, 0].str.contains("y")],
|
|
124
|
-
)
|
|
125
|
-
elif symbol == "乙二醇期权":
|
|
126
|
-
result_one_df, result_two_df = (
|
|
127
|
-
table_df[table_df["商品名称"] == "乙二醇"],
|
|
128
|
-
another_df[another_df.iloc[:, 0].str.contains("eg")],
|
|
129
|
-
)
|
|
130
|
-
elif symbol == "苯乙烯期权":
|
|
131
|
-
result_one_df, result_two_df = (
|
|
132
|
-
table_df[table_df["商品名称"] == "苯乙烯"],
|
|
133
|
-
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')
|
|
134
142
|
)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
|
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)
|
|
179
|
+
|
|
180
|
+
return df_copy
|
|
139
181
|
|
|
140
182
|
|
|
141
|
-
def
|
|
142
|
-
|
|
183
|
+
def option_hist_czce(
|
|
184
|
+
symbol: str = "白糖期权", trade_date: str = "20191017"
|
|
143
185
|
) -> pd.DataFrame:
|
|
144
186
|
"""
|
|
145
187
|
郑州商品交易所-期权-日频行情数据
|
|
146
|
-
|
|
188
|
+
http://www.czce.com.cn/cn/sspz/dejbqhqq/H770227index_1.htm#tabs-2
|
|
147
189
|
:param trade_date: 交易日
|
|
148
190
|
:type trade_date: str
|
|
149
|
-
:param symbol: choice of {"白糖期权", "棉花期权", "甲醇期权", "PTA期权", "
|
|
191
|
+
:param symbol: choice of {"白糖期权", "棉花期权", "甲醇期权", "PTA期权", "动力煤期权", "菜籽粕期权", "菜籽油期权",
|
|
192
|
+
"花生期权", "对二甲苯期权", "烧碱期权", "纯碱期权", "短纤期权", "锰硅期权", "硅铁期权", "尿素期权", "苹果期权", "红枣期权",
|
|
193
|
+
"玻璃期权", "瓶片期权", "丙烯期货"}
|
|
150
194
|
:type symbol: str
|
|
151
195
|
:return: 日频行情数据
|
|
152
196
|
:rtype: pandas.DataFrame
|
|
@@ -156,80 +200,174 @@ def option_czce_daily(
|
|
|
156
200
|
if day.strftime("%Y%m%d") not in calendar:
|
|
157
201
|
warnings.warn("{}非交易日".format(day.strftime("%Y%m%d")))
|
|
158
202
|
return pd.DataFrame()
|
|
159
|
-
if day > datetime.date(2010, 8, 24):
|
|
203
|
+
if day > datetime.date(year=2010, month=8, day=24):
|
|
160
204
|
url = CZCE_DAILY_OPTION_URL_3.format(day.strftime("%Y"), day.strftime("%Y%m%d"))
|
|
161
205
|
try:
|
|
162
206
|
r = requests.get(url)
|
|
163
207
|
f = StringIO(r.text)
|
|
164
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
|
+
]
|
|
165
227
|
if symbol == "白糖期权":
|
|
166
228
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SR")]
|
|
167
229
|
temp_df.reset_index(inplace=True, drop=True)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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")]
|
|
171
235
|
temp_df.reset_index(inplace=True, drop=True)
|
|
172
|
-
|
|
236
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
237
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
238
|
+
return new_df
|
|
173
239
|
elif symbol == "甲醇期权":
|
|
174
240
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("MA")]
|
|
175
241
|
temp_df.reset_index(inplace=True, drop=True)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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")]
|
|
179
247
|
temp_df.reset_index(inplace=True, drop=True)
|
|
180
|
-
|
|
248
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
249
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
250
|
+
return new_df
|
|
181
251
|
elif symbol == "动力煤期权":
|
|
182
252
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("ZC")]
|
|
183
253
|
temp_df.reset_index(inplace=True, drop=True)
|
|
184
|
-
|
|
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
|
|
185
263
|
elif symbol == "菜籽油期权":
|
|
186
264
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("OI")]
|
|
187
265
|
temp_df.reset_index(inplace=True, drop=True)
|
|
188
|
-
|
|
266
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
267
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
268
|
+
return new_df
|
|
189
269
|
elif symbol == "花生期权":
|
|
190
270
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("PK")]
|
|
191
271
|
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, :]
|
|
272
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
273
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
274
|
+
return new_df
|
|
197
275
|
elif symbol == "短纤期权":
|
|
198
276
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("PF")]
|
|
199
277
|
temp_df.reset_index(inplace=True, drop=True)
|
|
200
|
-
|
|
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
|
|
201
293
|
elif symbol == "纯碱期权":
|
|
202
294
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SA")]
|
|
203
295
|
temp_df.reset_index(inplace=True, drop=True)
|
|
204
|
-
|
|
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
|
|
205
305
|
elif symbol == "锰硅期权":
|
|
206
306
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SM")]
|
|
207
307
|
temp_df.reset_index(inplace=True, drop=True)
|
|
208
|
-
|
|
308
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
309
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
310
|
+
return new_df
|
|
209
311
|
elif symbol == "硅铁期权":
|
|
210
312
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("SF")]
|
|
211
313
|
temp_df.reset_index(inplace=True, drop=True)
|
|
212
|
-
|
|
314
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
315
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
316
|
+
return new_df
|
|
213
317
|
elif symbol == "尿素期权":
|
|
214
318
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("UR")]
|
|
215
319
|
temp_df.reset_index(inplace=True, drop=True)
|
|
216
|
-
|
|
217
|
-
|
|
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 == "苹果期权":
|
|
218
324
|
temp_df = table_df[table_df.iloc[:, 0].str.contains("AP")]
|
|
219
325
|
temp_df.reset_index(inplace=True, drop=True)
|
|
220
|
-
|
|
221
|
-
|
|
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")]
|
|
331
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
332
|
+
temp_df = temp_df.iloc[:-1, :].copy()
|
|
333
|
+
new_df = __option_czce_daily_convert_numeric_columns(temp_df)
|
|
334
|
+
return new_df
|
|
335
|
+
elif symbol == "玻璃期权":
|
|
336
|
+
temp_df = table_df[table_df.iloc[:, 0].str.contains("FG")]
|
|
337
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
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")]
|
|
343
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
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")]
|
|
349
|
+
temp_df.reset_index(inplace=True, drop=True)
|
|
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()
|
|
355
|
+
except: # noqa: E722
|
|
222
356
|
return pd.DataFrame()
|
|
357
|
+
else:
|
|
358
|
+
return pd.DataFrame()
|
|
223
359
|
|
|
224
360
|
|
|
225
|
-
def
|
|
226
|
-
|
|
361
|
+
def option_hist_shfe(
|
|
362
|
+
symbol: str = "铝期权", trade_date: str = "20250418"
|
|
227
363
|
) -> pd.DataFrame:
|
|
228
364
|
"""
|
|
229
365
|
上海期货交易所-期权-日频行情数据
|
|
366
|
+
https://www.shfe.com.cn/reports/tradedata/dailyandweeklydata/
|
|
230
367
|
:param trade_date: 交易日
|
|
231
368
|
:type trade_date: str
|
|
232
|
-
:param symbol: choice of {
|
|
369
|
+
:param symbol: choice of {'原油期权', '铜期权', '铝期权', '锌期权', '铅期权', '螺纹钢期权', '镍期权', '锡期权', '氧化铝期权',
|
|
370
|
+
'黄金期权', '白银期权', '丁二烯橡胶期权', '天胶期权'}
|
|
233
371
|
:type symbol: str
|
|
234
372
|
:return: 日频行情数据
|
|
235
373
|
:rtype: pandas.DataFrame
|
|
@@ -238,9 +376,9 @@ def option_shfe_daily(
|
|
|
238
376
|
day = convert_date(trade_date) if trade_date is not None else datetime.date.today()
|
|
239
377
|
if day.strftime("%Y%m%d") not in calendar:
|
|
240
378
|
warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
|
|
241
|
-
return
|
|
242
|
-
if day > datetime.date(2010, 8, 24):
|
|
243
|
-
url =
|
|
379
|
+
return pd.DataFrame()
|
|
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"""
|
|
244
382
|
try:
|
|
245
383
|
r = requests.get(url, headers=SHFE_HEADERS)
|
|
246
384
|
json_data = r.json()
|
|
@@ -253,35 +391,25 @@ def option_shfe_daily(
|
|
|
253
391
|
]
|
|
254
392
|
)
|
|
255
393
|
contract_df = table_df[table_df["PRODUCTNAME"].str.strip() == symbol]
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
"持仓量变化",
|
|
276
|
-
"_",
|
|
277
|
-
"行权量",
|
|
278
|
-
"成交额",
|
|
279
|
-
"德尔塔",
|
|
280
|
-
"_",
|
|
281
|
-
"_",
|
|
282
|
-
"_",
|
|
283
|
-
"_",
|
|
284
|
-
]
|
|
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
|
+
)
|
|
285
413
|
contract_df = contract_df[
|
|
286
414
|
[
|
|
287
415
|
"合约代码",
|
|
@@ -301,21 +429,51 @@ def option_shfe_daily(
|
|
|
301
429
|
"行权量",
|
|
302
430
|
]
|
|
303
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()
|
|
304
438
|
|
|
305
|
-
volatility_df.columns = [
|
|
306
|
-
"_",
|
|
307
|
-
"_",
|
|
308
|
-
"_",
|
|
309
|
-
"合约系列",
|
|
310
|
-
"成交量",
|
|
311
|
-
"持仓量",
|
|
312
|
-
"持仓量变化",
|
|
313
|
-
"行权量",
|
|
314
|
-
"成交额",
|
|
315
|
-
"隐含波动率",
|
|
316
|
-
"_",
|
|
317
|
-
]
|
|
318
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)
|
|
319
477
|
volatility_df = volatility_df[
|
|
320
478
|
[
|
|
321
479
|
"合约系列",
|
|
@@ -327,14 +485,15 @@ def option_shfe_daily(
|
|
|
327
485
|
"隐含波动率",
|
|
328
486
|
]
|
|
329
487
|
]
|
|
330
|
-
contract_df.reset_index(inplace=True, drop=True)
|
|
331
488
|
volatility_df.reset_index(inplace=True, drop=True)
|
|
332
|
-
return
|
|
333
|
-
except:
|
|
334
|
-
return
|
|
489
|
+
return volatility_df
|
|
490
|
+
except: # noqa: E722
|
|
491
|
+
return pd.DataFrame()
|
|
492
|
+
else:
|
|
493
|
+
return pd.DataFrame()
|
|
335
494
|
|
|
336
495
|
|
|
337
|
-
def
|
|
496
|
+
def option_hist_gfex(symbol: str = "工业硅", trade_date: str = "20230724") -> pd.DataFrame:
|
|
338
497
|
"""
|
|
339
498
|
广州期货交易所-日频率-量价数据
|
|
340
499
|
http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml
|
|
@@ -349,7 +508,7 @@ def option_gfex_daily(symbol: str = "工业硅", trade_date: str = "20230724"):
|
|
|
349
508
|
day = convert_date(trade_date) if trade_date is not None else datetime.date.today()
|
|
350
509
|
if day.strftime("%Y%m%d") not in calendar:
|
|
351
510
|
warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
|
|
352
|
-
return
|
|
511
|
+
return pd.DataFrame()
|
|
353
512
|
url = "http://www.gfex.com.cn/u/interfacesWebTiDayQuotes/loadList"
|
|
354
513
|
payload = {"trade_date": day.strftime("%Y%m%d"), "trade_type": "1"}
|
|
355
514
|
headers = {
|
|
@@ -364,7 +523,8 @@ def option_gfex_daily(symbol: str = "工业硅", trade_date: str = "20230724"):
|
|
|
364
523
|
"Pragma": "no-cache",
|
|
365
524
|
"Proxy-Connection": "keep-alive",
|
|
366
525
|
"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)
|
|
526
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
527
|
+
"Chrome/108.0.0.0 Safari/537.36",
|
|
368
528
|
"X-Requested-With": "XMLHttpRequest",
|
|
369
529
|
"content-type": "application/x-www-form-urlencoded",
|
|
370
530
|
}
|
|
@@ -415,12 +575,12 @@ def option_gfex_daily(symbol: str = "工业硅", trade_date: str = "20230724"):
|
|
|
415
575
|
"隐含波动率",
|
|
416
576
|
]
|
|
417
577
|
]
|
|
418
|
-
temp_df = temp_df[temp_df[
|
|
578
|
+
temp_df = temp_df[temp_df["商品名称"].str.contains(symbol)]
|
|
419
579
|
temp_df.reset_index(inplace=True, drop=True)
|
|
420
580
|
return temp_df
|
|
421
581
|
|
|
422
582
|
|
|
423
|
-
def
|
|
583
|
+
def option_vol_gfex(symbol: str = "碳酸锂", trade_date: str = "20230724"):
|
|
424
584
|
"""
|
|
425
585
|
广州期货交易所-日频率-合约隐含波动率
|
|
426
586
|
http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml
|
|
@@ -434,6 +594,7 @@ def option_gfex_vol_daily(symbol: str = "碳酸锂", trade_date: str = "20230724
|
|
|
434
594
|
symbol_code_map = {
|
|
435
595
|
"工业硅": "si",
|
|
436
596
|
"碳酸锂": "lc",
|
|
597
|
+
"多晶硅": "ps",
|
|
437
598
|
}
|
|
438
599
|
calendar = get_calendar()
|
|
439
600
|
day = convert_date(trade_date) if trade_date is not None else datetime.date.today()
|
|
@@ -454,7 +615,8 @@ def option_gfex_vol_daily(symbol: str = "碳酸锂", trade_date: str = "20230724
|
|
|
454
615
|
"Pragma": "no-cache",
|
|
455
616
|
"Proxy-Connection": "keep-alive",
|
|
456
617
|
"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)
|
|
618
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
619
|
+
"Chrome/108.0.0.0 Safari/537.36",
|
|
458
620
|
"X-Requested-With": "XMLHttpRequest",
|
|
459
621
|
"content-type": "application/x-www-form-urlencoded",
|
|
460
622
|
}
|
|
@@ -475,44 +637,26 @@ def option_gfex_vol_daily(symbol: str = "碳酸锂", trade_date: str = "20230724
|
|
|
475
637
|
"隐含波动率",
|
|
476
638
|
]
|
|
477
639
|
]
|
|
478
|
-
temp_df = temp_df[temp_df[
|
|
640
|
+
temp_df = temp_df[temp_df["合约系列"].str.contains(symbol_code_map[symbol])]
|
|
479
641
|
temp_df.reset_index(inplace=True, drop=True)
|
|
480
642
|
return temp_df
|
|
481
643
|
|
|
482
644
|
|
|
483
645
|
if __name__ == "__main__":
|
|
484
|
-
|
|
485
|
-
print(
|
|
486
|
-
|
|
487
|
-
option_dce_daily_one, option_dce_daily_two = option_dce_daily(
|
|
488
|
-
symbol="黄大豆2号期权", trade_date="20220808"
|
|
489
|
-
)
|
|
490
|
-
print(option_dce_daily_one)
|
|
491
|
-
print(option_dce_daily_two)
|
|
646
|
+
option_hist_czce_df = option_hist_czce(symbol="白糖期权", trade_date="20250812")
|
|
647
|
+
print(option_hist_czce_df)
|
|
492
648
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
)
|
|
496
|
-
print(option_dce_daily_one)
|
|
497
|
-
print(option_dce_daily_two)
|
|
649
|
+
option_hist_dce_df = option_hist_dce(symbol="聚丙烯期权", trade_date="20250812")
|
|
650
|
+
print(option_hist_dce_df)
|
|
498
651
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
)
|
|
502
|
-
print(option_dce_daily_one)
|
|
503
|
-
print(option_dce_daily_two)
|
|
504
|
-
|
|
505
|
-
option_shfe_daily_one, option_shfe_daily_two = option_shfe_daily(
|
|
506
|
-
symbol="天胶期权", trade_date="20210312"
|
|
507
|
-
)
|
|
508
|
-
print(option_shfe_daily_one)
|
|
509
|
-
print(option_shfe_daily_two)
|
|
652
|
+
option_hist_shfe_df = option_hist_shfe(symbol="天胶期权", trade_date="20250418")
|
|
653
|
+
print(option_hist_shfe_df)
|
|
510
654
|
|
|
511
|
-
|
|
512
|
-
print(
|
|
655
|
+
option_vol_shfe_df = option_vol_shfe(symbol="天胶期权", trade_date="20250418")
|
|
656
|
+
print(option_vol_shfe_df)
|
|
513
657
|
|
|
514
|
-
|
|
515
|
-
print(
|
|
658
|
+
option_hist_gfex_df = option_hist_gfex(symbol="工业硅", trade_date="20250801")
|
|
659
|
+
print(option_hist_gfex_df)
|
|
516
660
|
|
|
517
|
-
|
|
518
|
-
print(
|
|
661
|
+
option_vol_gfex_df = option_vol_gfex(symbol="多晶硅", trade_date="20250123")
|
|
662
|
+
print(option_vol_gfex_df)
|