pyalgotrade
pyalgotrade copied to clipboard
Added generic input support for Pandas DataFrames and List Structures
This allows users to easily take advantage of arbitrary data structures as inputs if they are already loaded into memory e.g. for creating custom stressed scenarios
Example
import pandas as pd
import numpy as np
vals = np.array([['2015-08-14 09:06:00', 0.0069, 0.0069, 0.0069, 0.0069, 1.34611713,
9567],
['2015-08-14 09:10:00', 0.0069, 0.0069, 0.0069, 0.0069, 0.37540654,
8751],
['2015-08-14 09:13:00', 0.0069, 0.0069, 0.0069, 0.0069, 0.18775374,
7758],
['2015-08-14 09:23:00', 0.0069, 0.006959999999999999,
0.006959999999999999, 0.0069, 0.09382613, 4662],
['2015-08-14 09:25:00', 0.006959999999999999, 0.00716, 0.00716,
0.006959999999999999, 4.98869811, 9409]], dtype=object)
cols = [u'Date Time', u'Open', u'Close', u'High', u'Low',
u'Volume', u'Adj Close']
df = pd.DataFrame(vals, columns=cols)
df = df.convert_objects()
# resample irregular data to regular time series
df['Date Time'] = pd.to_datetime(df['Date Time'])
df = df.set_index('Date Time').resample('s').interpolate().resample('5T').asfreq().dropna().reset_index()
from pyalgotrade.barfeed import customfeed
feed = customfeed.Feed(Frequency.MINUTE*5)
feed.addBarsFromDataFrame('test', df)
It seems that the failures aren't related to my code as indicated by the node coverage report
pyalgotrade/barfeed/customfeed.py 82 82 0%
Also I've improved the code-quality by removing the two libraries that were not longer needed Let me know your thoughts!
is there anything more I need to do on this to get it merged?
- I'd recommend creating two separate modules:
- pandasfeed
- listfeed
- The dataframe seems to be getting converted to strings, and then it will be converted back to floats and datetimes in csvfeed.GenericRowParser.
- Please add testcases
Any chance this will be merged in the near future?