Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Added generic input support for Pandas DataFrames and List Structures#107

Open
flipdazed wants to merge 1 commit into
gbeced:masterfrom
flipdazed:master
Open

Added generic input support for Pandas DataFrames and List Structures#107
flipdazed wants to merge 1 commit into
gbeced:masterfrom
flipdazed:master

Conversation

@flipdazed

@flipdazed flipdazed commented Sep 5, 2017

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

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!

@9590 9590 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@flipdazed

Copy link
Copy Markdown
Author

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



# Interface for csv row parsers.
class RowParser(object):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This RowParser class is not used, and it can be removed.

if missing_columns:
raise ValueError('Missing required columns: {}'.format(repr(missing_columns)))

df = df[self.__columnNames.values()]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will prevent extra columns from being included on each bar.

@gbeced

gbeced commented Mar 1, 2018

Copy link
Copy Markdown
Owner
  • 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

@reijmer

reijmer commented Dec 21, 2019

Copy link
Copy Markdown

Any chance this will be merged in the near future?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants