dataseries – Basic dataseries classes

class pyalgotrade.dataseries.DataSeries

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.

getFirstValidPos()

Returns the first valid position in the dataseries.

getLength()

Returns the number of values in the data series.

getValue(valuesAgo=0)

Returns the value at a given instant, relative to the last value, or None if the value doesn’t exist.

Parameters:valuesAgo (int) – The position of the value relative to the last one. Must be >= 0.
  • getValue() returns the last value.
  • getValue(1) returns the previous value (assuming that the dataseries has at least 2 values).
getValueAbsolute(pos)

Returns the value at a given instant, or None if the value doesn’t exist.

Parameters:pos – The absolute position of the value in the dataseries. Must be >= 0.
  • getValueAbsolute(0) returns the first value.
  • getValueAbsolute(1) returns the second value.
class pyalgotrade.dataseries.SequenceDataSeries(values=None)

A sequence based DataSeries.

Parameters:values (list.) – The values that this DataSeries will hold. If its None, an empty list is used. Note that the list is not cloned and it takes ownership of it.
appendValue(value)

Appends a value.

class pyalgotrade.dataseries.BarDataSeries

A DataSeries of pyalgotrade.bar.Bar instances.

getAdjCloseDataSeries()

Returns a DataSeries with the adjusted close prices.

getCloseDataSeries()

Returns a DataSeries with the close prices.

getHighDataSeries()

Returns a DataSeries with the high prices.

getLowDataSeries()

Returns a DataSeries with the low prices.

getOpenDataSeries()

Returns a DataSeries with the open prices.

getVolumeDataSeries()

Returns a DataSeries with the volume.

Example

from pyalgotrade import dataseries

# Build a sequence based DataSeries.
ds = dataseries.SequenceDataSeries(range(0, 50))

# Get the last value.
print ds.getValue()
print ds.getValueAbsolute(49)

# Get the previous value.
print ds.getValue(1)
print ds.getValueAbsolute(48)

# Get the first value.
print ds.getValue(49)
print ds.getValueAbsolute(0)

The output should be:

49
49
48
48
0
0

Table Of Contents

Previous topic

bar – Instrument prices

Next topic

barfeed – Bar providers

This Page