我已经勾选外汇对的价格数据
以下是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
列是:
Symbol,Datetime,Bid,Ask
我想将此刻度数字转换为Renko图表 http://www.investopedia.com/terms/r/renkochart.asp
图表的参数是蜡烛高度(close-open):让我们称之为candle_height
我想使用Python和Pandas库来完成这项任务。
我完成了工作的一小部分......通过勾选数据文件
阅读我想获得像
这样的数据Id,Symbol,open_price,close_price
能够画Renko
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()
我的问题是,我在这里所做的并不是真正的Renko图表,原因有二:
我正在寻找一种非常快速的算法,如果可能的话,矢量化算法(如果可能的话)作为刻度数据可能非常大。
答案 0 :(得分:0)
for i,row in enumerate(df.values):
ID = i
sym,timestamp,open_price,close_price = row
print ID,sym,open_price,close_price
但我不认为我完全明白你要做什么......