1

i tried to code below:

from pyalgotrade.feed import csvfeed

feed=csvfeed.Feed("Date","%Y.%M.%d %H:%m:%S")

feed.addValuesFromCSV('/Users/emacsen/Duka_Data/EURUSD_UTC_1 Min_Bid_2005.01.01_2015.10.05.csv')

and an error turned out to be :

dateTime = datetime.datetime.strptime(csvRowDict[self.__dateTimeColumn], self.__dateTimeFormat) KeyError: 'Date'

if I use formatting style "Date","%Y.%m.%d %H:%M:%S" ,same error:

feed=csvfeed.Feed("Date","%Y.%m.%d %H:%M:%S")

feed.addValuesFromCSV('/Users/emacsen/Duka_Data/EURUSD_UTC_1 Min_Bid_2005.01.01_2015.10.05.csv')

Traceback (most recent call last):

File "", line 1, in

File "/Users/emacsen/anaconda/envs/py2.7/lib/python2.7/site-packages/pyalgotrade/feed/csvfeed.py", line 171, in addValuesFromCSV return BaseFeed.addValuesFromCSV(self, path)

File "/Users/emacsen/anaconda/envs/py2.7/lib/python2.7/site-packages/pyalgotrade/feed/csvfeed.py", line 90, in addValuesFromCSV dateTime, rowValues = self.__rowParser.parseRow(row)

File "/Users/emacsen/anaconda/envs/py2.7/lib/python2.7/site-packages/pyalgotrade/feed/csvfeed.py", line 108, in parseRow dateTime = datetime.datetime.strptime(csvRowDict[self.__dateTimeColumn], self.__dateTimeFormat) KeyError: 'Date'


if I use pandas.read_csv() instead,it can be well read , so what is wrong with my Date formatting?

the csv file is formatted

Time,Open,High,Low,Close,Volume 

2005.01.02 22:00:00,1.35464,1.3548,1.35464,1.3548,152.2
2005.01.02 22:01:00,1.35485,1.35489,1.35464,1.35479,409.1
2005.01.02 22:02:00,1.35492,1.35492,1.3547,1.3547,687.5
2005.01.02 22:03:00,1.35493,1.35501,1.35469,1.35486,604
2005.01.02 22:04:00,1.35485,1.35507,1.35478,1.3548,541.5

the last column is traded volume of EUR/USD

and by the way, how does pyalgotrade go along with pandas? can i use pandas to read a csv file and transfer that to pyalgotrade?

Emacsen
  • 11
  • 2
  • Shouldn't the format be `("Date","%Y.%m.%d %H:%M:%S")` e.g. month and minute formats swapped around – EdChum Jan 08 '16 at 13:16
  • Also how do you determine the column header names? your sample includes no header line – EdChum Jan 08 '16 at 13:17
  • Don't post as comment, edit your question so we don't lose formatting, also did you try my format string? – EdChum Jan 08 '16 at 13:24
  • Your csv shows no column called `Date` you do have one called `Time` – EdChum Jan 08 '16 at 13:31
  • Have you tried on 'Time' column? `"Time","%Y.%m.%d %H:%M:%S"` – EdChum Jan 08 '16 at 13:49
  • yes that is right, it is working now. and .....but pyalgotrade is rather slow to read a large csv file more than 4 million lines .can i read it into pandas and transfer it to pyalgotrade? – Emacsen Jan 08 '16 at 13:55
  • @user2834945 If you have a new question, I encourage you to submit that as a new question on StackOverflow, that will have the best chance of getting you a quality answer. – Kyle Pittman Jan 08 '16 at 13:57
  • I have no idea about pyalgotrade, unless it supports numpy arrays as dtype then no is the answer, otherwise I can post why your original error occurred and you can accept my answer so this question remains closed – EdChum Jan 08 '16 at 13:58
  • As-is, I'm voting to close this question as [off-topic](http://stackoverflow.com/help/on-topic) because it was caused by typo. – Kyle Pittman Jan 08 '16 at 14:00

1 Answers1

1

You have a couple errors, the KeyError is because you tried to refer to a column that didn't exist, it's Time and not Date, the second is your format string, your month and minute specifier should be swapped around:

feed=csvfeed.Feed("Time","%Y.%m.%d %H:%M:%S")

is the correct form, see the docs: http://strftime.org/

As to the slow performance and compatibility with pandas I have no idea, pyalgotrade needs to support numpy arrays in order for it to work with a pandas df.

EdChum
  • 376,765
  • 198
  • 813
  • 562