In [14]:
%matplotlib inline
from matplotlib.pyplot import plot

from redis import StrictRedis
from activetick_http import ActiveTick
from datetime import datetime
import pandas as pd

at = ActiveTick(cache=StrictRedis(host='127.0.0.1'))
def drop_dupe_index(df):
    return df[~df.index.duplicated()]

In [15]:
beginTime = datetime(2016, 9, 29, 10, 40)
endTime = datetime(2016, 9, 29, 10, 50)
trades = at.tickData('GDX', trades=True, quotes=False, beginTime=beginTime, endTime=endTime)
quotes = at.tickData('GDX', trades=False, quotes=True, beginTime=beginTime, endTime=endTime)

In [16]:
mid = (quotes['ask'] + quotes['bid'])/2
mid = drop_dupe_index(mid).dropna()

In [17]:
# difference between the last executed trade and the mid point between bid/ask
diff = mid - trades['last']
diff = drop_dupe_index(diff).dropna()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-aabf48e01163> in <module>()
      1 # difference between the last executed trade and the mid point between bid/ask
----> 2 diff = mid - trades['last']
      3 diff = drop_dupe_index(diff).dropna()

/home/nak/PycharmProjects/activetickdata/lib/python3.5/site-packages/pandas/core/ops.py in wrapper(left, right, name, na_op)
    599             else:
    600                 index, lidx, ridx = left.index.join(rindex, how='outer',
--> 601                                                        return_indexers=True)
    602 
    603                 if lidx is not None:

/home/nak/PycharmProjects/activetickdata/lib/python3.5/site-packages/pandas/tseries/index.py in join(self, other, how, level, return_indexers)
   1011         this, other = self._maybe_utc_convert(other)
   1012         return Index.join(this, other, how=how, level=level,
-> 1013                           return_indexers=return_indexers)
   1014 
   1015     def _maybe_utc_convert(self, other):

/home/nak/PycharmProjects/activetickdata/lib/python3.5/site-packages/pandas/core/index.py in join(self, other, how, level, return_indexers)
   2276             return self._join_non_unique(other, how=how,
   2277                                          return_indexers=return_indexers)
-> 2278         elif not self.is_unique or not other.is_unique:
   2279             if self.is_monotonic and other.is_monotonic:
   2280                 return self._join_monotonic(other, how=how,

pandas/src/properties.pyx in pandas.lib.cache_readonly.__get__ (pandas/lib.c:44341)()

/home/nak/PycharmProjects/activetickdata/lib/python3.5/site-packages/pandas/core/index.py in is_unique(self)
    810     def is_unique(self):
    811         """ return if the index has unique values """
--> 812         return self._engine.is_unique
    813 
    814     @property

pandas/index.pyx in pandas.index.IndexEngine.is_unique.__get__ (pandas/index.c:4711)()

pandas/index.pyx in pandas.index.IndexEngine._do_unique_check (pandas/index.c:5305)()

pandas/index.pyx in pandas.index.IndexEngine._ensure_mapping_populated (pandas/index.c:5510)()

pandas/index.pyx in pandas.index.IndexEngine.initialize (pandas/index.c:5620)()

pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.map_locations (pandas/hashtable.c:7191)()

/home/nak/PycharmProjects/activetickdata/lib/python3.5/site-packages/pandas/hashtable.cpython-35m-x86_64-linux-gnu.so in View.MemoryView.memoryview_cwrapper (pandas/hashtable.c:29636)()

/home/nak/PycharmProjects/activetickdata/lib/python3.5/site-packages/pandas/hashtable.cpython-35m-x86_64-linux-gnu.so in View.MemoryView.memoryview.__cinit__ (pandas/hashtable.c:26005)()

ValueError: buffer source array is read-only

In [9]:
mid = mid - float(mid[0])
last = drop_dupe_index(trades['last'])
last = last - float(last[0])

df = pd.concat([mid, diff, last], axis=1).dropna(axis=0, how='any')
df.columns = ['mid', 'diff', 'last']
df.plot()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-9-02aa5d8acd78> in <module>()
      3 last = last - float(last[0])
      4 
----> 5 df = pd.concat([mid, diff, last], axis=1).dropna(axis=0, how='any')
      6 df.columns = ['mid', 'diff', 'last']
      7 df.plot()

NameError: name 'diff' is not defined

In [130]:
diff = diff.cumsum()
df = pd.concat([mid, diff, last], axis=1).dropna(axis=0, how='any')
df.columns = ['mid', 'diff', 'last']
df.plot()


Out[130]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f7347e66f98>

In [ ]: