关于opt.XXXX表的提取方法,建议先看看query的教程
注意
以下提供几种常见的数据提取的方法的示例:
可以通过get_all_securities获取,也可以通过OPT_CONTRACT_INFO表或OPT_DAILY_PREOPEN表获取
# 通过get_all_securities获,dataframe的过滤方法可以查看 https://www.joinquant.com/view/community/detail/3e93cf2c6bcc0787c2cdd736a0d4117f?type=1
df1 = get_all_securities('options',date=None)
df1.tail()
display_name | name | start_date | end_date | type | |
---|---|---|---|---|---|
SR911P5500.XZCE | SR911P5500.XZCE | SR911P5500.XZCE | 2019-01-22 | 2019-10-10 | options |
SR911P5600.XZCE | SR911P5600.XZCE | SR911P5600.XZCE | 2019-02-12 | 2019-10-10 | options |
SR911P5700.XZCE | SR911P5700.XZCE | SR911P5700.XZCE | 2019-02-26 | 2019-10-10 | options |
SR911P5800.XZCE | SR911P5800.XZCE | SR911P5800.XZCE | 2019-04-12 | 2019-10-10 | options |
SR911P5900.XZCE | SR911P5900.XZCE | SR911P5900.XZCE | 2019-04-16 | 2019-10-10 | options |
# 通过OPT_CONTRACT_INFO 表获取50etf的所有合约 query的过滤方法 https://www.joinquant.com/view/community/detail/433d0e9ed9fed11fc9f7772eab8d9376?type=1
from jqdata import *
df2 = opt.run_query(query(opt.OPT_CONTRACT_INFO).filter(opt.OPT_CONTRACT_INFO.underlying_symbol=='510050.XSHG'))
df2.tail()
id | code | trading_code | name | contract_type | exchange_code | currency_id | underlying_symbol | underlying_name | underlying_exchange | underlying_type | exercise_price | contract_unit | contract_status | list_date | list_reason | list_price | high_limit | low_limit | expire_date | last_trade_date | exercise_date | delivery_date | is_adjust | delist_date | delist_reason | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1903 | 17860 | 10001904.XSHG | 510050P1907M03400 | 50ETF沽7月3400 | PO | XSHG | CNY | 510050.XSHG | 50ETF | XSHG | ETF | 3.4 | 10000 | LIST | 2019-07-02 | 价格波动 | 0.3800 | 0.6820 | 0.0780 | 2019-07-24 | 2019-07-24 | 2019-07-24 | 2019-07-25 | 0 | None | None |
1904 | 17861 | 10001905.XSHG | 510050C1908M03400 | 50ETF购8月3400 | CO | XSHG | CNY | 510050.XSHG | 50ETF | XSHG | ETF | 3.4 | 10000 | LIST | 2019-07-02 | 价格波动 | 0.0245 | 0.2885 | 0.0001 | 2019-08-28 | 2019-08-28 | 2019-08-28 | 2019-08-29 | 0 | None | None |
1905 | 17862 | 10001906.XSHG | 510050P1908M03400 | 50ETF沽8月3400 | PO | XSHG | CNY | 510050.XSHG | 50ETF | XSHG | ETF | 3.4 | 10000 | LIST | 2019-07-02 | 价格波动 | 0.3872 | 0.6892 | 0.0852 | 2019-08-28 | 2019-08-28 | 2019-08-28 | 2019-08-29 | 0 | None | None |
1906 | 17863 | 10001907.XSHG | 510050C1912M03400 | 50ETF购12月3400 | CO | XSHG | CNY | 510050.XSHG | 50ETF | XSHG | ETF | 3.4 | 10000 | LIST | 2019-07-02 | 价格波动 | 0.0962 | 0.3602 | 0.0001 | 2019-12-25 | 2019-12-25 | 2019-12-25 | 2019-12-26 | 0 | None | None |
1907 | 17864 | 10001908.XSHG | 510050P1912M03400 | 50ETF沽12月3400 | PO | XSHG | CNY | 510050.XSHG | 50ETF | XSHG | ETF | 3.4 | 10000 | LIST | 2019-07-02 | 价格波动 | 0.4318 | 0.7338 | 0.1298 | 2019-12-25 | 2019-12-25 | 2019-12-25 | 2019-12-26 | 0 | None | None |
50etf期权的行情数据目前提供有天,分钟,tick级别。
其中天数据可以通过get_price,get_bars函数获取,也可以通过opt.OPT_DAILY_PRICE表获得(OPT_DAILY_PRICE表是盘后更新,get_price等盘中实时更新,对50etf期权,建议直接使用get_price/get_bars获取数据);
分钟数据可以通过 get_price/get_bars获取;
tick数据通过get_ticks获取。
以下仅做示例,关于get_price及get_bars的用法,可以直接查看API。
# 使用get_price 获取多个期权的日行情
get_price(["10001908.XSHG","10001907.XSHG"],end_date='2019-07-03',count=5)
<class 'pandas.core.panel.Panel'> Dimensions: 6 (items) x 5 (major_axis) x 2 (minor_axis) Items axis: open to money Major_axis axis: 2019-06-27 00:00:00 to 2019-07-03 00:00:00 Minor_axis axis: 10001908.XSHG to 10001907.XSHG
# 使用get_bars获取多个期权的15m行情
get_bars(["10001908.XSHG","10001907.XSHG"],end_dt='2019-07-03',count=5,unit='15m')
{'10001908.XSHG': array([(0.4286, 0.4286, 0.4286, 0.4286), (0.4286, 0.4286, 0.4286, 0.4286), (0.4286, 0.4286, 0.4242, 0.4242), (0.4242, 0.4242, 0.4227, 0.4227), (0.4227, 0.4227, 0.4227, 0.4227)], dtype=(numpy.record, [('open', '<f8'), ('high', '<f8'), ('low', '<f8'), ('close', '<f8')])), '10001907.XSHG': array([(0.0899, 0.0899, 0.089, 0.089), (0.0891, 0.0902, 0.0891, 0.0902), (0.0902, 0.0915, 0.0898, 0.0915), (0.0915, 0.0934, 0.0915, 0.0931), (0.0931, 0.0931, 0.0914, 0.0918)], dtype=(numpy.record, [('open', '<f8'), ('high', '<f8'), ('low', '<f8'), ('close', '<f8')]))}
get_ticks的API : https://www.joinquant.com/help/api/help?name=api#get_ticks
# 获取 10001908 在 2019-07-02 的tick数据
get_ticks("10001908.XSHG", end_dt='2019-07-02 15:30:00', start_dt='2019-07-02 09:00:00')
array([(20190702092500.32, 0.4318, 0.4318, 0.4318, 0.0, 0.0), (20190702093000.56, 0.4318, 0.4318, 0.4318, 0.0, 0.0), (20190702093001.03, 0.4318, 0.4318, 0.4318, 0.0, 0.0), ..., (20190702145659.96, 0.4227, 0.4397, 0.4227, 0.0, 0.0), (20190702145701.46, 0.4227, 0.4397, 0.4227, 0.0, 0.0), (20190702150000.008, 0.4227, 0.4397, 0.4227, 0.0, 0.0)], dtype=[('time', '<f8'), ('current', '<f8'), ('high', '<f8'), ('low', '<f8'), ('volume', '<f8'), ('money', '<f8')])
关于query的用法,请查看此篇教程: Query的简单教程
商品期权的行情目前只有天级别的,仅可以通过 opt.OPT_CONTRACT_INFO 表查询。
商品期货没有OPT_DAILY_PREOPEN表,OPT_TRADE_RANK_STK表以及分钟和tick行情数据
from jqdata import *
info_df = opt.run_query(query(opt.OPT_CONTRACT_INFO).filter(opt.OPT_CONTRACT_INFO.underlying_symbol=="SR1911.XZCE"))
info_df.tail()
id | code | trading_code | name | contract_type | exchange_code | currency_id | underlying_symbol | underlying_name | underlying_exchange | underlying_type | exercise_price | contract_unit | contract_status | list_date | list_reason | list_price | high_limit | low_limit | expire_date | last_trade_date | exercise_date | delivery_date | is_adjust | delist_date | delist_reason | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
29 | 13388 | SR911P5700.XZCE | None | 白糖沽11月5700 | PO | XZCE | CNY | SR1911.XZCE | 郑白糖911合约 | XZCE | FUTURE | 5700.0 | 10 | LIST | 2019-02-26 | 合约新挂 | 583.0 | 790.0 | 376.0 | 2019-10-10 | 2019-10-10 | None | None | 0 | None | None |
30 | 14784 | SR911C5800.XZCE | None | 白糖购11月5800 | CO | XZCE | CNY | SR1911.XZCE | 郑白糖911合约 | XZCE | FUTURE | 5800.0 | 10 | LIST | 2019-04-12 | 合约新挂 | 38.0 | 248.5 | 0.5 | 2019-10-10 | 2019-10-10 | None | None | 0 | None | None |
31 | 14786 | SR911P5800.XZCE | None | 白糖沽11月5800 | PO | XZCE | CNY | SR1911.XZCE | 郑白糖911合约 | XZCE | FUTURE | 5800.0 | 10 | LIST | 2019-04-12 | 合约新挂 | 560.5 | 771.0 | 350.0 | 2019-10-10 | 2019-10-10 | None | None | 0 | None | None |
32 | 14799 | SR911C5900.XZCE | None | 白糖购11月5900 | CO | XZCE | CNY | SR1911.XZCE | 郑白糖911合约 | XZCE | FUTURE | 5900.0 | 10 | LIST | 2019-04-16 | 合约新挂 | 64.0 | 280.0 | 0.5 | 2019-10-10 | 2019-10-10 | None | None | 0 | None | None |
33 | 14803 | SR911P5900.XZCE | None | 白糖沽11月5900 | PO | XZCE | CNY | SR1911.XZCE | 郑白糖911合约 | XZCE | FUTURE | 5900.0 | 10 | LIST | 2019-04-16 | 合约新挂 | 556.5 | 772.0 | 340.5 | 2019-10-10 | 2019-10-10 | None | None | 0 | None | None |
from jqdata import *
q = query(opt.OPT_DAILY_PRICE).filter(
opt.OPT_DAILY_PRICE.code=='SR911P5900.XZCE',# 选择标的,多个合约用in_操作,详细查看query教程
opt.OPT_DAILY_PRICE.date<='2019-07-02' # 过滤掉date大于2019-07-02 的数据
).order_by(opt.OPT_DAILY_PRICE.date.desc() # 根据日期排序
).limit(10)
opt.run_query(q)
id | code | exchange_code | date | pre_settle | pre_close | open | high | low | close | change_pct_close | settle_price | change_pct_settle | volume | money | position | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 845809 | SR911P5900.XZCE | XZCE | 2019-07-02 | 891.0 | 0.0 | None | None | None | 0.0 | -100.0 | 824.5 | -7.4635 | 0.0 | 0.0 | 24 |
1 | 844142 | SR911P5900.XZCE | XZCE | 2019-07-01 | 898.0 | 0.0 | None | None | None | 0.0 | -100.0 | 891.0 | -0.7795 | 0.0 | 0.0 | 24 |
2 | 842484 | SR911P5900.XZCE | XZCE | 2019-06-28 | 933.0 | 0.0 | None | None | None | 0.0 | -100.0 | 898.0 | -3.7513 | 0.0 | 0.0 | 24 |
3 | 840827 | SR911P5900.XZCE | XZCE | 2019-06-27 | 909.0 | 0.0 | None | None | None | 0.0 | -100.0 | 933.0 | 2.6403 | 0.0 | 0.0 | 24 |
4 | 839173 | SR911P5900.XZCE | XZCE | 2019-06-26 | 898.5 | 0.0 | None | None | None | 0.0 | -100.0 | 909.0 | 1.1686 | 0.0 | 0.0 | 24 |
5 | 837465 | SR911P5900.XZCE | XZCE | 2019-06-25 | 879.0 | 0.0 | None | None | None | 0.0 | -100.0 | 898.5 | 2.2184 | 0.0 | 0.0 | 24 |
6 | 835723 | SR911P5900.XZCE | XZCE | 2019-06-24 | 858.5 | 0.0 | None | None | None | 0.0 | -100.0 | 879.0 | 2.3879 | 0.0 | 0.0 | 24 |
7 | 833951 | SR911P5900.XZCE | XZCE | 2019-06-21 | 826.0 | 0.0 | None | None | None | 0.0 | -100.0 | 858.5 | 3.9346 | 0.0 | 0.0 | 24 |
8 | 832180 | SR911P5900.XZCE | XZCE | 2019-06-20 | 818.5 | 0.0 | None | None | None | 0.0 | -100.0 | 826.0 | 0.9163 | 0.0 | 0.0 | 24 |
9 | 830415 | SR911P5900.XZCE | XZCE | 2019-06-19 | 830.5 | 0.0 | None | None | None | 0.0 | -100.0 | 818.5 | -1.4449 | 0.0 | 0.0 | 24 |
from jqdata import *
q = query(opt.OPT_DAILY_PRICE).filter(
opt.OPT_DAILY_PRICE.code.like('SR%'), # 选择code中以SR开头的标的,详细查看query教程
opt.OPT_DAILY_PRICE.date=='2019-07-02' # 指定date等于2019-07-02
).order_by(opt.OPT_DAILY_PRICE.date.desc() # 根据日期排序
).limit(10)
opt.run_query(q)
id | code | exchange_code | date | pre_settle | pre_close | open | high | low | close | change_pct_close | settle_price | change_pct_settle | volume | money | position | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 845056 | SR005P5500.XZCE | XZCE | 2019-07-02 | 671.0 | 0.0 | NaN | NaN | NaN | 0.0 | -100.0000 | 637.0 | -5.0671 | 0.0 | 0.0 | 20 |
1 | 845060 | SR001C5600.XZCE | XZCE | 2019-07-02 | 69.5 | 67.5 | 69.5 | 78.5 | 67.5 | 69.5 | 0.0000 | 72.0 | 3.5971 | 664.0 | 480400.0 | 4766 |
2 | 845072 | SR001P5700.XZCE | XZCE | 2019-07-02 | 717.5 | 0.0 | NaN | NaN | NaN | 0.0 | -100.0000 | 670.5 | -6.5505 | 0.0 | 0.0 | 482 |
3 | 845078 | SR909C4800.XZCE | XZCE | 2019-07-02 | 252.0 | 257.5 | 256.5 | 326.5 | 256.5 | 283.5 | 12.5000 | 295.5 | 17.2619 | 430.0 | 1269700.0 | 754 |
4 | 845085 | SR003P5400.XZCE | XZCE | 2019-07-02 | 496.5 | 0.0 | NaN | NaN | NaN | 0.0 | -100.0000 | 453.0 | -8.7613 | 0.0 | 0.0 | 10 |
5 | 845092 | SR911P4800.XZCE | XZCE | 2019-07-02 | 85.0 | 0.0 | 63.5 | 63.5 | 63.5 | 63.5 | -25.2941 | 61.0 | -28.2353 | 60.0 | 37400.0 | 154 |
6 | 845094 | SR005C5200.XZCE | XZCE | 2019-07-02 | 166.5 | 173.0 | 177.0 | 190.0 | 172.5 | 175.0 | 5.1051 | 179.0 | 7.5075 | 326.0 | 594100.0 | 360 |
7 | 845157 | SR003C4400.XZCE | XZCE | 2019-07-02 | 676.5 | 0.0 | NaN | NaN | NaN | 0.0 | -100.0000 | 721.5 | 6.6519 | 0.0 | 0.0 | 10 |
8 | 845158 | SR909P4400.XZCE | XZCE | 2019-07-02 | 4.0 | 4.0 | 3.5 | 4.0 | 2.5 | 3.0 | -25.0000 | 2.5 | -37.5000 | 744.0 | 22300.0 | 9970 |
9 | 845160 | SR003C4800.XZCE | XZCE | 2019-07-02 | 378.0 | 0.0 | NaN | NaN | NaN | 0.0 | -100.0000 | 410.5 | 8.5979 | 0.0 | 0.0 | 0 |
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
移动端课程