返回介绍

第一部分 新手入门

第二部分 股票量化相关

第三部分 基金、利率互换、固定收益类

第四部分 衍生品相关

期权市场一周纵览

发布于 2022-02-20 22:26:20 字数 21043 浏览 912 评论 0 收藏 0

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

from matplotlib import pylab
import pandas as pd
import seaborn as sns
sns.set(style="white", context="talk")

import pandas as pd
pd.options.display.float_format = '{:,>.4f}'.format
res = pd.read_csv('option_data.csv', parse_dates=['pdDateTime'])
res['timeStamp'] = res['dataDate'] + ' ' + res['dataTime']
res['timeStamp'] = pd.to_datetime(res['timeStamp'])
res.optionId = res.optionId.astype('str')
res = res.drop('Unnamed: 0', axis=1)
res.pdDateTime = res.pdDateTime.apply(lambda x:Date(x.year,x.month,x.day))
print('开始日期: ' + res['dataDate'].iloc[0])
print('结束日期: ' + res['dataDate'].iloc[-1])
print('Market Sample: ')
res[['dataDate', 'dataTime', 'optionId', 'lastPrice', 'bidPrice1', 'askPrice1', 'lastPrice(vol)']].head()

开始日期: 2015-03-05
结束日期: 2015-03-09
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 买卖价差(到期时间)

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

tmp = bidAskSample.groupby(['maturity'])[['bidAskSpread(bps)']]
ax = tmp.mean().plot(kind = 'bar', figsize = (12,6), rot = 45)
ax.set_title(u'买卖价差(按照期权到期时间)', fontproperties = font, fontsize = 25)
ax.set_xlabel(u'到期时间', fontproperties = font, fontsize = 15)

<matplotlib.text.Text at 0x7798290>

1.2 买卖价差(行权价)

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

<matplotlib.text.Text at 0x5bc08d0>

1.3 买卖价差(期权类型)

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

<matplotlib.text.Text at 0x7a8d7d0>

2. 日交易量分析

volumeSample = res[[u'optionId', 'pdDateTime', 'dataDate', 'contractType', 'strikePrice', 'volume']]
volumeSample.columns = ['optionId', 'maturity', 'tradingDate', 'contractType', 'strikePrice', 'volume']
tmp = volumeSample.groupby(['tradingDate'])[['volume']].sum()
ax = tmp.plot(kind = 'bar', figsize = (12,6), rot = 45)
ax.set_title(u'日交易量(按交易日期)', fontproperties = font, fontsize = 25)
ax.set_xlabel(u'交易日期', fontproperties = font, fontsize = 15)

<matplotlib.text.Text at 0x7a72d90>

2.1 日交易量(到期时间)

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

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

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 日交易量(行权价)

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

<matplotlib.text.Text at 0x7fa5610>

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

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 日交易量(期权类型)

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

<matplotlib.text.Text at 0x8813e10>

3. 波动率价差分析

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

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

tmp = bidAskVolSample.groupby(['maturity'])[['bidAskSpread(vol bps)']]
ax = tmp.mean().plot(kind = 'bar', figsize = (12,6), rot = 45)
ax.set_title(u'波动率价差(按照期权到期时间)', fontproperties = font, fontsize = 25)
ax.set_xlabel(u'到期时间', fontproperties = font, fontsize = 15)

<matplotlib.text.Text at 0x8c0b7d0>

3.2 波动率价差(行权价)

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

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

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

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

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

<matplotlib.text.Text at 0x8d1fc50>

4. 个券分析

4.1 交易量

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

4.2 买卖价差

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

4.3 波动率价差

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

4.4 时间序列分析

tmp = volumeSample.groupby(['tradingDate','optionId'])[['volume']].sum().unstack()

for i, d in enumerate(tmp.index):
    fig, axs = pylab.subplots(2, 1, figsize = (16,5))
    sample = tmp.loc(d)
    sample = sample[d]
    sample.sort('volume', ascending = False)

    base = res[res['dataDate'] == d]
    base = base[base.optionId == sample.index[0][1]]
    base.index = range(len(base))

    base['calTimeStamp'] = base.timeStamp.apply(lambda s: DateTime(s.year, s.month, s.day, s.hour, s.minute, s.second))
    ax = base.plot(x = 'calTimeStamp', y = ['volume'], kind = 'bar', sharex=True, xticks = [], color = 'r', ax = axs[0])
    ax.set_title(u'交易日: ' + unicode(d) + u' 最活跃期权:'+ unicode(sample.index[0][1]), fontproperties = font, fontsize = 18)
    ax = base.plot(x= 'calTimeStamp', y = ['lastPrice(vol)'], sharex=True, legend = True,ax = axs[1], rot = 45)
    ax.set_xlabel(u'交易时间', fontproperties = font, fontsize = 15)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文