pyalgotrade icon indicating copy to clipboard operation
pyalgotrade copied to clipboard

Added generic input support for Pandas DataFrames and List Structures

Open flipdazed opened this issue 8 years ago • 4 comments

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)

flipdazed avatar Sep 05 '17 17:09 flipdazed

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!

flipdazed avatar Sep 06 '17 15:09 flipdazed

is there anything more I need to do on this to get it merged?

flipdazed avatar Feb 19 '18 22:02 flipdazed

  • 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

gbeced avatar Mar 01 '18 02:03 gbeced

Any chance this will be merged in the near future?

reijmer avatar Dec 21 '19 14:12 reijmer