In [1]:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib.widgets import MultiCursor

In [2]:
%matplotlib qt
sns.set_context('paper')
sns.set_style("dark", rc={'axes.facecolor': 'black', 'grid.color': 'red', 
                              'grid.linestyle': '--',
                              'figure.facecolor': 'grey'})

In [95]:
sns.axes_style()


Out[95]:
{'axes.axisbelow': True,
 'axes.edgecolor': 'white',
 'axes.facecolor': 'black',
 'axes.grid': True,
 'axes.labelcolor': '.15',
 'axes.linewidth': 0,
 'figure.facecolor': 'grey',
 'font.family': ['sans-serif'],
 'font.sans-serif': ['Arial',
  'Liberation Sans',
  'Bitstream Vera Sans',
  'sans-serif'],
 'grid.color': 'red',
 'grid.linestyle': '--',
 'image.cmap': 'Greys',
 'legend.frameon': False,
 'legend.numpoints': 1,
 'legend.scatterpoints': 1,
 'lines.solid_capstyle': 'round',
 'text.color': '.15',
 'xtick.color': '.15',
 'xtick.direction': 'out',
 'xtick.major.size': 0,
 'xtick.minor.size': 0,
 'ytick.color': '.15',
 'ytick.direction': 'out',
 'ytick.major.size': 0,
 'ytick.minor.size': 0}

In [234]:
plt.plot(np.arange(10))
plt.plot(np.arange(10, 0, -1))


Out[234]:
[<matplotlib.lines.Line2D at 0x7f1c1b2f0390>]

In [3]:
import matplotlib.finance as mf

In [5]:
hft = pd.read_hdf('HFT_SR_RM_MA_TA.hdf')

In [6]:
hft.head


Out[6]:
<bound method Panel.head of <class 'pandas.core.panel.Panel'>
Dimensions: 38 (items) x 2700120 (major_axis) x 4 (minor_axis)
Items axis: AveragePrice to volume
Major_axis axis: 2015-11-19 21:00:00 to 2015-12-31 15:00:00
Minor_axis axis: MA0001 to TA0001>

In [7]:
hft.items


Out[7]:
Index([u'AveragePrice', u'LifeHigh', u'LifeLow', u'TotalAskLot',
       u'TotalBidLot', u'askPrc_0', u'askPrc_1', u'askPrc_2', u'askPrc_3',
       u'askPrc_4', u'askQty_0', u'askQty_1', u'askQty_2', u'askQty_3',
       u'askQty_4', u'bidPrc_0', u'bidPrc_1', u'bidPrc_2', u'bidPrc_3',
       u'bidPrc_4', u'bidQty_0', u'bidQty_1', u'bidQty_2', u'bidQty_3',
       u'bidQty_4', u'close', u'high', u'highLimit', u'last', u'low',
       u'lowLimit', u'open', u'openInterest', u'prevClose',
       u'prevOpenInterest', u'prevSettle', u'settle', u'volume'],
      dtype='object')

In [8]:
# output cols to csv
cols = hft.items
cols = np.array(cols).astype(str)
np.savetxt('cols.csv', cols, delimiter=',', fmt='%s')

In [9]:
hft.major_axis


Out[9]:
DatetimeIndex([       '2015-11-19 21:00:00', '2015-11-19 21:00:00.250000',
               '2015-11-19 21:00:00.500000', '2015-11-19 21:00:00.750000',
                      '2015-11-19 21:00:01', '2015-11-19 21:00:01.250000',
               '2015-11-19 21:00:01.500000', '2015-11-19 21:00:01.750000',
                      '2015-11-19 21:00:02', '2015-11-19 21:00:02.250000',
               ...
               '2015-12-31 14:59:57.750000',        '2015-12-31 14:59:58',
               '2015-12-31 14:59:58.250000', '2015-12-31 14:59:58.500000',
               '2015-12-31 14:59:58.750000',        '2015-12-31 14:59:59',
               '2015-12-31 14:59:59.250000', '2015-12-31 14:59:59.500000',
               '2015-12-31 14:59:59.750000',        '2015-12-31 15:00:00'],
              dtype='datetime64[ns]', length=2700120, freq=None)

In [10]:
hft.minor_axis


Out[10]:
Index([u'MA0001', u'RM0001', u'SR0001', u'TA0001'], dtype='object')

In [11]:
night_len = int(4*3600*2.5)
mor_len = int(4*3600*2.25)
aftn_len = int(4*3600*1.5)
day_len = night_len + mor_len + aftn_len + 3

In [12]:
mor_len


Out[12]:
32400

FOCUS on RM


In [13]:
rm = hft.minor_xs('RM0001')
type(rm)


Out[13]:
pandas.core.frame.DataFrame

plot VERIFY THAT THIS IS rm1601


In [129]:
plt.figure(figsize=(20,10))
plt.plot(rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'].index, 
         rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'])


Out[129]:
[<matplotlib.lines.Line2D at 0x7f1c1e419d90>]

In [15]:
rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last']


Out[15]:
2015-11-22 21:00:00.000    1777.0
2015-11-22 21:00:00.250    1778.0
2015-11-22 21:00:00.500    1779.0
2015-11-22 21:00:00.750    1778.0
2015-11-22 21:00:01.000    1779.0
2015-11-22 21:00:01.250    1778.0
2015-11-22 21:00:01.500    1777.0
2015-11-22 21:00:01.750    1777.0
2015-11-22 21:00:02.000    1779.0
2015-11-22 21:00:02.250    1777.0
2015-11-22 21:00:02.500    1777.0
2015-11-22 21:00:02.750    1777.0
2015-11-22 21:00:03.000    1777.0
2015-11-22 21:00:03.250    1777.0
2015-11-22 21:00:03.500    1777.0
2015-11-22 21:00:03.750    1777.0
2015-11-22 21:00:04.000    1777.0
2015-11-22 21:00:04.250    1778.0
2015-11-22 21:00:04.500    1779.0
2015-11-22 21:00:04.750    1778.0
2015-11-22 21:00:05.000    1778.0
2015-11-22 21:00:05.250    1777.0
2015-11-22 21:00:05.500    1778.0
2015-11-22 21:00:05.750    1777.0
2015-11-22 21:00:06.000    1778.0
2015-11-22 21:00:06.250    1778.0
2015-11-22 21:00:06.500    1778.0
2015-11-22 21:00:06.750    1779.0
2015-11-22 21:00:07.000    1778.0
2015-11-22 21:00:07.250    1778.0
                            ...  
2015-11-23 14:59:52.750    1709.0
2015-11-23 14:59:53.000    1709.0
2015-11-23 14:59:53.250    1709.0
2015-11-23 14:59:53.500    1709.0
2015-11-23 14:59:53.750    1709.0
2015-11-23 14:59:54.000    1709.0
2015-11-23 14:59:54.250    1709.0
2015-11-23 14:59:54.500    1709.0
2015-11-23 14:59:54.750    1709.0
2015-11-23 14:59:55.000    1709.0
2015-11-23 14:59:55.250    1709.0
2015-11-23 14:59:55.500    1709.0
2015-11-23 14:59:55.750    1709.0
2015-11-23 14:59:56.000    1709.0
2015-11-23 14:59:56.250    1709.0
2015-11-23 14:59:56.500    1709.0
2015-11-23 14:59:56.750    1709.0
2015-11-23 14:59:57.000    1709.0
2015-11-23 14:59:57.250    1709.0
2015-11-23 14:59:57.500    1709.0
2015-11-23 14:59:57.750    1709.0
2015-11-23 14:59:58.000    1709.0
2015-11-23 14:59:58.250    1709.0
2015-11-23 14:59:58.500    1709.0
2015-11-23 14:59:58.750    1709.0
2015-11-23 14:59:59.000    1709.0
2015-11-23 14:59:59.250    1709.0
2015-11-23 14:59:59.500    1709.0
2015-11-23 14:59:59.750    1709.0
2015-11-23 15:00:00.000    1709.0
Name: last, dtype: float64

In [16]:
print rm.ix['2015-11-23 15:00:00', ['open', 'close', 'volume', 'last', 'high', 'low', 'openInterest']]


                       open  close     volume    last    high     low  \
2015-11-23 15:00:00  1777.0    0.0  1436512.0  1709.0  1796.0  1709.0   

                     openInterest  
2015-11-23 15:00:00      507074.0  

In [17]:
ta = hft.minor_xs('MA0001')
print ta.ix['2015-11-23 15:00:00', ['open', 'close', 'volume', 'last', 'high', 'low', 'openInterest']]


                       open  close     volume    last    high     low  \
2015-11-23 15:00:00  1808.0    0.0  2340410.0  1731.0  1820.0  1731.0   

                     openInterest  
2015-11-23 15:00:00      650322.0  

show columns


In [18]:
rm.iloc[:5, :12]


Out[18]:
AveragePrice LifeHigh LifeLow TotalAskLot TotalBidLot askPrc_0 askPrc_1 askPrc_2 askPrc_3 askPrc_4 askQty_0 askQty_1
2015-11-19 21:00:00.000 1775.0 2322.0 1768.0 3103.0 2975.0 1776.0 1777.0 1778.0 1779.0 1780.0 21.0 7.0
2015-11-19 21:00:00.250 1775.0 2322.0 1768.0 3424.0 3010.0 1776.0 1777.0 1778.0 1779.0 1780.0 20.0 7.0
2015-11-19 21:00:00.500 1775.0 2322.0 1768.0 3648.0 3170.0 1776.0 1777.0 1778.0 1779.0 1780.0 8.0 13.0
2015-11-19 21:00:00.750 1775.0 2322.0 1768.0 3830.0 3234.0 1775.0 1776.0 1777.0 1778.0 1779.0 38.0 37.0
2015-11-19 21:00:01.000 1775.0 2322.0 1768.0 4012.0 3294.0 1775.0 1776.0 1777.0 1778.0 1779.0 96.0 88.0

In [19]:
rm.iloc[:5, 12:24]


Out[19]:
askQty_2 askQty_3 askQty_4 bidPrc_0 bidPrc_1 bidPrc_2 bidPrc_3 bidPrc_4 bidQty_0 bidQty_1 bidQty_2 bidQty_3
2015-11-19 21:00:00.000 58.0 30.0 262.0 1775.0 1774.0 1773.0 1772.0 1771.0 83.0 26.0 68.0 154.0
2015-11-19 21:00:00.250 58.0 352.0 262.0 1775.0 1774.0 1773.0 1772.0 1771.0 83.0 56.0 68.0 159.0
2015-11-19 21:00:00.500 80.0 362.0 263.0 1775.0 1774.0 1773.0 1772.0 1771.0 83.0 109.0 89.0 160.0
2015-11-19 21:00:00.750 55.0 84.0 362.0 1774.0 1773.0 1772.0 1771.0 1770.0 183.0 90.0 164.0 88.0
2015-11-19 21:00:01.000 77.0 84.0 369.0 1774.0 1773.0 1772.0 1771.0 1770.0 185.0 94.0 174.0 89.0

In [20]:
rm.iloc[:5, 24:]


Out[20]:
bidQty_4 close high highLimit last low lowLimit open openInterest prevClose prevOpenInterest prevSettle settle volume
2015-11-19 21:00:00.000 60.0 0.0 1775.0 1866.0 1775.0 1775.0 1722.0 1775.0 587568.0 1779.0 587568.0 1794.0 1775.0 520.0
2015-11-19 21:00:00.250 60.0 0.0 1776.0 1866.0 1776.0 1775.0 1722.0 1775.0 587566.0 1779.0 587568.0 1794.0 1775.0 522.0
2015-11-19 21:00:00.500 80.0 0.0 1777.0 1866.0 1775.0 1775.0 1722.0 1775.0 587534.0 1779.0 587568.0 1794.0 1775.0 674.0
2015-11-19 21:00:00.750 407.0 0.0 1777.0 1866.0 1775.0 1775.0 1722.0 1775.0 587648.0 1779.0 587568.0 1794.0 1775.0 1036.0
2015-11-19 21:00:01.000 422.0 0.0 1777.0 1866.0 1775.0 1774.0 1722.0 1775.0 587652.0 1779.0 587568.0 1794.0 1775.0 1086.0

ALL datatype are float64


In [21]:
# for col, ser in rm.iteritems():
#     print col, ser.dtype, ser.std(axis=0)
#     #ser.plot(marker='*', linestyle='-')
#     #plt.show()

Standard Deviation


In [22]:
# rm_20 = rm.ix[night_len + mor_len + aftn_len + 1: night_len + mor_len + aftn_len +night_len + mor_len + aftn_len, :]
# for col, ser in rm_20.iteritems():
#     print col, ser.dtype, ser.std(axis=0)
#     print ser.mean(axis=0)
#     #ser.plot(marker='*', linestyle='-')
#     #plt.show()

FEATURE!

investigate previous big jump to find features:

volume


In [125]:
rm.ix['2015-11-22 21:00:01': '2015-11-23 15:00:00': 20000, :5]


Out[125]:
AveragePrice LifeHigh LifeLow TotalAskLot TotalBidLot
2015-11-22 21:00:01.000 1778.0 2322.0 1765.0 4939.0 8587.0
2015-11-22 22:23:21.000 1785.0 2322.0 1765.0 14499.0 12002.0
2015-11-23 09:16:40.750 1787.0 2322.0 1765.0 16201.0 10426.0
2015-11-23 10:55:00.500 1779.0 2322.0 1752.0 20712.0 6184.0
2015-11-23 14:18:20.250 1762.0 2322.0 1709.0 36241.0 0.0

In [56]:
rm_index_str = rm.index.format()

In [113]:
rm_index_str = pd.Series(data=rm_index_str, index=rm.index)

In [114]:
rm_index_str


Out[114]:
2015-11-19 21:00:00.000    2015-11-19 21:00:00.000
2015-11-19 21:00:00.250    2015-11-19 21:00:00.250
2015-11-19 21:00:00.500    2015-11-19 21:00:00.500
2015-11-19 21:00:00.750    2015-11-19 21:00:00.750
2015-11-19 21:00:01.000    2015-11-19 21:00:01.000
2015-11-19 21:00:01.250    2015-11-19 21:00:01.250
2015-11-19 21:00:01.500    2015-11-19 21:00:01.500
2015-11-19 21:00:01.750    2015-11-19 21:00:01.750
2015-11-19 21:00:02.000    2015-11-19 21:00:02.000
2015-11-19 21:00:02.250    2015-11-19 21:00:02.250
2015-11-19 21:00:02.500    2015-11-19 21:00:02.500
2015-11-19 21:00:02.750    2015-11-19 21:00:02.750
2015-11-19 21:00:03.000    2015-11-19 21:00:03.000
2015-11-19 21:00:03.250    2015-11-19 21:00:03.250
2015-11-19 21:00:03.500    2015-11-19 21:00:03.500
2015-11-19 21:00:03.750    2015-11-19 21:00:03.750
2015-11-19 21:00:04.000    2015-11-19 21:00:04.000
2015-11-19 21:00:04.250    2015-11-19 21:00:04.250
2015-11-19 21:00:04.500    2015-11-19 21:00:04.500
2015-11-19 21:00:04.750    2015-11-19 21:00:04.750
2015-11-19 21:00:05.000    2015-11-19 21:00:05.000
2015-11-19 21:00:05.250    2015-11-19 21:00:05.250
2015-11-19 21:00:05.500    2015-11-19 21:00:05.500
2015-11-19 21:00:05.750    2015-11-19 21:00:05.750
2015-11-19 21:00:06.000    2015-11-19 21:00:06.000
2015-11-19 21:00:06.250    2015-11-19 21:00:06.250
2015-11-19 21:00:06.500    2015-11-19 21:00:06.500
2015-11-19 21:00:06.750    2015-11-19 21:00:06.750
2015-11-19 21:00:07.000    2015-11-19 21:00:07.000
2015-11-19 21:00:07.250    2015-11-19 21:00:07.250
                                    ...           
2015-12-31 14:59:52.750    2015-12-31 14:59:52.750
2015-12-31 14:59:53.000    2015-12-31 14:59:53.000
2015-12-31 14:59:53.250    2015-12-31 14:59:53.250
2015-12-31 14:59:53.500    2015-12-31 14:59:53.500
2015-12-31 14:59:53.750    2015-12-31 14:59:53.750
2015-12-31 14:59:54.000    2015-12-31 14:59:54.000
2015-12-31 14:59:54.250    2015-12-31 14:59:54.250
2015-12-31 14:59:54.500    2015-12-31 14:59:54.500
2015-12-31 14:59:54.750    2015-12-31 14:59:54.750
2015-12-31 14:59:55.000    2015-12-31 14:59:55.000
2015-12-31 14:59:55.250    2015-12-31 14:59:55.250
2015-12-31 14:59:55.500    2015-12-31 14:59:55.500
2015-12-31 14:59:55.750    2015-12-31 14:59:55.750
2015-12-31 14:59:56.000    2015-12-31 14:59:56.000
2015-12-31 14:59:56.250    2015-12-31 14:59:56.250
2015-12-31 14:59:56.500    2015-12-31 14:59:56.500
2015-12-31 14:59:56.750    2015-12-31 14:59:56.750
2015-12-31 14:59:57.000    2015-12-31 14:59:57.000
2015-12-31 14:59:57.250    2015-12-31 14:59:57.250
2015-12-31 14:59:57.500    2015-12-31 14:59:57.500
2015-12-31 14:59:57.750    2015-12-31 14:59:57.750
2015-12-31 14:59:58.000    2015-12-31 14:59:58.000
2015-12-31 14:59:58.250    2015-12-31 14:59:58.250
2015-12-31 14:59:58.500    2015-12-31 14:59:58.500
2015-12-31 14:59:58.750    2015-12-31 14:59:58.750
2015-12-31 14:59:59.000    2015-12-31 14:59:59.000
2015-12-31 14:59:59.250    2015-12-31 14:59:59.250
2015-12-31 14:59:59.500    2015-12-31 14:59:59.500
2015-12-31 14:59:59.750    2015-12-31 14:59:59.750
2015-12-31 15:00:00.000    2015-12-31 15:00:00.000
dtype: object

In [135]:
rm_index_str2 = rm.index.strftime('%T')

In [138]:
rm_index_str2 = pd.Series(data=rm_index_str2, index=rm.index)

In [17]:
chg_Vol = pd.Series(data=rm.ix[:, 'volume'].diff(), index=rm.index)
chg_OpenInt = pd.Series(data=rm.ix[:, 'openInterest'].diff(), index=rm.index)

In [62]:
day_len


Out[62]:
90003

In [61]:
len(rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'])


Out[61]:
90004

In [110]:
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(2,1,1)

ax.plot(rm.ix['2015-11-22 21:00:01': '2015-11-23 15:00:00', 'last'].values, lw=0.5, color='#f5f112')

labels = rm_index_str[day_len: day_len*2 +1]
ax.set_xticklabels(labels)

ax1 = ax.twinx()

ax1.plot(rm.ix['2015-11-22 21:00:01': '2015-11-23 15:00:00', 'openInterest'].values, lw=0.5, color='white')

# make ax and ax1 to be shown in the upper half of the figure
# ax.set_ylim(rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'].min() 
#             - 
#             (rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'].max() 
#               - rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'].min()),
#             rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'].max()
#             )
# ax1.set_ylim(rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'openInterest'].min() 
#             - 
#             (rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'openInterest'].max() 
#               - rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'openInterest'].min()),
#             rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'openInterest'].max()
#             )

# mf.volume_overlay2(ax2, 
#                    rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'], 
#                    chg_Vol.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00'], 
#                    colorup='#77d879', colordown='#db3f3f', alpha=.4)



ax2 = fig.add_subplot(2,1,2)
ax2.plot(chg_Vol.ix['2015-11-22 21:00:01': '2015-11-23 15:00:00'])
# make ax2 to be shown in the lowwer half of the figure
#ax2.set_ylim(0, chg_Vol.ix['2015-11-22 21:00:01': '2015-11-23 15:00:00'].values.max()*2)


Out[110]:
[<matplotlib.lines.Line2D at 0x7f1bd5b68e90>]

In [189]:
def myplot(myprc, myopen, myvol, mylabels, fs=(15,10)):
    fig = plt.figure(figsize=fs)
    ax = fig.add_subplot(2,1,1)
    
    ax.plot(myprc, lw=0.5, color='#f5f112')
    #labels = rm_index_str[day_len: day_len*2 +1]
    #ax.set_xticklabels(mylabels, fontsize=8, rotation=45)
    
    ax1 = ax.twinx()
    ax1.plot(myopen, lw=0.5, color='white')
#    make ax and ax1 to be shown in the upper half of the figure
#     ax.set_ylim(rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'].min() 
#                 - 
#                 (rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'].max() 
#                  - rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'].min()),
#                 rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'last'].max()
#                 )
#     ax1.set_ylim(rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'openInterest'].min() 
#                 - 
#                 (rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'openInterest'].max() 
#                  - rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'openInterest'].min()),
#                 rm.ix['2015-11-22 21:00:00': '2015-11-23 15:00:00', 'openInterest'].max()
#                 )
    ax2 = fig.add_subplot(2,1,2)
    ax2.plot(myvol)
    # make ax2 to be shown in the lowwer half of the figure
    #ax2.set_ylim(0, chg_Vol.ix['2015-11-22 21:00:01': '2015-11-23 15:00:00'].values.max()*2)
    plt.show()

whole day


In [195]:
t1, t2 = '2015-11-22 21:00:01', '2015-11-23 15:00:00'
myplot(rm.ix[t1: t2, 'last'], rm.ix[t1: t2, 'openInterest'], chg_Vol.ix[t1: t2], rm_index_str[t1: t2], fs=(24,10))



In [214]:
t1, t2 = '2015-11-22 21:15:01', '2015-11-22 21:25:00'
myplot(rm.ix[t1: t2, 'last'].values, 
       rm.ix[t1: t2, 'openInterest'].values, 
       chg_Vol.ix[t1: t2].values, 
       rm_index_str2[t1: t2].values,
       fs=(18,8))
rm.ix[t1: t2, ['TotalAskLot', 'TotalBidLot']].plot(figsize=(18,8))
rm.ix[t1: t2, ['askPrc_0', 'askPrc_1', 'askPrc_2', 'askPrc_3',
       'askPrc_4', 'bidPrc_0', 'bidPrc_1', 'bidPrc_2', 'bidPrc_3',
       'bidPrc_4', ]].plot(figsize=(18,8))


Out[214]:
<matplotlib.axes.AxesSubplot at 0x7f1c1c703d90>

In [181]:
rm.ix[t1: t2, ['askQty_0', 'askQty_1', 'askQty_2', 'askQty_3',
       'askQty_4', 'bidQty_0', 'bidQty_1', 'bidQty_2', 'bidQty_3',
       'bidQty_4']].plot(figsize=(18,8))


Out[181]:
<matplotlib.axes.AxesSubplot at 0x7f1c1d4ae390>

a drop


In [202]:
t1, t2 = '2015-11-22 22:00:01', '2015-11-22 23:30:00'
myplot(rm.ix[t1: t2, 'last'], 
       rm.ix[t1: t2, 'openInterest'].values, 
       chg_Vol.ix[t1: t2].values, 
       rm_index_str2[t1: t2].values,
       fs=(18,8))
rm.ix[t1: t2, ['TotalAskLot', 'TotalBidLot']].plot(figsize=(18,8))
rm.ix[t1: t2, ['askPrc_0', 'askPrc_1', 'askPrc_2', 'askPrc_3',
       'askPrc_4', 'bidPrc_0', 'bidPrc_1', 'bidPrc_2', 'bidPrc_3',
       'bidPrc_4', ]].plot(figsize=(18,8))


Out[202]:
<matplotlib.axes.AxesSubplot at 0x7f1c1c8c3090>

In [22]:
def prc_total(df, myvol, t1, t2, fs=(15,10)):
    fig = plt.figure(figsize=fs)
    ax1 = fig.add_subplot(411)
    
    ax1.plot(df.ix[t1: t2, 'last'], color='#f5f112', marker='*')
    plt.hold()

    ax3 = fig.add_subplot(413, sharex=ax1)
    ax3.plot(df.ix[t1: t2, 'TotalBidLot'] - df.ix[t1: t2, 'TotalAskLot'], color='white')
    # ax3.plot(df.ix[t1: t2, 'TotalAskLot'], lw=0.5, color='green')
    
    ax2 = fig.add_subplot(412, sharex=ax1)
    
    ax2.plot(np.zeros_like(myvol.ix[t1: t2].values), color='orange')
    ax2.plot(myvol.ix[t1: t2], color='orange', marker='*')
    ax2_2 = ax2.twinx()
    ax2_2.plot(df.ix[t1: t2, 'openInterest'], color='white', lw=0.4, marker='*')
    
    ax4 = fig.add_subplot(414, sharex=ax1)
    ax4.plot(df.ix[t1: t2, ['bidQty_0', 'bidQty_1', 'bidQty_2', 'bidQty_3', 'bidQty_4']].sum(axis=1).values, color='red')
    ax4.plot(df.ix[t1: t2, ['askQty_4', 'askQty_3', 'askQty_2', 'askQty_1', 'askQty_0']].sum(axis=1).values, color='green')
    return fig

In [286]:
t1, t2 = '2015-11-22 22:00:01', '2015-11-22 23:30:00'
thefig = prc_total(rm, chg_Vol, t1, t2, fs=(20,16))
multi = MultiCursor(thefig.canvas, thefig.axes, color='c', lw=1)
thefig.show()

In [288]:
t1, t2 = '2015-11-22 21:15:01', '2015-11-22 21:25:00'
thefig = prc_total(rm, chg_Vol, t1, t2, fs=(20,16))
multi = MultiCursor(thefig.canvas, thefig.axes, color='c', lw=1)
thefig.show()

In [290]:
t1, t2 = '2015-11-23 11:00:01', '2015-11-23 14:20:00'
thefig = prc_total(rm, chg_Vol, t1, t2, fs=(20,16))
multi = MultiCursor(thefig.canvas, thefig.axes, color='c', lw=1)
thefig.show()

In [25]:
t1, t2 = '2015-12-16 21:00:01', '2015-12-17 15:00:00'
thefig = prc_total(rm, chg_Vol, t1, t2, fs=(20,16))
multi = MultiCursor(thefig.canvas, thefig.axes, color='c', lw=1)
thefig.show()

see data


In [354]:
rm.ix['2015-11-22 21:00:01': '2015-11-23 15:00:00',:].ix[76070: 76120, ['volume', 'TotalAskLot', 
                                                                      'askQty_4', 'askQty_3', 'askQty_2', 'askQty_1', 'askPrc_1',
       'askQty_0', 'askPrc_0', 'last', 'bidPrc_0', 'bidQty_0', 'bidQty_1', 'bidQty_2', 'bidQty_3', 'bidQty_4', 
       'TotalBidLot', ]]


Out[354]:
volume TotalAskLot askQty_4 askQty_3 askQty_2 askQty_1 askPrc_1 askQty_0 askPrc_0 last bidPrc_0 bidQty_0 bidQty_1 bidQty_2 bidQty_3 bidQty_4 TotalBidLot
2015-11-23 14:01:57.750 1207914.0 17494.0 283.0 236.0 696.0 397.0 1714.0 298.0 1713.0 1712.0 1712.0 143.0 487.0 433.0 4843.0 0.0 5906.0
2015-11-23 14:01:58.000 1207920.0 17499.0 283.0 236.0 696.0 397.0 1714.0 301.0 1713.0 1712.0 1712.0 140.0 487.0 433.0 4843.0 0.0 5903.0
2015-11-23 14:01:58.250 1207938.0 17438.0 283.0 236.0 696.0 398.0 1714.0 297.0 1713.0 1712.0 1712.0 137.0 487.0 435.0 4843.0 0.0 5902.0
2015-11-23 14:01:58.500 1207944.0 17446.0 283.0 236.0 696.0 398.0 1714.0 305.0 1713.0 1712.0 1712.0 136.0 488.0 435.0 4843.0 0.0 5902.0
2015-11-23 14:01:58.750 1207950.0 17481.0 283.0 236.0 696.0 398.0 1714.0 340.0 1713.0 1713.0 1712.0 137.0 488.0 435.0 4843.0 0.0 5903.0
2015-11-23 14:01:59.000 1208040.0 17481.0 283.0 236.0 696.0 398.0 1714.0 340.0 1713.0 1712.0 1712.0 93.0 488.0 435.0 4843.0 0.0 5859.0
2015-11-23 14:01:59.250 1208042.0 17463.0 283.0 236.0 696.0 398.0 1714.0 342.0 1713.0 1712.0 1712.0 97.0 488.0 437.0 4843.0 0.0 5865.0
2015-11-23 14:01:59.500 1208048.0 17366.0 283.0 239.0 696.0 398.0 1714.0 242.0 1713.0 1712.0 1712.0 83.0 488.0 438.0 4843.0 0.0 5852.0
2015-11-23 14:01:59.750 1208170.0 17365.0 283.0 239.0 696.0 396.0 1714.0 242.0 1713.0 1712.0 1712.0 25.0 488.0 438.0 4845.0 0.0 5796.0
2015-11-23 14:02:00.000 1208220.0 17390.0 239.0 696.0 396.0 242.0 1713.0 25.0 1712.0 1712.0 1711.0 487.0 438.0 4845.0 0.0 0.0 5770.0
2015-11-23 14:02:00.250 1208222.0 17430.0 239.0 696.0 396.0 242.0 1713.0 65.0 1712.0 1712.0 1711.0 487.0 438.0 4845.0 0.0 0.0 5770.0
2015-11-23 14:02:00.500 1208232.0 17425.0 239.0 696.0 396.0 242.0 1713.0 60.0 1712.0 1712.0 1711.0 490.0 441.0 4848.0 0.0 0.0 5779.0
2015-11-23 14:02:00.750 1208238.0 17514.0 239.0 696.0 397.0 243.0 1713.0 147.0 1712.0 1712.0 1711.0 493.0 456.0 4848.0 0.0 0.0 5797.0
2015-11-23 14:02:01.000 1208292.0 17490.0 239.0 696.0 387.0 243.0 1713.0 133.0 1712.0 1711.0 1711.0 481.0 454.0 4848.0 0.0 0.0 5783.0
2015-11-23 14:02:01.250 1208306.0 17502.0 239.0 696.0 387.0 243.0 1713.0 141.0 1712.0 1712.0 1711.0 480.0 454.0 4848.0 0.0 0.0 5782.0
2015-11-23 14:02:01.500 1208310.0 17501.0 239.0 696.0 387.0 244.0 1713.0 139.0 1712.0 1712.0 1711.0 477.0 454.0 4848.0 0.0 0.0 5779.0
2015-11-23 14:02:01.750 1208312.0 17506.0 239.0 696.0 387.0 244.0 1713.0 143.0 1712.0 1711.0 1711.0 473.0 454.0 4848.0 0.0 0.0 5775.0
2015-11-23 14:02:02.000 1208338.0 17519.0 239.0 695.0 387.0 261.0 1713.0 140.0 1712.0 1712.0 1711.0 463.0 454.0 4848.0 0.0 0.0 5765.0
2015-11-23 14:02:02.250 1208340.0 17522.0 239.0 695.0 387.0 261.0 1713.0 142.0 1712.0 1711.0 1711.0 462.0 454.0 4849.0 0.0 0.0 5765.0
2015-11-23 14:02:02.500 1208340.0 17523.0 239.0 695.0 387.0 262.0 1713.0 142.0 1712.0 1711.0 1711.0 462.0 454.0 4850.0 0.0 0.0 5766.0
2015-11-23 14:02:02.750 1208358.0 17514.0 239.0 695.0 387.0 224.0 1713.0 171.0 1712.0 1712.0 1711.0 463.0 451.0 4850.0 0.0 0.0 5764.0
2015-11-23 14:02:03.000 1208358.0 17513.0 239.0 695.0 387.0 223.0 1713.0 171.0 1712.0 1712.0 1711.0 463.0 451.0 4850.0 0.0 0.0 5764.0
2015-11-23 14:02:03.250 1208360.0 17563.0 239.0 695.0 387.0 223.0 1713.0 221.0 1712.0 1712.0 1711.0 277.0 451.0 4850.0 0.0 0.0 5578.0
2015-11-23 14:02:03.500 1208364.0 17573.0 239.0 695.0 387.0 223.0 1713.0 231.0 1712.0 1712.0 1711.0 278.0 451.0 4853.0 0.0 0.0 5582.0
2015-11-23 14:02:03.750 1208364.0 17577.0 239.0 695.0 387.0 223.0 1713.0 235.0 1712.0 1712.0 1711.0 278.0 451.0 4853.0 0.0 0.0 5582.0
2015-11-23 14:02:04.000 1208372.0 17592.0 239.0 695.0 387.0 220.0 1713.0 253.0 1712.0 1711.0 1711.0 277.0 451.0 4853.0 0.0 0.0 5581.0
2015-11-23 14:02:04.250 1208372.0 17592.0 239.0 695.0 387.0 220.0 1713.0 253.0 1712.0 1711.0 1711.0 277.0 451.0 4853.0 0.0 0.0 5581.0
2015-11-23 14:02:04.500 1208378.0 17593.0 239.0 695.0 387.0 220.0 1713.0 254.0 1712.0 1712.0 1711.0 277.0 451.0 4854.0 0.0 0.0 5582.0
2015-11-23 14:02:04.750 1208434.0 17589.0 239.0 695.0 387.0 219.0 1713.0 251.0 1712.0 1712.0 1711.0 252.0 450.0 4854.0 0.0 0.0 5556.0
2015-11-23 14:02:05.000 1208442.0 17539.0 189.0 695.0 387.0 219.0 1713.0 251.0 1712.0 1711.0 1711.0 248.0 450.0 4854.0 0.0 0.0 5552.0
2015-11-23 14:02:05.250 1208622.0 17948.0 189.0 694.0 387.0 197.0 1713.0 683.0 1712.0 1711.0 1711.0 158.0 450.0 4854.0 0.0 0.0 5462.0
2015-11-23 14:02:05.500 1208828.0 17945.0 189.0 694.0 387.0 197.0 1713.0 680.0 1712.0 1711.0 1711.0 58.0 450.0 4854.0 0.0 0.0 5362.0
2015-11-23 14:02:05.750 1208832.0 17946.0 189.0 694.0 387.0 197.0 1713.0 679.0 1712.0 1711.0 1711.0 57.0 450.0 4854.0 0.0 0.0 5361.0
2015-11-23 14:02:06.000 1208946.0 17996.0 694.0 387.0 197.0 683.0 1712.0 45.0 1711.0 1711.0 1710.0 451.0 4854.0 0.0 0.0 0.0 5305.0
2015-11-23 14:02:06.250 1208954.0 18011.0 694.0 387.0 197.0 688.0 1712.0 55.0 1711.0 1711.0 1710.0 451.0 4854.0 0.0 0.0 0.0 5305.0
2015-11-23 14:02:06.500 1208968.0 18651.0 694.0 387.0 197.0 689.0 1712.0 694.0 1711.0 1711.0 1710.0 446.0 4854.0 0.0 0.0 0.0 5300.0
2015-11-23 14:02:06.750 1208984.0 18196.0 694.0 387.0 197.0 191.0 1712.0 752.0 1711.0 1710.0 1710.0 444.0 4854.0 0.0 0.0 0.0 5298.0
2015-11-23 14:02:07.000 1208992.0 18199.0 694.0 387.0 199.0 192.0 1712.0 752.0 1711.0 1710.0 1710.0 441.0 4855.0 0.0 0.0 0.0 5296.0
2015-11-23 14:02:07.250 1208992.0 18205.0 694.0 387.0 188.0 193.0 1712.0 769.0 1711.0 1710.0 1710.0 441.0 4855.0 0.0 0.0 0.0 5296.0
2015-11-23 14:02:07.500 1208992.0 18029.0 694.0 385.0 149.0 193.0 1712.0 634.0 1711.0 1710.0 1710.0 445.0 4855.0 0.0 0.0 0.0 5300.0
2015-11-23 14:02:07.750 1209024.0 18033.0 694.0 385.0 153.0 193.0 1712.0 634.0 1711.0 1710.0 1710.0 429.0 4855.0 0.0 0.0 0.0 5284.0
2015-11-23 14:02:08.000 1209024.0 18034.0 694.0 385.0 153.0 194.0 1712.0 634.0 1711.0 1710.0 1710.0 429.0 4855.0 0.0 0.0 0.0 5284.0
2015-11-23 14:02:08.250 1209882.0 18619.0 385.0 153.0 194.0 634.0 1711.0 585.0 1710.0 1710.0 1709.0 4855.0 0.0 0.0 0.0 0.0 4855.0
2015-11-23 14:02:08.500 1209884.0 18655.0 385.0 153.0 194.0 634.0 1711.0 621.0 1710.0 1710.0 1709.0 4857.0 0.0 0.0 0.0 0.0 4857.0
2015-11-23 14:02:08.750 1209884.0 18690.0 385.0 153.0 219.0 634.0 1711.0 621.0 1710.0 1710.0 1709.0 4860.0 0.0 0.0 0.0 0.0 4860.0
2015-11-23 14:02:09.000 1209886.0 18538.0 385.0 152.0 219.0 634.0 1711.0 620.0 1710.0 1710.0 1709.0 4760.0 0.0 0.0 0.0 0.0 4760.0
2015-11-23 14:02:09.250 1209892.0 18546.0 385.0 152.0 219.0 633.0 1711.0 629.0 1710.0 1710.0 1709.0 4758.0 0.0 0.0 0.0 0.0 4758.0
2015-11-23 14:02:09.500 1209922.0 18532.0 384.0 152.0 207.0 633.0 1711.0 629.0 1710.0 1709.0 1709.0 4748.0 0.0 0.0 0.0 0.0 4748.0
2015-11-23 14:02:09.750 1209952.0 18583.0 381.0 152.0 185.0 658.0 1711.0 680.0 1710.0 1709.0 1709.0 4745.0 0.0 0.0 0.0 0.0 4745.0
2015-11-23 14:02:10.000 1209992.0 18633.0 381.0 152.0 180.0 658.0 1711.0 730.0 1710.0 1709.0 1709.0 4726.0 0.0 0.0 0.0 0.0 4726.0

In [330]:
np.where(abs(rm.ix[:, 'last'].diff()) > 2)


Out[330]:
(array([ 126006,  126008,  162255,  180008,  216010,  216011,  216014,
        217799,  306017,  338418,  360016,  396019,  450022,  486022,
        488461,  540024,  540026,  540028,  540030,  540032,  540034,
        540036,  540037,  540038,  540039,  540042,  540071,  540072,
        576140,  576269,  720032,  720039,  720040,  720041,  720063,
        720064,  720066,  720067,  756038,  900551,  990044, 1026046,
       1026047, 1026048, 1026049, 1026050, 1080048, 1080049, 1093189,
       1116050, 1116054, 1116058, 1116063, 1116230, 1116381, 1206054,
       1206061, 1260056, 1260064, 1260066, 1260068, 1260070, 1260076,
       1260078, 1260081, 1260092, 1260093, 1530068, 1656074, 1746078,
       1748619, 1748628, 1748631, 1836082, 1836086, 1836091, 1836098,
       1836111, 1890084, 1890096, 1926086, 1926095, 1926204, 1926212,
       1926217, 1926219, 1926222, 1926226, 2016090, 2070094, 2106094,
       2106100, 2196098, 2250100, 2340104, 2466110]),)

In [ ]:
t1, t2 = 0, 2700000
thefig = prc_total(rm, chg_Vol, t1, t2, fs=(20,16))
multi = MultiCursor(thefig.canvas, thefig.axes, color='c', lw=1)
thefig.show()