Numpy / Matplotlib - Transform tick data into OHLCV

我们两清 提交于 2021-02-10 03:51:13

问题


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,

来源:https://stackoverflow.com/questions/18413903/numpy-matplotlib-transform-tick-data-into-ohlcv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!