1.股指期货概述
股指期货,用于对冲股票市场风险的金融衍生工具,恰当的应用可以有效的规避投资风险,股指期货T0交易制度,双向交易,且支持做多也支持做空的交易方式,是对T 1交易制度、单向交易的股票市场是极大的扩展,同时也兼具期货本身的套利、投机等功能属性。
在量化交易策略中,有不少追求alpha收益的策略,如果能够找到稳定赚钱的alpha,就可以通过指数期货的对冲,规避掉市场风险部分,获取超额收益。
和其他的期货品种一样,期货市场同样也存在着期保值者、投机者、套利者,股指期货市场的表现同样也表达了投资者对股票市场未来走势看法,如在2015年熊市挡住,股指期货就曾被认为是股市下跌的元凶。
股指期货到期进行交割时就是股票指数了,受政策变化、市场流动性缩减、手续费提升的影响,指数期货与股票指数的实际走势也发生着变化,本篇文章就是带大家看一下股指期货与股指的具体表现。
2.股指期货的几个重要时间点
目前,市场上已经开放的股指期货有三个,沪深300股指期货(交易代码IF)、中证500股指期货(交易代码IC),上证50股指期货(交易代码IH),首先,这里我们先整体看一下三个指数期货发布以来到现在的成交量、基差率(期货价格/指数价格 -1)的变化情况
可以看到,成交量和基差率均在2015年下半年发生了翻天覆地的变化!这是由于在2015年股指期货交易制度更改的原因。接下来,我们把三个股指期货的几个关键时间点都列出来;
其次,列出几次重要的制度变化时间点
3.不同时间段的表现
按照上面列出的时间点,这里分了如下几个时间段进行研究
沪深300股指期货分阶段的成交量、基差的均值数据
中证500股指期货分阶段的成交量、基差数据统计
上证50股指期货分阶段的成交量、基差数据统计
为了更加直观的看到变化情况,下面进行统计图展示
4.分阶段描述各个时期的特点。
这张图统计了自2015年限制之后,三个股指期货的成交量变化,成交量均在稳步提升,我们看到在政策不断松绑的
成交量回升显著,上证50从近5000手上升至超过2万手,沪深300从1.25万手上升智4万手以上
中证500中间出现了缩量的情况,但当前月的均量也已经是成倍的增长
(上证50、沪深300集中了大盘蓝筹股、中证500则反映着中小股的走势,从2017年年初之后,市场就是大盘股主导,估计与这行情有着一定的关系)
再来看基差率
5.汇总总结。
自从股指期货被限制之后,长期处于深度贴水状态,即股指期货长期低于股票指数。
股指期货现金交割模式下,持有成本中并未包含仓储物流等费用,也不受供求关系的影响。风险完全来自股票市场的变化,理论上二者的价格应该更加接近才对,但是由于交易手数的限制、高昂的手续费,抑制了投资者的参与,使得套保套利者对手盘缺失,整个股指期货市场流动性严重不足,基差率过大,直接影响着对股票市场的风险锁定功能,通过对冲实现的市场中性策略效果。在这种情况下空头操作将承担更大的成本,同时面临着期货价格大幅拉升的危险之中。
随着政策不断松绑,我们看到二者的价差在不断缩小,成交量也开始大幅回升,我们期待一个流动性充足,交易成本合理的股指期货市场,使得更多的策略模型能够发挥效用。
内容说明
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('ggplot')
#行情数据获取
#输入:起止时间,返回:几个期货数据的时间序列
s_date,e_date = '2010-1-1','2019-2-13'
pool = ['IF9999.CCFX','IH9999.CCFX','IC9999.CCFX','000300.XSHG','000016.XSHG','000905.XSHG',\
'IF8888.CCFX','IH8888.CCFX','IC8888.CCFX']
df = get_price(pool,start_date=s_date,end_date=e_date,fields=['close'])['close'] #获取价格信息
df_volume = get_price(pool,start_date=s_date,end_date=e_date,fields=['volume'])['volume'] #获取成交量信息
#将主力合约的值减去行情价格,观察差值表现
diff_df = pd.DataFrame()
diff_df['IF_diff'] = df['000300.XSHG'] - df['IF9999.CCFX']
diff_df['IH_diff'] = df['000016.XSHG'] - df['IH9999.CCFX']
diff_df['IC_diff'] = df['000905.XSHG']- df['IC9999.CCFX']
diff_df.tail(5)
IF_diff | IH_diff | IC_diff | |
---|---|---|---|
2019-01-31 | -5.77 | -3.33 | 8.47 |
2019-02-01 | -14.00 | -5.96 | -10.73 |
2019-02-11 | 0.87 | 5.47 | 2.87 |
2019-02-12 | 0.34 | 1.58 | 10.68 |
2019-02-13 | -8.17 | -1.19 | 2.61 |
diff_df.plot(figsize=(15,10)) #基差
<matplotlib.axes._subplots.AxesSubplot at 0x7fd7b13d4f28>
统计基差率
div_df = pd.DataFrame()
div_df['IF_div'] = (df['IF9999.CCFX'] - df['000300.XSHG'])/df['000300.XSHG']
div_df['IH_div'] = df['IH9999.CCFX']/df['000016.XSHG'] - 1
div_df['IC_div'] = df['IC9999.CCFX']/df['000905.XSHG'] - 1
div_df.plot(figsize=(15,10))#期现偏离度
<matplotlib.axes._subplots.AxesSubplot at 0x7fd7b18ea908>
#三个股指期货产品的成交量
df_volume[['IF9999.CCFX','IH9999.CCFX','IC9999.CCFX']].plot(figsize=(15,10)) #成交量变化
<matplotlib.axes._subplots.AxesSubplot at 0x7fd7b1d63a58>
div_df['IC_diff'].hist(bins=100)
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) /opt/conda/envs/python3new/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2441 try: -> 2442 return self._engine.get_loc(key) 2443 except KeyError: pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5280)() pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5126)() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20523)() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20477)() KeyError: 'IC_diff' During handling of the above exception, another exception occurred: KeyError Traceback (most recent call last) <ipython-input-12-673fe952cedf> in <module>() ----> 1 div_df['IC_diff'].hist(bins=100) /opt/conda/envs/python3new/lib/python3.6/site-packages/pandas/core/frame.py in __getitem__(self, key) 1962 return self._getitem_multilevel(key) 1963 else: -> 1964 return self._getitem_column(key) 1965 1966 def _getitem_column(self, key): /opt/conda/envs/python3new/lib/python3.6/site-packages/pandas/core/frame.py in _getitem_column(self, key) 1969 # get column 1970 if self.columns.is_unique: -> 1971 return self._get_item_cache(key) 1972 1973 # duplicate columns & possible reduce dimensionality /opt/conda/envs/python3new/lib/python3.6/site-packages/pandas/core/generic.py in _get_item_cache(self, item) 1643 res = cache.get(item) 1644 if res is None: -> 1645 values = self._data.get(item) 1646 res = self._box_item_values(item, values) 1647 cache[item] = res /opt/conda/envs/python3new/lib/python3.6/site-packages/pandas/core/internals.py in get(self, item, fastpath) 3588 3589 if not isnull(item): -> 3590 loc = self.items.get_loc(item) 3591 else: 3592 indexer = np.arange(len(self.items))[isnull(self.items)] /opt/conda/envs/python3new/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2442 return self._engine.get_loc(key) 2443 except KeyError: -> 2444 return self._engine.get_loc(self._maybe_cast_indexer(key)) 2445 2446 indexer = self.get_indexer([key], method=method, tolerance=tolerance) pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5280)() pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5126)() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20523)() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20477)() KeyError: 'IC_diff'
沪深300股指期货在2015年9月7日限制之后的成交量变化
if_df = get_price('IF9999.CCFX',fields=['volume'],start_date='2015-9-8',end_date='2018-12-30')['volume']
if_df.plot(figsize = (12,8))
<matplotlib.axes._subplots.AxesSubplot at 0x7fd7b1a77278>
s_date,e_date = '2005-1-1','2019-1-1'
pool = ['IF9999.CCFX','IH9999.CCFX','IC9999.CCFX','000300.XSHG','000016.XSHG','000905.XSHG',\
'IF8888.CCFX','IH8888.CCFX','IC8888.CCFX']
df_test = get_price(pool,start_date=s_date,end_date=e_date,fields=['close'])['close']
df_test[['000300.XSHG','000016.XSHG','000905.XSHG']].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7fd7b0503630>
#中证500成交量变化
df_volume['IC9999.CCFX'].plot(figsize=(15,10))
<matplotlib.axes._subplots.AxesSubplot at 0x7fd7b04808d0>
分阶段统计
date1 = '20100416' #hs300期货上市
date2 = '20150416' #ss50、zz500期货上市
date3 = '20150907' #限制
date4 = '20170217' #放开1
date5 = '20170918' #放开2
date6 = '20181203' #放开3
date7 = '20190213' #至今
date_list = [date1,date2,date3,date4,date5,date6,date7]
'''
对指定时间段的成交量、基差、基差率统
'''
#df1是close价格,df2是成交量的df
def cal_mean(s_date,e_date,index,df1,df2):
df_temp1 = df1[(df1.index>=s_date) & (df1.index<e_date)]
df_temp2 = df2[(df2.index>=s_date) & (df2.index<e_date)]
mean_volume = np.mean(df_temp2[index])
if index == 'IF9999.CCFX':
stock_index = '000300.XSHG'
elif index == 'IC9999.CCFX':
stock_index = '000905.XSHG'
elif index == 'IH9999.CCFX':
stock_index = '000016.XSHG'
#期货 - 股指
basis_se = df_temp1[index] - df_temp1[stock_index]
basis_mean = np.mean(basis_se)
#期货/股指 - 1
dev_se = df_temp1[index]/df_temp1[stock_index] - 1
dev_mean = np.mean(dev_se)
return mean_volume,basis_mean,dev_mean,basis_se,dev_se
#cal_mean(s_date=date5,e_date=date6,index ='IF9999.CCFX',df1=df,df2 =df_volume)
#我们统一为 期货-指数
summary_if = pd.DataFrame(columns= ['成交量均值','基差均值','基差率'])
for d1,d2 in zip(date_list[:-1],date_list[1:]):
summary_if.loc[str(d1)+'-'+str(d2)] = cal_mean(s_date=d1,e_date=d2,index ='IF9999.CCFX',df1=df,df2 =df_volume)[:3]
summary_if
成交量均值 | 基差均值 | 基差率 | |
---|---|---|---|
20100416-20150416 | 5.101351e+05 | 5.503223 | 0.001748 |
20150416-20150907 | 1.570417e+06 | -59.609184 | -0.016358 |
20150907-20170217 | 1.265470e+04 | -41.068291 | -0.012178 |
20170217-20170918 | 1.345356e+04 | -13.591986 | -0.003844 |
20170918-20181203 | 1.757595e+04 | -8.465119 | -0.002332 |
20181203-20190213 | 4.296662e+04 | 1.251778 | 0.000384 |
#我们统一为 期货-指数
summary_ic = pd.DataFrame(columns= ['成交量均值','基差均值','基差率'])
for d1,d2 in zip(date_list[:-1],date_list[1:]):
summary_ic.loc[str(d1)+'-'+str(d2)] = cal_mean(s_date=d1,e_date=d2,index ='IC9999.CCFX',df1=df,df2 =df_volume)[:3]
summary_ic
成交量均值 | 基差均值 | 基差率 | |
---|---|---|---|
20100416-20150416 | NaN | NaN | NaN |
20150416-20150907 | 193651.247423 | -221.018763 | -0.028709 |
20150907-20170217 | 10154.566952 | -106.351766 | -0.016422 |
20170217-20170918 | 11091.821918 | -34.493973 | -0.005539 |
20170918-20181203 | 10304.354949 | -28.814846 | -0.005325 |
20181203-20190213 | 22029.000000 | -17.501333 | -0.004066 |
#我们统一为 期货-指数
summary_ih = pd.DataFrame(columns= ['成交量均值','基差均值','基差率'])
for d1,d2 in zip(date_list[:-1],date_list[1:]):
summary_ih.loc[str(d1)+'-'+str(d2)] = cal_mean(s_date=d1,e_date=d2,index ='IH9999.CCFX',df1=df,df2 =df_volume)[:3]
summary_ih
成交量均值 | 基差均值 | 基差率 | |
---|---|---|---|
20100416-20150416 | NaN | NaN | NaN |
20150416-20150907 | 310781.979381 | -19.586598 | -0.008984 |
20150907-20170217 | 4873.720798 | -15.929031 | -0.007154 |
20170217-20170918 | 7467.842466 | -5.689452 | -0.002364 |
20170918-20181203 | 12921.542662 | -1.944471 | -0.000798 |
20181203-20190213 | 20012.822222 | 1.963333 | 0.000813 |
#成交量放在一张图上展示
summary_vol = pd.DataFrame(index=summary_ih.index)
summary_vol['IC_成交量']=summary_ic['成交量均值']
summary_vol['IH_成交量']=summary_ih['成交量均值']
summary_vol['IF_成交量']=summary_if['成交量均值']
summary_vol
IC_成交量 | IH_成交量 | IF_成交量 | |
---|---|---|---|
20100416-20150416 | NaN | NaN | 5.101351e+05 |
20150416-20150907 | 193651.247423 | 310781.979381 | 1.570417e+06 |
20150907-20170217 | 10154.566952 | 4873.720798 | 1.265470e+04 |
20170217-20170918 | 11091.821918 | 7467.842466 | 1.345356e+04 |
20170918-20181203 | 10304.354949 | 12921.542662 | 1.757595e+04 |
20181203-20190213 | 22029.000000 | 20012.822222 | 4.296662e+04 |
summary_vol.plot(kind='bar',figsize=(12,8))
<matplotlib.axes._subplots.AxesSubplot at 0x7fd7b09ecb38>
#单独显示限制之后的成交量情况
summary_vol.iloc[2:,:].plot(kind='bar',figsize=(12,8))
<matplotlib.axes._subplots.AxesSubplot at 0x7fd7b03df828>
#基差率放在一张图上展示
summary_dev = pd.DataFrame(index=summary_ih.index)
summary_dev['IC_基差率']=summary_ic['基差率']
summary_dev['IH_基差率']=summary_ih['基差率']
summary_dev['IF_基差率']=summary_if['基差率']
summary_dev
IC_基差率 | IH_基差率 | IF_基差率 | |
---|---|---|---|
20100416-20150416 | NaN | NaN | 0.001748 |
20150416-20150907 | -0.028709 | -0.008984 | -0.016358 |
20150907-20170217 | -0.016422 | -0.007154 | -0.012178 |
20170217-20170918 | -0.005539 | -0.002364 | -0.003844 |
20170918-20181203 | -0.005325 | -0.000798 | -0.002332 |
20181203-20190213 | -0.004066 | 0.000813 | 0.000384 |
summary_dev.plot(kind='bar',figsize=(12,8))
<matplotlib.axes._subplots.AxesSubplot at 0x7f680c054be0>
dev_df = pd.DataFrame()
dev_df['IF_基差率'] = cal_mean('2010-4-16','2019-1-1','IF9999.CCFX',df,df_volume)[-1]
dev_df['IH_基差率'] = cal_mean('2010-4-16','2019-1-1','IH9999.CCFX',df,df_volume)[-1]
dev_df['IC_基差率'] = cal_mean('2010-4-16','2019-1-1','IC9999.CCFX',df,df_volume)[-1]
dev_df.plot(figsize=(12,8))
<matplotlib.axes._subplots.AxesSubplot at 0x7fd7b023d780>
#三个股指期货产品的成交量
df_volume[['IF9999.CCFX','IH9999.CCFX','IC9999.CCFX']].loc['2015-09-06':,:].plot(figsize=(15,10)) #成交量变化
<matplotlib.axes._subplots.AxesSubplot at 0x7f6807e63390>
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
移动端课程