dataseries – Basic dataseries classes

class pyalgotrade.dataseries.DataSeries

Bases: object

Base class for data series. A data series is an abstraction used to manage historical data.

Note

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

__getitem__(key)

Returns the value at a given position/slice. It raises IndexError if the position is invalid, or TypeError if the key type is invalid.

__len__()

Returns the number of elements in the data series.

__weakref__

list of weak references to the object (if defined)

getDateTimes()

Returns a list of datetime.datetime associated with each value.

class pyalgotrade.dataseries.SequenceDataSeries(maxLen=1024)

Bases: pyalgotrade.dataseries.DataSeries

A DataSeries that holds values in a sequence in memory.

Parameters:maxLen (int.) – The maximum number of values to 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.
append(value)

Appends a value.

appendWithDateTime(dateTime, value)

Appends a value with an associated datetime.

Note

If dateTime is not None, it must be greater than the last one.

getMaxLen()

Returns the maximum number of values to hold.

setMaxLen(maxLen)

Sets the maximum number of values to hold and resizes accordingly if necessary.

pyalgotrade.dataseries.aligned.datetime_aligned(ds1, ds2, maxLen=1024)

Returns two dataseries that exhibit only those values whose datetimes are in both dataseries.

Parameters:
  • ds1 (DataSeries.) – A DataSeries instance.
  • ds2 (DataSeries.) – A DataSeries instance.
  • maxLen (int.) – The maximum number of values to hold for the returned DataSeries. 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.
class pyalgotrade.dataseries.bards.BarDataSeries(maxLen=1024)

Bases: pyalgotrade.dataseries.SequenceDataSeries

A pyalgotrade.dataseries.DataSeries of pyalgotrade.bar.Bar instances.

Parameters:maxLen (int.) – The maximum number of values to 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.
getAdjCloseDataSeries()

Returns a pyalgotrade.dataseries.DataSeries with the adjusted close prices.

getCloseDataSeries()

Returns a pyalgotrade.dataseries.DataSeries with the close prices.

getHighDataSeries()

Returns a pyalgotrade.dataseries.DataSeries with the high prices.

getLowDataSeries()

Returns a pyalgotrade.dataseries.DataSeries with the low prices.

getOpenDataSeries()

Returns a pyalgotrade.dataseries.DataSeries with the open prices.

getVolumeDataSeries()

Returns a pyalgotrade.dataseries.DataSeries with the volume.

class pyalgotrade.dataseries.resampled.ResampledBarDataSeries(dataSeries, frequency, maxLen=1024)

Bases: pyalgotrade.dataseries.bards.BarDataSeries

A pyalgotrade.dataseries.bards.BarDataSeries that will build on top of another higher frequency pyalgotrade.dataseries.bards.BarDataSeries.

Parameters:
  • dataSeries (pyalgotrade.dataseries.bards.BarDataSeries.) – The DataSeries instance being resampled.
  • frequency – The grouping frequency.
  • maxLen (int.) – The maximum number of values to 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.HOUR
  • pyalgotrade.barfeed.Frequency.DAY

Example

from pyalgotrade import dataseries

# Build a sequence based DataSeries and put in some values.
ds = dataseries.SequenceDataSeries()
for i in range(0, 50):
	ds.append(i)

# Get the last value.
print ds[49]
print ds[-1]

# Get the previous value.
print ds[48]
print ds[-2]

# Get the first value.
print ds[0]
print ds[-50]

# Get the last 3 values.
print ds[-3:]

The output should be:

49
49
48
48
0
0
[47, 48, 49]

Table Of Contents

Previous topic

bar – Instrument prices

Next topic

barfeed – Bar providers

This Page