def main2(): # 获取期权基础信息文件 df_info = get_opt_info('510050.SH.csv') df_info_call = df_info[df_info['call_or_put'] == 'C'] df_info_put = df_info[df_info['call_or_put'] == 'P'] df_info_call.reset_index(inplace=True) df_info_put.reset_index(inplace=True) path = os.path.join(__CONFIG_TDX_STK_DIR__, 'vipdoc', 'ds', 'lday') wind_codes = list(set(df_info_call['wind_code'])) wind_codes.sort() df_volume = None for wind_code in wind_codes: print(wind_code) try: df_volume_ = get_price(wind_code, path=path, instrument_type='option', fields=['Volume']) except: continue if df_volume is None: df_volume = df_volume_ else: # 将所有数据合并成一个DataFrame太占用内存,读一个计算一个更快 df_volume = df_volume.add(df_volume_, fill_value=0) path_csv = os.path.join(__CONFIG_H5_OPT_DIR__, 'data', 'call.csv') df_volume.to_csv(path_csv) wind_codes = list(set(df_info_put['wind_code'])) wind_codes.sort() df_volume = None for wind_code in wind_codes: print(wind_code) try: df_volume_ = get_price(wind_code, path=path, instrument_type='option', fields=['Volume']) except: continue if df_volume is None: df_volume = df_volume_ else: df_volume = df_volume.add(df_volume_, fill_value=0) path_csv = os.path.join(__CONFIG_H5_OPT_DIR__, 'data', 'put.csv') df_volume.to_csv(path_csv)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ 读取数据示例 """ from kquant_data.api import get_price pricing = get_price('600000.SH', instrument_type='stock') print(pricing) pricing = get_price(['600000.SH', '000001.SZ'], instrument_type='stock') print(pricing) pricing = get_price(['000001.SZ'], instrument_type='stock', start_date='2010-01-01') print(pricing) pricing = get_price(['000001.SZ'], instrument_type='stock', start_date='2010-01-01', bar_size=300, fields=['Close']) print(pricing) pricing = get_price(['000001.SZ'], instrument_type='stock', start_date='2010-01-01', bar_size=86400) print(pricing) # 拿到的价格是原始价格,需要自己复权 # 向前复权 pricing['Close_forward_factor'] = pricing['Close'] * pricing['forward_factor']
#!/usr/bin/env python # -*- coding: utf-8 -*- """ 读取数据示例 """ from kquant_data.api import get_price pricing = get_price('600000.SH') print(pricing) pricing = get_price(['600000.SH', '000001.SZ']) print(pricing) pricing = get_price(['000001.SZ'], start_date='2010-01-01') print(pricing) pricing = get_price(['000001.SZ'], start_date='2010-01-01', bar_size=300, fields=['Close']) print(pricing) pricing = get_price(['000001.SZ'], start_date='2010-01-01', bar_size=86400) print(pricing) # 拿到的价格是原始价格,需要自己复权 # 向前复权 pricing['Close_forward_factor'] = pricing['Close'] * pricing['forward_factor'] print(pricing) # 向后复权 pricing['Close_backward_factor'] = pricing['Close'] * pricing['backward_factor'] print(pricing)
from kquant_data.api import get_price from kquant_data.option.info import get_opt_info, get_opt_info_filtered_by_month from kquant_data.processing.utils import read_fill_from_dir from kquant_data.config import __CONFIG_H5_OPT_DIR__, __CONFIG_TDX_STK_DIR__ if __name__ == '__main__': # 获取期权基础信息文件 df_info = get_opt_info('510050.SH.csv') df_filtered = get_opt_info_filtered_by_month(df_info, 1806) df_filtered = df_filtered[(df_filtered['listed_date'] <= '2018-04-10')] path = os.path.join(__CONFIG_TDX_STK_DIR__, 'vipdoc', 'ds', 'lday') pricing = get_price(list(df_filtered.index), path=path, instrument_type='option') # print(df) # 这是期权的价格,不是标的的价格 Close = pricing['Close'] # print(Close) path = os.path.join(__CONFIG_H5_OPT_DIR__, 'optionchain', '510050.SH') df_strike_price = pd.DataFrame(index=Close.index, columns=Close.columns) df_strike_price = read_fill_from_dir(path, 'strike_price', df_strike_price) df_strike_price.iloc[-1] = df_info['exercise_price'] df_strike_price.fillna(method='bfill', inplace=True) df_multiplier = pd.DataFrame(index=Close.index, columns=Close.columns) df_multiplier = read_fill_from_dir(path, 'multiplier', df_multiplier) df_multiplier.iloc[-1] = df_info['contract_unit']
#!/usr/bin/env python # -*- coding: utf-8 -*- """ 读取数据示例 """ import os from kquant_data.config import __CONFIG_H5_FUT_DIR__ from kquant_data.api import get_price from kquant_data.option.info import read_optioncontractbasicinfo get_price('sh') root_path = os.path.join(__CONFIG_H5_FUT_DIR__, 'optioncontractbasicinfo', '510050.SH.csv') df_info = read_optioncontractbasicinfo(root_path) # 排序一下,方便显示 df_info = df_info.sort_values( by=['limit_month', 'call_or_put', 'exercise_price']) df_info = df_info.reset_index() # df_info = df_info.set_index(['limit_month', 'call_or_put', 'exercise_price', 'limit_month_m']) df_info = df_info.set_index(['limit_month', 'call_or_put', 'exercise_price']) # df_info.to_csv(r'd:\x.csv', encoding='utf-8-sig') # 选择具体的到期月份,这下可以画T型报价图了 df_filtered = df_info[df_info.index.get_level_values('limit_month') == 1806] df = get_price(list(df_filtered['wind_code']), path=r'D:\shqqday', instrument_type='option', new_symbols=list(df_filtered['trade_code'])) print(df)