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.

__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)

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[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