# 4.15 成交量 • 决战之地， IF1507 ！

``````import pandas as pd
import seaborn as sns
sns.set_style('white')
from CAL.PyCAL import *
from matplotlib import pylab
``````
1. 期货主力合约成交变化趋势

• IF150X成交额：当月期货主力合约成交金额；
• 沪深300成交额：沪深300成分股总成交金额，用于指示现货市场的成交额；
• 占比(%)：现货市场成交金额占期货市场成交金额比例。
``````contractMonths = [5,6,7]
allRes = []
for cMonth in contractMonths:
contractName = 'IF150' + unicode(cMonth)
beginDate = Date.NthWeekDay(3,Friday,cMonth-1,2015).strftime('%Y%m%d')
endDate = Date(2015,cMonth,3).strftime('%Y%m%d')
futRes = DataAPI.MktFutdGet(ticker=contractName, beginDate=beginDate, endDate = endDate, field=['tradeDate','closePrice' ,'turnoverVol','turnoverValue'])
idxRes = DataAPI.MktIdxdGet(ticker='000300', beginDate=beginDate, endDate = endDate,field=['tradeDate','closeIndex','turnoverVol','turnoverValue'])
totalRes = pd.merge(futRes, idxRes, left_index=True, right_index=True)
totalRes.columns = [contractName, contractName + ' turn over vol', contractName + u' turn over value', u'HS300', u'HS300 turn over vol', u'HS300 turn over value',]
totalRes[u'Per.(%)'] = totalRes[u'HS300 turn over value'] / totalRes[contractName + u' turn over value'] * 100
font.set_size(12)
pylab.figure(figsize = (16,6))
ax1 = totalRes.plot(y=['Per.(%)'], secondary_y= ['Per.(%)'], style='r')
ax2 = totalRes.plot(y=[contractName + ' turn over value', 'HS300 turn over value'], kind='bar',legend=False, rot=30)
patches2, labels2 = ax2.get_legend_handles_labels()
ax2.set_ylabel(u'成交额', fontproperties=font)
ax2.set_ylim((0.0,4.0e12))
ax1.set_ylim((0.0, 50.0))
ax2.set_xlabel(u'交易日期', fontproperties=font)
ax1.set_ylabel(u'占比(%)', fontproperties=font)
patches1, labels1 = ax1.get_legend_handles_labels()
ax1.legend(patches2 + patches1, [contractName + u'成交额', u'沪深300成交额', u'占比(%)'], prop = font, loc='best')
font.set_size(18)
pylab.title(contractName + u'期货主力合约 v.s.沪深300 （成交金额）', fontproperties=font)
allRes.append(totalRes)
``````

• 期货主力成交金额显著上升，从日均2万亿上升至日均3万亿；
• 现货成交量较为稳定，日均在5千亿到1万亿之间；
• 现货成交与期货成交占比显著下降，从4月份的40%左右，下降至5月份的30%左右，直至6月份的20%左右。

## 2. IF1507期货价量变化趋势

``````font.set_size(12)
pylab.figure(figsize = (16,6))
ax2 = allRes[-1].plot(y=['IF1507'], secondary_y=['IF1507'], style='ro-', )
ax1 = allRes[-1].plot(y=['IF1507 turn over vol'], kind='bar', rot =30)
ax1.set_ylabel(u'成交量', fontproperties=font)
ax2.set_ylabel('IF1507')
patches, labels = ax1.get_legend_handles_labels()
patches2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(patches + patches2, [u'IF1507成交量', u'IF1507'], prop = font, loc='best')
ax1.set_ylim((0.0,4000000))
ax1.set_xlabel(u'交易日期', fontproperties=font)
font.set_size(18)
pylab.title(contractName + u'IF1507合约走势以及成交量', fontproperties=font)
``````