期权市场一周纵览

来源:https://uqer.io/community/share/55027679f9f06c7a9ae9a53a

本文档依赖的数据 option_data.csv 可以通过运行 期权高频数据准备 notebook而获取。

  1. from matplotlib import pylab
  2. import pandas as pd
  3. import seaborn as sns
  4. sns.set(style="white", context="talk")
  5. import pandas as pd
  6. pd.options.display.float_format = '{:,>.4f}'.format
  1. res = pd.read_csv('option_data.csv', parse_dates=['pdDateTime'])
  2. res['timeStamp'] = res['dataDate'] + ' ' + res['dataTime']
  3. res['timeStamp'] = pd.to_datetime(res['timeStamp'])
  4. res.optionId = res.optionId.astype('str')
  5. res = res.drop('Unnamed: 0', axis=1)
  6. res.pdDateTime = res.pdDateTime.apply(lambda x:Date(x.year,x.month,x.day))
  7. print('开始日期: ' + res['dataDate'].iloc[0])
  8. print('结束日期: ' + res['dataDate'].iloc[-1])
  9. print('Market Sample: ')
  10. res[['dataDate', 'dataTime', 'optionId', 'lastPrice', 'bidPrice1', 'askPrice1', 'lastPrice(vol)']].head()
  11. 开始日期: 2015-03-05
  12. 结束日期: 2015-03-09
  13. Market Sample:
dataDatedataTimeoptionIdlastPricebidPrice1askPrice1lastPrice(vol)
02015-03-0509:30:00100000010.16770.17170.17650.3468
12015-03-0509:30:14100000010.17170.17170.17650.3768
22015-03-0509:30:15100000010.17170.16100.17980.3768
32015-03-0509:30:16100000010.16780.16100.17980.3525
42015-03-0509:30:18100000010.17980.16410.17980.4205

1. 买卖价差分析

1.1 买卖价差(到期时间)

  1. bidAskSample = res[[u'optionId', 'pdDateTime', 'dataDate', 'contractType', 'strikePrice', 'bidAskSpread(bps)']]
  2. bidAskSample.columns = ['optionId', 'maturity', 'tradingDate', 'contractType', 'strikePrice', 'bidAskSpread(bps)']
  3. tmp = bidAskSample.groupby(['maturity'])[['bidAskSpread(bps)']]
  4. ax = tmp.mean().plot(kind = 'bar', figsize = (12,6), rot = 45)
  5. ax.set_title(u'买卖价差(按照期权到期时间)', fontproperties = font, fontsize = 25)
  6. ax.set_xlabel(u'到期时间', fontproperties = font, fontsize = 15)
  7. <matplotlib.text.Text at 0x7798290>

期权市场一周纵览 - 图1

1.2 买卖价差(行权价)

  1. tmp = bidAskSample.groupby(['maturity', 'strikePrice'])[['bidAskSpread(bps)']].mean().unstack()
  2. ax = tmp.plot(kind = 'bar', figsize = (12,6), legend = True, rot = 45)
  3. patches, labels = ax.get_legend_handles_labels()
  4. labels = ['Strike/' + l.strip('()').split()[1] for l in labels]
  5. ax.legend(patches, labels, loc='best', prop = font)
  6. ax.set_title(u'买卖价差(按照期权行权价)', fontproperties = font, fontsize = 25)
  7. ax.set_xlabel(u'到期时间', fontproperties = font, fontsize = 15)
  8. <matplotlib.text.Text at 0x5bc08d0>

期权市场一周纵览 - 图2

1.3 买卖价差(期权类型)

  1. tmp = bidAskSample.groupby(['maturity', 'contractType'])[['bidAskSpread(bps)']].mean().unstack()
  2. ax = tmp.plot(kind = 'bar', figsize = (12,6), rot = 45)
  3. patches, labels = ax.get_legend_handles_labels()
  4. labels = [l.strip('()').split()[1] for l in labels]
  5. ax.legend(patches, labels, loc='best')
  6. ax.set_title(u'买卖价差(按照期权类型)', fontproperties = font, fontsize = 25)
  7. ax.set_xlabel(u'到期时间', fontproperties = font, fontsize = 15)
  8. <matplotlib.text.Text at 0x7a8d7d0>

期权市场一周纵览 - 图3

2. 日交易量分析

  1. volumeSample = res[[u'optionId', 'pdDateTime', 'dataDate', 'contractType', 'strikePrice', 'volume']]
  2. volumeSample.columns = ['optionId', 'maturity', 'tradingDate', 'contractType', 'strikePrice', 'volume']
  3. tmp = volumeSample.groupby(['tradingDate'])[['volume']].sum()
  4. ax = tmp.plot(kind = 'bar', figsize = (12,6), rot = 45)
  5. ax.set_title(u'日交易量(按交易日期)', fontproperties = font, fontsize = 25)
  6. ax.set_xlabel(u'交易日期', fontproperties = font, fontsize = 15)
  7. <matplotlib.text.Text at 0x7a72d90>

期权市场一周纵览 - 图4

2.1 日交易量(到期时间)

  1. tmp = volumeSample.groupby(['maturity', 'tradingDate'])[['volume']].sum().unstack()
  2. ax = tmp.plot(kind = 'bar', figsize = (12,6), rot = 45)
  3. patches, labels = ax.get_legend_handles_labels()
  4. labels = [l.strip('()').split()[1] for l in labels]
  5. ax.legend(patches, labels, loc='best')
  6. ax.set_title(u'日交易量(按照期权到期时间)', fontproperties = font, fontsize = 25)
  7. ax.set_xlabel(u'到期时间', fontproperties = font, fontsize = 15)

期权市场一周纵览 - 图5

每个交易日不同到期期限期权的交易量:

  1. tmp
volume
tradingDate2015-03-052015-03-062015-03-092015-03-102015-03-11
maturity
March 25th, 201518767.000016704.000031115.000011888.000011562.0000
April 22nd, 20157791.00004468.000013355.00006909.00005632.0000
June 24th, 2015965.0000326.00003091.0000619.0000604.0000
September 23rd, 2015635.0000101.00002426.0000240.0000178.0000

2.2 日交易量(行权价)

  1. tmp = volumeSample.groupby(['tradingDate','strikePrice'])[['volume']].sum().unstack()
  2. ax = tmp.plot(kind = 'bar', figsize = (16,8), rot = 45)
  3. patches, labels = ax.get_legend_handles_labels()
  4. labels = ['Strike/' + l.strip('()').split()[1] for l in labels]
  5. ax.legend(patches, labels, loc='best')
  6. ax.set_title(u'日交易量(按照期权行权价)', fontproperties = font, fontsize = 25)
  7. ax.set_xlabel(u'交易日期', fontproperties = font, fontsize = 15)
  8. <matplotlib.text.Text at 0x7fa5610>

期权市场一周纵览 - 图6

每个交易日不同行权价期权的交易量:

  1. tmp
volume
strikePrice2.20002.25002.30002.35002.40002.45002.50002.5500
tradingDate
2015-03-052597.00001725.00003077.00005351.00005430.00004231.00003148.00002599.0000
2015-03-061352.0000750.00001435.00005219.00004395.00003301.00003143.00002004.0000
2015-03-094576.00003407.00003599.00008954.00009564.00009015.00005969.00004903.0000
2015-03-102225.00001649.00001532.00003237.00003588.00002832.00002343.00002250.0000
2015-03-112021.00001286.00001299.00002959.00003121.00002648.00002565.00002077.0000

2.3 日交易量(期权类型)

  1. tmp = volumeSample.groupby(['tradingDate','contractType'])[['volume']].sum().unstack()
  2. ax = tmp.plot(kind = 'bar', y = ['volume'], figsize = (12,6), rot = 45)
  3. patches, labels = ax.get_legend_handles_labels()
  4. labels = [l.strip('()').split()[1] for l in labels]
  5. ax.legend(patches, labels, loc='best')
  6. ax.set_title(u'日交易量(按照期权类型)', fontproperties = font, fontsize = 25)
  7. ax.set_xlabel(u'交易日期', fontproperties = font, fontsize = 15)
  8. <matplotlib.text.Text at 0x8813e10>

期权市场一周纵览 - 图7

3. 波动率价差分析

  1. bidAskVolSample = res[[u'optionId', 'pdDateTime', 'dataDate', 'contractType', 'strikePrice', 'bidAskSpread(vol bps)']]
  2. bidAskVolSample.columns = ['optionId', 'maturity', 'tradingDate', 'contractType', 'strikePrice', 'bidAskSpread(vol bps)']

3.1 波动率价差(到期时间)

  1. tmp = bidAskVolSample.groupby(['maturity'])[['bidAskSpread(vol bps)']]
  2. ax = tmp.mean().plot(kind = 'bar', figsize = (12,6), rot = 45)
  3. ax.set_title(u'波动率价差(按照期权到期时间)', fontproperties = font, fontsize = 25)
  4. ax.set_xlabel(u'到期时间', fontproperties = font, fontsize = 15)
  5. <matplotlib.text.Text at 0x8c0b7d0>

期权市场一周纵览 - 图8

3.2 波动率价差(行权价)

  1. tmp = bidAskVolSample.groupby(['maturity', 'strikePrice'])[['bidAskSpread(vol bps)']].mean().unstack()
  2. ax = tmp.plot(kind = 'bar', figsize = (14,6), legend = True, rot = 45)
  3. patches, labels = ax.get_legend_handles_labels()
  4. labels = ['strike/' + l.strip('()').split()[-1] for l in labels]
  5. ax.legend(patches, labels, loc='best')
  6. ax.set_title(u'波动率价差(按照期权行权价)', fontproperties = font, fontsize = 25)
  7. ax.set_xlabel(u'到期时间', fontproperties = font, fontsize = 15)

期权市场一周纵览 - 图9

3.3 波动率价差(期权类型)

  1. tmp = bidAskVolSample.groupby(['maturity', 'contractType'])[['bidAskSpread(vol bps)']].mean().unstack()
  2. ax = tmp.plot(kind = 'bar', figsize = (12,6), rot = 45)
  3. patches, labels = ax.get_legend_handles_labels()
  4. labels = [l.split()[-1].strip('()') for l in labels]
  5. ax.legend(patches, labels, loc='best')
  6. ax.set_title(u'波动率价差(按照期权类型)', fontproperties = font, fontsize = 25)
  7. ax.set_xlabel(u'到期时间', fontproperties = font, fontsize = 15)

期权市场一周纵览 - 图10

3.4 波动率价差(交易时间)

  1. tmp = bidAskVolSample.groupby(['tradingDate', 'maturity'])[['bidAskSpread(vol bps)']].mean().unstack()
  2. ax = tmp.plot(kind = 'bar', figsize = (12,6), rot = 45)
  3. patches, labels = ax.get_legend_handles_labels()
  4. labels = [l.split(',')[1].strip('()') for l in labels]
  5. ax.legend(patches, labels, loc='best')
  6. ax.set_title(u'波动率价差(按照交易时间)', fontproperties = font, fontsize = 25)
  7. ax.set_xlabel(u'交易日期', fontproperties = font, fontsize = 15)
  8. <matplotlib.text.Text at 0x8d1fc50>

期权市场一周纵览 - 图11

4. 个券分析

4.1 交易量

  1. tmp = volumeSample.groupby(['tradingDate','optionId'])[['volume']].sum().unstack()
  2. fig, axs = pylab.subplots(len(tmp)/2 + len(tmp)%2, 2, figsize = (16,8 * len(tmp)/2))
  3. for i in range(len(tmp)):
  4. sample = pd.DataFrame(tmp.iloc[i]['volume'])
  5. sample.columns = ['volume']
  6. sample = sample.sort('volume', ascending = False)
  7. sample = sample[:10]
  8. row = i / 2
  9. col = i % 2
  10. sample.plot(kind = 'PIE',y = 'volume', sharex= False, ax = axs[row][col], legend = False, rot = 45)
  11. axs[row][col].set_title(u'交易日: ' + str(tmp.index[i]), fontproperties = font, fontsize = 18)

期权市场一周纵览 - 图12

4.2 买卖价差

  1. tmp = bidAskSample.groupby(['tradingDate','optionId'])[['bidAskSpread(bps)']].mean().unstack()
  2. fig, axs = pylab.subplots(len(tmp)/2 + len(tmp)%2, 2, figsize = (16,8*len(tmp)/2))
  3. for i in range(len(tmp)):
  4. sample = pd.DataFrame(tmp.iloc[i]['bidAskSpread(bps)'])
  5. sample.columns = ['bidAskSpread(bps)']
  6. sample = sample.sort('bidAskSpread(bps)')
  7. sample = sample[:10]
  8. row = i / 2
  9. col = i % 2
  10. sample.plot(kind = 'bar',y = 'bidAskSpread(bps)', sharex= False, ax = axs[row][col], legend = False, rot = 20)
  11. axs[row][col].set_title(u'交易日: ' + str(tmp.index[i]), fontproperties = font, fontsize = 18)

期权市场一周纵览 - 图13

4.3 波动率价差

  1. tmp = bidAskVolSample.groupby(['tradingDate','optionId'])[['bidAskSpread(vol bps)']].mean().unstack()
  2. fig, axs = pylab.subplots(len(tmp)/2 + len(tmp)%2, 2, figsize = (16,8*len(tmp)/2))
  3. for i in range(len(tmp)):
  4. sample = pd.DataFrame(tmp.iloc[i]['bidAskSpread(vol bps)'])
  5. sample.columns = ['bidAskSpread(vol bps)']
  6. sample = sample.sort('bidAskSpread(vol bps)')
  7. sample = sample[:10]
  8. row = i / 2
  9. col = i % 2
  10. sample.plot(kind = 'bar',y = 'bidAskSpread(vol bps)', sharex= False, ax = axs[row][col], legend = False, rot = 20)
  11. axs[row][col].set_title(u'交易日: ' + str(tmp.index[i]), fontproperties = font, fontsize = 18)

期权市场一周纵览 - 图14

4.4 时间序列分析

  1. tmp = volumeSample.groupby(['tradingDate','optionId'])[['volume']].sum().unstack()
  2. for i, d in enumerate(tmp.index):
  3. fig, axs = pylab.subplots(2, 1, figsize = (16,5))
  4. sample = tmp.loc(d)
  5. sample = sample[d]
  6. sample.sort('volume', ascending = False)
  7. base = res[res['dataDate'] == d]
  8. base = base[base.optionId == sample.index[0][1]]
  9. base.index = range(len(base))
  10. base['calTimeStamp'] = base.timeStamp.apply(lambda s: DateTime(s.year, s.month, s.day, s.hour, s.minute, s.second))
  11. ax = base.plot(x = 'calTimeStamp', y = ['volume'], kind = 'bar', sharex=True, xticks = [], color = 'r', ax = axs[0])
  12. ax.set_title(u'交易日: ' + unicode(d) + u' 最活跃期权:'+ unicode(sample.index[0][1]), fontproperties = font, fontsize = 18)
  13. ax = base.plot(x= 'calTimeStamp', y = ['lastPrice(vol)'], sharex=True, legend = True,ax = axs[1], rot = 45)
  14. ax.set_xlabel(u'交易时间', fontproperties = font, fontsize = 15)

期权市场一周纵览 - 图15

期权市场一周纵览 - 图16

期权市场一周纵览 - 图17

期权市场一周纵览 - 图18

期权市场一周纵览 - 图19