3

I have tick data that I wold like to transform in OHLCV(Open, High, Low, Close, Volume) Daily, Hourly, 15min, 5min, 1min.

The tick data that I have is like this:

array([[u'2011-08-18 13:37:25', u'10.9', u'0.48990826'],
   [u'2011-08-19 13:19:24', u'11.85', u'0.08438819'],
   [u'2011-08-19 16:45:01', u'11.5', u'0.4'],
   ..., 
   [u'2013-08-24 01:29:27', u'107.97', u'0.18523664'],
   [u'2013-08-24 01:29:35', u'107.98', u'4.61659567'],
   [u'2013-08-24 01:30:56', u'107.98', u'0.09339562']], 
  dtype='<U19')

The numpy array have (date, price, volume).

I got the data to the nympy array with this code:

import matplotlib.pyplot as plt
import sqlite3
import numpy as np

database = sqlite3.connect('database.db')
cursor = database.cursor() # Criar o cursor
cursor.execute("select date, price, amount from table order by date asc")

ar=[[r[0], r[1], r[2]] for r in cursor.fetchall()]
database.close()

arnp = np.array(ar)
plt.plot(arnp[:, 1])
plt.ylabel('some...')
plt.show()

I really don't know what the best method to do this transformation. I've the data in a Sqlite database, it will be easier to do this transformation using SQL or using Python?

Any clues?

Best Regards,

André
  • 24,706
  • 43
  • 121
  • 178
  • 1
    Take a look at Pandas, it can interface with sqlite and has an 'ohlc' aggregator build in. Seems perfect for what you want: http://stackoverflow.com/questions/13464492/ohlc-aggregator-doesnt-work-with-dataframe-on-pandas – Rutger Kassies Aug 24 '13 at 16:52

0 Answers0