gpt4 book ai didi

csv - 如何将我自己的数据输入 PyAlgoTrade?

转载 作者:行者123 更新时间:2023-12-04 14:23:17 25 4
gpt4 key购买 nike

I'm trying to use PyAlogoTrade 's event profiler

但是我不想使用来自 的数据雅虎财经 ,我想用我自己的但是在中不知道怎么解析CSV ,其格式为:

Timestamp      Low  Open   Close       High        BTC_vol     USD_vol       [8]      [9]
2013-11-23 00 800 860 847.666666 886.876543 853.833333 6195.334452 5248330 0
2013-11-24 00 745 847.5 815.01 860 831.255 10785.94131 8680720 0

The complete CSV is here

我想做类似的事情:
def main(plot):
instruments = ["AA", "AES", "AIG"]
feed = yahoofinance.build_feed(instruments, 2008, 2009, ".")

然后替换 yahoofinance.build_feed(instruments, 2008, 2009, ".")和我的 CSV
我试过:
import csv

with open( 'FinexBTCDaily.csv', 'rb' ) as csvfile:
data = csv.reader( csvfile )

def main( plot ):
feed = data

但它会引发属性错误。任何想法如何做到这一点?

最佳答案

步骤A: 上关注 PyAlgoTrade 文档GenericBarFeed 类(class)

On this link see the addBarsFromCSV() in CSV section of the BarFeed class in v0.16

On this link see the addBarsFromCSV() in CSV section of the BarFeed class in v0.17

Note

- The CSV file must have the column names in the first row.
- It is ok if the Adj Close column is empty.
- When working with multiple instruments:
--- If all the instruments loaded are in the same timezone, then the timezone parameter may not be specified.
--- If any of the instruments loaded are in different timezones, then the timezone parameter should be set.

addBarsFromCSV( instrument, path, timezone = None )
Loads bars for a given instrument from a CSV formatted file. The instrument gets registered in the bar feed.

Parameters:
(string) instrument – Instrument identifier.
(string) path – The path to the CSV file.
(pytz) timezone – The timezone to use to localize bars.
Check pyalgotrade.marketsession.



下一个:
A BarFeed 从具有以下格式的 CSV 文件加载条形图:
Date       Time,    Open,    High, Low,  Close,   Volume,      Adj Close
2013-01-01 13:59:00,13.51001,13.56,13.51,13.56789,273.88014126,13.51001

步骤 B:实现记录的 CSV 文件预格式化

您的 CSV 数据需要一些理智(之前可以在 PyAlgoTrade 方法中使用),但是它是可行的,您可以手动或使用强大 numpy.genfromtxt() lambda-基于 converters设施。

此示例代码用于说明目的,以便立即了解 的功能。 converters 用于您自己的转换,因为 CSV 结构不同。
with  open( getCsvFileNAME( ... ), "r" ) as aFH:
numpy.genfromtxt( aFH,
skip_header = 1, # Ref. pyalgotrade
delimiter = ",",
# v v v v v v
# 2011.08.30,12:00,1791.20,1792.60,1787.60,1789.60,835
# 2011.08.30,13:00,1789.70,1794.30,1788.70,1792.60,550
# 2011.08.30,14:00,1792.70,1816.70,1790.20,1812.10,1222
# 2011.08.30,15:00,1812.20,1831.50,1811.90,1824.70,2373
# 2011.08.30,16:00,1824.80,1828.10,1813.70,1817.90,2215
converters = { 0: lambda aString: mPlotDATEs.date2num( datetime.datetime.strptime( aString, "%Y.%m.%d" ) ), #_______________________________________asFloat ( 1.0, +++ )
1: lambda aString: ( ( int( aString[0:2] ) * 60 + int( aString[3:] ) ) / 60. / 24. ) # ( 15*60 + 00 ) / 60. / 24.__asFloat < 0.0, 1.0 )
# HH: :MM HH MM
}
)

关于csv - 如何将我自己的数据输入 PyAlgoTrade?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37003788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com