我有外汇对的逐点数据
以下是EURUSD/EURUSD-2012-06.csv
的示例
EUR/USD,20120601 00:00:00.207,1.23618,1.2363
EUR/USD,20120601 00:00:00.209,1.23618,1.23631
EUR/USD,20120601 00:00:00.210,1.23618,1.23631
EUR/USD,20120601 00:00:00.211,1.23623,1.23631
EUR/USD,20120601 00:00:00.240,1.23623,1.23627
EUR/USD,20120601 00:00:00.423,1.23622,1.23627
EUR/USD,20120601 00:00:00.457,1.2362,1.23626
EUR/USD,20120601 00:00:01.537,1.2362,1.23625
EUR/USD,20120601 00:00:03.010,1.2362,1.23624
EUR/USD,20120601 00:00:03.012,1.2362,1.23625
完整的勾号数据可以在这里下载 http://dl.free.fr/k4vVF7aOD
列为:
^{pr2}$我想把这个滴答滴答的数据转换成人字图 http://www.investopedia.com/terms/r/renkochart.asp
烛光高度是指烛光的高度
我想用Python和Pandas库来实现这个任务。在
我已经完成了一小部分工作。。。读取逐点数据文件
我想得到像
Id,Symbol,open_price,close_price
能画人子
Id是蜡烛的编号
蜡烛价格将以投标栏为基础。在
这是密码
#!/usr/bin/env python
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.finance import candlestick
def candle_price_ref(price, candle_height):
#return(int(price/candle_height)*candle_height)
return(round(price/candle_height)*candle_height)
print("Reading CSV (please wait)")
df = pd.read_csv('test_EURUSD/EURUSD-2012-07.csv', names=['Symbol', 'Date_Time', 'Bid', 'Ask'], index_col=1)
print("End of reading")
df['Bid'] = df['Bid']
#candle_height = 0.0015
#candle_height = 0.0010
#candle_height = 0.0005
candle_height = 0.0001
#candle_height = 0.000001
price = df.ix[0]['Bid']
price_ref = candle_price_ref(price, candle_height)
ID = 0
#print("ID={0} price_ref={1}".format(ID, price_ref))
candle_price_open = []
candle_price_close = []
candle_price_open.append(price) # price ou price_ref
candle_price_close.append(price)
for i in range(len(df)):
price = df.ix[i]['Bid']
candle_price_close[ID] = price
new_price_ref = candle_price_ref(price, candle_height)
if new_price_ref!=price_ref:
candle_price_close[ID]=new_price_ref
price_ref = new_price_ref
ID += 1
candle_price_open.append(price_ref)
candle_price_close.append(price_ref)
IDs=range(ID+1)
volume=np.zeros(ID+1)
a_price_open=np.array(candle_price_open)
a_price_close=np.array(candle_price_close)
b_green_candle = a_price_open < a_price_close
candle_price_low = np.where(b_green_candle, a_price_open, a_price_close)
candle_price_high = np.where(b_green_candle, a_price_close, a_price_open)
DOCHLV=zip(IDs, candle_price_open, candle_price_close, candle_price_high, candle_price_low, volume)
#print(DOCHLV)
fig = plt.figure()
fig.subplots_adjust(bottom=0.1)
ax = fig.add_subplot(211)
df['Bid'].plot()
plt.title("Price graph")
ax = fig.add_subplot(212)
plt.title("Renko chart")
candlestick(ax, DOCHLV, width=0.6, colorup='g', colordown='r', alpha=1.0)
plt.show()
我的问题是,我在这里做的不是一个真正的仁科图,原因有二:
我正在寻找一个相当快速的算法,如果可能的话,一个矢量化的算法(如果可能的话),因为蜱虫的数据可能非常大。在
但我想我不太明白你想做什么。。。在
相关问题 更多 >
编程相关推荐