def option_czce_daily(symbol: str = "白糖期权", trade_date: str = "20191017") -> pd.DataFrame: """ 郑州商品交易所-期权-日频行情数据 :param trade_date: 交易日 :type trade_date: str :param symbol: choice of {"白糖期权", "棉花期权", "甲醇期权", "PTA期权", "菜籽粕期权", "动力煤期权"} :type symbol: str :return: 日频行情数据 :rtype: pandas.DataFrame """ calendar = get_calendar() day = convert_date( trade_date) if trade_date is not None else datetime.date.today() if day.strftime("%Y%m%d") not in calendar: warnings.warn("{}非交易日".format(day.strftime("%Y%m%d"))) return if day > datetime.date(2010, 8, 24): url = CZCE_DAILY_OPTION_URL_3.format(day.strftime("%Y"), day.strftime("%Y%m%d")) try: r = requests.get(url) f = StringIO(r.text) table_df = pd.read_table(f, encoding="utf-8", skiprows=1, sep="|") if symbol == "白糖期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("SR")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] elif symbol == "PTA期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("TA")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] elif symbol == "甲醇期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("MA")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] elif symbol == "菜籽粕期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("RM")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] elif symbol == "动力煤期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("ZC")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] else: temp_df = table_df[table_df.iloc[:, 0].str.contains("CF")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] except: return
def get_czce_option_daily(trade_date="20191017", symbol="白糖期权"): """ 郑州商品交易所-期权-日频行情数据 说明: (1) 价格:元/吨 (2) 成交量、空盘量:手 (3) 成交额:万元 (4) 涨跌一:今收盘-昨结算 (5) 涨跌二:今结算-昨结算 (6) 隐含波动率:将当日期权合约的结算价代入期权定价模型,反推出来的波动率数值 :param trade_date: str "20191017" :param symbol: str "白糖期权", "棉花期权", "甲醇期权", "PTA期权", "菜籽粕期权" :return: pandas.DataFrame 郑商所每日期权交易数据 品种代码 昨结算 今开盘 最高价 最低价 今收盘 \ 0 CF001C10800 1,579.00 0.00 0.00 0.00 0.00 1 CF001C11000 1,392.00 0.00 0.00 0.00 0.00 2 CF001C11200 1,211.00 0.00 0.00 0.00 0.00 3 CF001C11400 1,038.00 1,396.00 1,396.00 1,396.00 1,396.00 4 CF001C11600 874.00 0.00 0.00 0.00 0.00 .. ... ... ... ... ... ... 398 SR009P5900 576.00 0.00 0.00 0.00 0.00 399 SR009P6000 653.00 0.00 0.00 0.00 0.00 400 小计 401 SR合计 402 总计 今结算 涨跌1 涨跌2 成交量(手) 空盘量 增减量 \ 0 1,866.00 287.00 287.00 0 0 0 1 1,672.00 280.00 280.00 0 0 0 2 1,481.00 270.00 270.00 0 4 0 3 1,295.00 358.00 257.00 2 68 0 4 1,114.00 240.00 240.00 0 224 0 .. ... ... ... ... ... ... 398 580.00 4.00 4.00 0 0 0 399 658.00 5.00 5.00 0 0 0 400 656 860 400 401 32,098 276,900 2252 402 110,664 474,154 14770 成交额(万元) DELTA 隐含波动率 行权量 0 0.00 0.9765 22.29 0 1 0.00 0.9621 21.84 0 2 0.00 0.9423 21.38 0 3 1.40 0.9155 20.91 0 4 0.00 0.8800 20.45 0 .. ... ... ... ... 398 0.00 -0.6639 16.24 0 399 0.00 -0.7007 16.58 0 400 97.28 0 401 2138.41 0 402 8769.52 2 """ calendar = get_calendar() day = convert_date( trade_date) if trade_date is not None else datetime.date.today() if day.strftime("%Y%m%d") not in calendar: warnings.warn("{}非交易日".format(day.strftime("%Y%m%d"))) return None if day > datetime.date(2010, 8, 24): url = CZCE_DAILY_OPTION_URL_3.format(day.strftime("%Y"), day.strftime("%Y%m%d")) try: r = requests.get(url) f = StringIO(r.text) table_df = pd.read_table(f, encoding="utf-8", skiprows=1, sep="|") if symbol == "白糖期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("SR")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] elif symbol == "PTA期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("TA")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] elif symbol == "甲醇期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("MA")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] elif symbol == "菜籽粕期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("RM")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] elif symbol == "动力煤期权": temp_df = table_df[table_df.iloc[:, 0].str.contains("ZC")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] else: temp_df = table_df[table_df.iloc[:, 0].str.contains("CF")] temp_df.reset_index(inplace=True, drop=True) return temp_df.iloc[:-1, :] except: return None