第一部分 新手入门
- 一 量化投资视频学习课程
- 二 Python 手把手教学
- 量化分析师的Python日记【第1天:谁来给我讲讲Python?】
- 量化分析师的Python日记【第2天:再接着介绍一下Python呗】
- 量化分析师的Python日记【第3天:一大波金融Library来袭之numpy篇】
- 量化分析师的Python日记【第4天:一大波金融Library来袭之scipy篇】
- 量化分析师的Python日记【第5天:数据处理的瑞士军刀pandas】
- 量化分析师的Python日记【第6天:数据处理的瑞士军刀pandas下篇
- 量化分析师的Python日记【第7天:Q Quant 之初出江湖】
- 量化分析师的Python日记【第8天 Q Quant兵器谱之函数插值】
- 量化分析师的Python日记【第9天 Q Quant兵器谱之二叉树】
- 量化分析师的Python日记【第10天 Q Quant兵器谱 -之偏微分方程1】
- 量化分析师的Python日记【第11天 Q Quant兵器谱之偏微分方程2】
- 量化分析师的Python日记【第12天:量化入门进阶之葵花宝典:因子如何产生和回测】
- 量化分析师的Python日记【第13天 Q Quant兵器谱之偏微分方程3】
- 量化分析师的Python日记【第14天:如何在优矿上做Alpha对冲模型】
- 量化分析师的Python日记【第15天:如何在优矿上搞一个wealthfront出来】
第二部分 股票量化相关
- 一 基本面分析
- 1.1 alpha 多因子模型
- 1.2 基本面因子选股
- 1.3 财报阅读 • [米缸量化读财报] 资产负债表-投资相关资产
- 1.4 股东分析
- 1.5 宏观研究
- 二 套利
- 三 事件驱动
- 四 技术分析
- 4.1 布林带
- 4.2 均线系统
- 4.3 MACD
- 4.4 阿隆指标 • 技术指标阿隆( Aroon )全解析
- 4.5 CCI • CCI 顺势指标探索
- 4.6 RSI
- 4.7 DMI • DMI 指标体系的构建及简单应用
- 4.8 EMV • EMV 技术指标的构建及应用
- 4.9 KDJ • KDJ 策略
- 4.10 CMO
- 4.11 FPC • FPC 指标选股
- 4.12 Chaikin Volatility
- 4.13 委比 • 实时计算委比
- 4.14 封单量
- 4.15 成交量 • 决战之地, IF1507 !
- 4.16 K 线分析 • 寻找夜空中最亮的星
- 五 量化模型
- 5.1 动量模型
- 5.2 Joseph Piotroski 9 F-Score Value Investing Model
- 5.3 SVR
- 5.4 决策树、随机树
- 5.5 钟摆理论
- 5.6 海龟模型
- 5.7 5217 策略
- 5.8 SMIA
- 5.9 神经网络
- 5.10 PAMR
- 5.11 Fisher Transform
- 5.12 分型假说, Hurst 指数
- 5.13 变点理论
- 5.14 Z-score Model
- 5.15 机器学习
- 5.16 DualTrust 策略和布林强盗策略
- 5.17 卡尔曼滤波
- 5.18 LPPL anti-bubble model
- 六 大数据模型
- 6.1 市场情绪分析
- 6.2 新闻热点
- 七 排名选股系统
- 八 轮动模型
- 九 组合投资
- 十 波动率
- 十一 算法交易
- 十二 中高频交易
- 十三 Alternative Strategy
第三部分 基金、利率互换、固定收益类
- 一 分级基金
- 二 基金分析
- 三 债券
- 四 利率互换
第四部分 衍生品相关
- 一 期权数据
- 二 期权系列
- 三 期权分析
- 四 期货分析
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
期权高频数据准备
本notebook根据指定的时间区间整理并保存option_data.csv
文件,请与 期权市场一周纵览 notebook配合使用。
import pandas as pd
import numpy as np
pd.options.display.float_format = '{:,>.4f}'.format
calendar = Calendar('China.SSE')
class _format_checker:
def __init__(self, calendar):
self.calendar = calendar
def _format_check(self, instrumentID):
contractType = instrumentID[6] + 'O'
contractYear = int(instrumentID[7:9]) + 2000
contractMonth = int(instrumentID[9:11])
contractExp = Date.NthWeekDay(4, Wednesday, contractMonth, contractYear)
contractExp = self.calendar.adjustDate(contractExp, BizDayConvention.Following)
contractStrike = float(instrumentID[-4:]) / 1000.0
return contractType, contractExp, contractStrike
checker = _format_checker(calendar)
tradingDays = calendar.bizDatesList(Date(2015,3,5), Date(2015,3,12))
names, instrumentIDs = (OptionsDataSnapShot().optionId.unique(), OptionsDataSnapShot().instrumentID.unique())
data = pd.DataFrame(names, columns = ['optionId'])
instrumentIDs = pd.Series(instrumentIDs)
data = data.join(pd.DataFrame(list(instrumentIDs.apply(checker._format_check)), columns= ['contractType', 'expDate', 'strikePrice']))
data[:5]
optionId | contractType | expDate | strikePrice | |
---|---|---|---|---|
0 | 10000001 | CO | March 25th, 2015 | 2.2000 |
1 | 10000002 | CO | March 25th, 2015 | 2.2500 |
2 | 10000003 | CO | March 25th, 2015 | 2.3000 |
3 | 10000004 | CO | March 25th, 2015 | 2.3500 |
4 | 10000005 | CO | March 25th, 2015 | 2.4000 |
tradingDaysStr = [''.join(date.toISO().split('-')) for date in tradingDays]
tradingDaysStr
['20150305', '20150306', '20150309', '20150310', '20150311']
res = pd.DataFrame()
spotData = []
for day in tradingDaysStr:
tmp = spotData
try:
spotData = DataAPI.MktTicksHistOneDayGet('510050.XSHG', date = day, field = ['dataDate', 'datasTime', 'secOffset', 'lastPrice'])
spotData = spotData.drop(0)
except Exception, e:
print e
spotData = tmp
for opt in names:
try:
sample = DataAPI.MktOptionTicksHistOneDayGet(optionId = opt,date = day)#field = ['optionId', 'dataDate', 'dataTime' 'secOffset', 'lastPrice'])
sample = sample.drop_duplicates(['secOffset'])
spotPrice = np.zeros((len(sample),))
j = 0
index = spotData.index
for i, secOffset in enumerate(sample.secOffset):
currentSpotSecOffset = spotData.loc[index[j], 'secOffset']*1000
while currentSpotSecOffset < secOffset and j < len(index)-1:
j = j + 1
currentSpotSecOffset = spotData.loc[index[j], 'secOffset']*1000
if j>=1:
spotPrice[i] = spotData.loc[index[j-1], 'lastPrice']
else:
spotPrice[i] = spotData.loc[index[j], 'lastPrice']
sample['spotPrice'] = spotPrice
res = res.append(sample)
except Exception, e:
print e
print day + ' finished!'
20150305 finished!
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000030&date=20150306&startSecOffset=&endSecOffset=
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000032&date=20150306&startSecOffset=&endSecOffset=
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000033&date=20150306&startSecOffset=&endSecOffset=
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000035&date=20150306&startSecOffset=&endSecOffset=
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000054&date=20150306&startSecOffset=&endSecOffset=
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000056&date=20150306&startSecOffset=&endSecOffset=
20150306 finished!
20150309 finished!
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000039&date=20150310&startSecOffset=&endSecOffset=
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000056&date=20150310&startSecOffset=&endSecOffset=
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000064&date=20150310&startSecOffset=&endSecOffset=
20150310 finished!
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000039&date=20150311&startSecOffset=&endSecOffset=
-1:No Data Returned for request: /market/getOptionTicksHistOneDay.csv?field=&optionId=10000064&date=20150311&startSecOffset=&endSecOffset=
20150311 finished!
res.optionId = res.optionId.astype('str')
res = res.merge(data, how = 'left', on = 'optionId')
dateData, idData, volumeData = res.dataDate, res.optionId, res['volume']
previous = [dateData[0], idData[0], 0]
newVolume = np.zeros((len(dateData),))
count = 0
for date, ids, volume in zip(dateData, idData, volumeData ):
if date == previous[0] and ids == previous[1]:
newVolume[count] = volume - previous[2]
else:
newVolume[count] = volume
previous[0] = date
previous[1] = ids
previous[2] = volume
count = count + 1
res.volume = newVolume
res['pdDateTime'] = res.expDate.apply(lambda x: x.toDateTime())
optData = pd.DataFrame()
optData['contractType'] = res['contractType']
optData['valuationDate'] = res['dataDate']
optData['expDate'] = res['expDate']
optData['strikePrice'] = res['strikePrice']
optData['lastPrice'] = res['lastPrice']
optData['optionId'] = res['optionId'].astype('str')
optData['Type'] = Option.Call
optData['spotPrice'] = res.spotPrice
optData.loc[optData['contractType'] == 'PO','Type'] = Option.Put
optData['valuationDate'] = [Date(int(date.split('-')[0]),int(date.split('-')[1]),int(date.split('-')[2])) for date in optData['valuationDate']]
dc = DayCounter('Actual/365 (Fixed)')
optData['ttm'] = [dc.yearFraction(date1, date2) for date1, date2 in zip(optData['valuationDate'], optData['expDate'])]
optData['lastPrice(vol)'] = BSMImpliedVolatity(optData['Type'], optData['strikePrice'], optData['spotPrice'], 0.0, 0.0, optData['ttm'], optData['lastPrice'])
optData['bid1(vol)'] = BSMImpliedVolatity(optData['Type'], optData['strikePrice'], optData['spotPrice'], 0.0, 0.0, optData['ttm'], res.bidPrice1)
optData['ask1(vol)'] = BSMImpliedVolatity(optData['Type'], optData['strikePrice'], optData['spotPrice'], 0.0, 0.0, optData['ttm'], res.askPrice1)
res1 = res.merge(optData[[u'spotPrice', u'ttm', u'lastPrice(vol)', u'bid1(vol)', u'ask1(vol)']], left_index=True, right_index=True)
res1 = res1.dropna(how = 'any')
res1['bidAskSpread(bps)'] = (res1.askPrice1 - res1.bidPrice1) * 10000
res1['bidAskSpread(vol bps)'] = (res1['ask1(vol)'] - res1['bid1(vol)']) * 10000
res1.to_csv('option_data.csv')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论