barfeed – Bar providers

class pyalgotrade.barfeed.BarFeed(frequency, maxLen=1024)

Bases: pyalgotrade.barfeed.BasicBarFeed

Base class for pyalgotrade.bar.Bars providing feeds.

Parameters:
  • frequency (barfeed.Frequency.MINUTE or barfeed.Frequency.DAY.) – The bars frequency.
  • maxLen (int.) – The maximum number of values that the pyalgotrade.dataseries.bards.BarDataSeries will hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.

Note

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

__contains__(instrument)

Returns True if a pyalgotrade.dataseries.bards.BarDataSeries for the given instrument is available.

__getitem__(instrument)

Returns the pyalgotrade.dataseries.bards.BarDataSeries for a given instrument. If the instrument is not found an exception is raised.

getCurrentBars()

Returns the current pyalgotrade.bar.Bars.

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.
getDefaultInstrument()

Returns the default instrument.

getLastBar(instrument)

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

getNextBars()

Returns the next pyalgotrade.bar.Bars in the feed or None if there are no bars.

getRegisteredInstruments()

Returns a list of registered intstrument names.

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

Bases: pyalgotrade.barfeed.membf.Feed

A CSV file based pyalgotrade.barfeed.BarFeed.

Note

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

getDailyBarTime()

Returns the time to set to daily bars when that information is not present in CSV files. Defaults to 23:59:59.

Return type:datetime.time.
setDailyBarTime(time)

Sets the time to set to daily bars when that information is not present in CSV files.

Parameters:time (datetime.time.) – The time to set.
class pyalgotrade.barfeed.csvfeed.GenericBarFeed(frequency, timezone=None, maxLen=1024)

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 00:59:59,13.51001,13.56,13.51,13.56,273.88014126,13.51001
Parameters:
  • frequency – The frequency of the bars.
  • 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. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.

Note

  • It is ok if the Adj Close column is empty.
  • Valid frequency parameter values are:
  • pyalgotrade.barfeed.Frequency.MINUTE
  • pyalgotrade.barfeed.Frequency.HOUR
  • pyalgotrade.barfeed.Frequency.DAY
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.

Yahoo! Finance

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

Bases: pyalgotrade.barfeed.csvfeed.BarFeed

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

Parameters:
  • 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. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.

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 from 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.

Ninja Trader

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

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.
  • 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. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.

Note

Valid frequency parameter values are:

  • pyalgotrade.barfeed.Frequency.MINUTE
  • pyalgotrade.barfeed.Frequency.DAY
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

dataseries – Basic dataseries classes

Next topic

technical – Technical indicators

This Page