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)

getDateTimes()

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

class pyalgotrade.dataseries.SequenceDataSeries(values=None, dateTimes=None)

A sequence based DataSeries.

Parameters:
  • values (list.) – The values that this DataSeries will hold. If its None, an empty list is used.
  • dateTimes (list.) – A list of the datetime.datetime associated with each value. If this is not None, it has be the same length as values.

Note

Neither values nor dateTimes get cloned, and this class takes ownership of them.

appendValue(value)

Appends a value.

appendValueWithDatetime(dateTime, value)

Appends a value with an associated datetime.

Note

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

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.

pyalgotrade.dataseries.datetime_aligned(ds1, ds2)

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

Parameters:

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