barfeed – Bar providers

class pyalgotrade.barfeed.BaseBarFeed(frequency, maxLen=None)

Bases: pyalgotrade.feed.BaseFeed

Base class for pyalgotrade.bar.Bar providing feeds.

Parameters:
  • frequency – The bars frequency. Valid values defined in pyalgotrade.bar.Frequency.
  • maxLen (int.) – The maximum number of values that the pyalgotrade.dataseries.bards.BarDataSeries will hold. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used.

Note

This is a base class and should not be used directly.

getNextBars()

Override to return the next pyalgotrade.bar.Bars in the feed or None if there are no bars.

Note

This is for BaseBarFeed subclasses and it should not be called directly.

getCurrentBars()

Returns the current pyalgotrade.bar.Bars.

getLastBar(instrument)

Returns the last pyalgotrade.bar.Bar for a given instrument, or None.

getDefaultInstrument()

Returns the last instrument registered.

getRegisteredInstruments()

Returns a list of registered intstrument names.

getDataSeries(instrument=None)

Returns the pyalgotrade.dataseries.bards.BarDataSeries for a given instrument.

Parameters:instrument (string.) – Instrument identifier. If None, the default instrument is returned.
Return type:pyalgotrade.dataseries.bards.BarDataSeries.

CSV

class pyalgotrade.barfeed.csvfeed.BarFeed(frequency, maxLen=None)

Bases: pyalgotrade.barfeed.membf.BarFeed

Base class for CSV file based pyalgotrade.barfeed.BarFeed.

Note

This is a base class and should not be used directly.

class pyalgotrade.barfeed.csvfeed.GenericBarFeed(frequency, timezone=None, maxLen=None)

Bases: pyalgotrade.barfeed.csvfeed.BarFeed

A BarFeed that loads bars from CSV files that have the following format:

Date Time,Open,High,Low,Close,Volume,Adj Close
2013-01-01 13:59:00,13.51001,13.56,13.51,13.56,273.88014126,13.51001
Parameters:
  • frequency – The frequency of the bars. Check pyalgotrade.bar.Frequency.
  • timezone (A pytz timezone.) – The default timezone to use to localize bars. Check pyalgotrade.marketsession.
  • maxLen (int.) – The maximum number of values that the pyalgotrade.dataseries.bards.BarDataSeries will hold. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used.

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, skipMalformedBars=False)

Loads bars for a given instrument from a CSV formatted file. The instrument gets registered in the bar feed.

Parameters:
  • instrument (string.) – Instrument identifier.
  • path (string.) – The path to the CSV file.
  • timezone (A pytz timezone.) – The timezone to use to localize bars. Check pyalgotrade.marketsession.
  • skipMalformedBars (boolean.) – True to skip errors while parsing bars.
setDateTimeFormat(dateTimeFormat)

Set the format string to use with strptime to parse datetime column.

Yahoo! Finance

class pyalgotrade.barfeed.yahoofeed.Feed(frequency=86400, timezone=None, maxLen=None)

Bases: pyalgotrade.barfeed.csvfeed.BarFeed

A pyalgotrade.barfeed.csvfeed.BarFeed that loads bars from CSV files downloaded from Yahoo! Finance.

Parameters:
  • frequency – The frequency of the bars. Only pyalgotrade.bar.Frequency.DAY or pyalgotrade.bar.Frequency.WEEK are supported.
  • timezone (A pytz timezone.) – The default timezone to use to localize bars. Check pyalgotrade.marketsession.
  • maxLen (int.) – The maximum number of values that the pyalgotrade.dataseries.bards.BarDataSeries will hold. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used.

Note

Yahoo! Finance csv files lack timezone information. 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 must 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:
  • instrument (string.) – Instrument identifier.
  • path (string.) – The path to the CSV file.
  • timezone (A pytz timezone.) – The timezone to use to localize bars. Check pyalgotrade.marketsession.

Google Finance

class pyalgotrade.barfeed.googlefeed.Feed(frequency=86400, timezone=None, maxLen=None)

Bases: pyalgotrade.barfeed.csvfeed.BarFeed

A pyalgotrade.barfeed.csvfeed.BarFeed that loads bars from CSV files downloaded from Google Finance.

Parameters:
  • frequency – The frequency of the bars. Only pyalgotrade.bar.Frequency.DAY is currently supported.
  • timezone (A pytz timezone.) – The default timezone to use to localize bars. Check pyalgotrade.marketsession.
  • maxLen (int.) – The maximum number of values that the pyalgotrade.dataseries.bards.BarDataSeries will hold. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used.

Note

Google Finance csv files lack timezone information. 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 must be set.
addBarsFromCSV(instrument, path, timezone=None, skipMalformedBars=False)

Loads bars for a given instrument from a CSV formatted file. The instrument gets registered in the bar feed.

Parameters:
  • instrument (string.) – Instrument identifier.
  • path (string.) – The path to the CSV file.
  • timezone (A pytz timezone.) – The timezone to use to localize bars. Check pyalgotrade.marketsession.
  • skipMalformedBars (boolean.) – True to skip errors while parsing bars.

Quandl

class pyalgotrade.barfeed.quandlfeed.Feed(frequency=86400, timezone=None, maxLen=None)

Bases: pyalgotrade.barfeed.csvfeed.GenericBarFeed

A pyalgotrade.barfeed.csvfeed.BarFeed that loads bars from CSV files downloaded from Quandl.

Parameters:
  • frequency – The frequency of the bars. Only pyalgotrade.bar.Frequency.DAY or pyalgotrade.bar.Frequency.WEEK are supported.
  • timezone (A pytz timezone.) – The default timezone to use to localize bars. Check pyalgotrade.marketsession.
  • maxLen (int.) – The maximum number of values that the pyalgotrade.dataseries.bards.BarDataSeries will hold. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used.

Note

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 must be set.

Ninja Trader

class pyalgotrade.barfeed.ninjatraderfeed.Feed(frequency, timezone=None, maxLen=None)

Bases: pyalgotrade.barfeed.csvfeed.BarFeed

A pyalgotrade.barfeed.csvfeed.BarFeed that loads bars from CSV files exported from NinjaTrader.

Parameters:
  • frequency – The frequency of the bars. Only pyalgotrade.bar.Frequency.MINUTE or pyalgotrade.bar.Frequency.DAY are supported.
  • timezone (A pytz timezone.) – The default timezone to use to localize bars. Check pyalgotrade.marketsession.
  • maxLen (int.) – The maximum number of values that the pyalgotrade.dataseries.bards.BarDataSeries will hold. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used.
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:
  • instrument (string.) – Instrument identifier.
  • path (string.) – The path to the file.
  • timezone (A pytz timezone.) – The timezone to use to localize bars. Check pyalgotrade.marketsession.

Table Of Contents

Previous topic

feed – Basic feeds

Next topic

technical – Technical indicators

This Page