dataseries – Basic dataseries classes

Data series are abstractions used to manage time-series data.

class pyalgotrade.dataseries.DataSeries

Bases: object

Base class for data series.

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.

getDateTimes()

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

class pyalgotrade.dataseries.SequenceDataSeries(maxLen=None)

Bases: pyalgotrade.dataseries.DataSeries

A DataSeries that holds values in a sequence in memory.

Parameters:maxLen (int.) – The maximum number of values to hold. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used.
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=None)

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. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used.
class pyalgotrade.dataseries.bards.BarDataSeries(maxLen=None)

Bases: pyalgotrade.dataseries.SequenceDataSeries

A DataSeries of pyalgotrade.bar.Bar instances.

Parameters:maxLen (int.) – The maximum number of values to hold. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. If None then dataseries.DEFAULT_MAX_LEN is used.
getAdjCloseDataSeries()

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

getCloseDataSeries()

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

getExtraDataSeries(name)

Returns a pyalgotrade.dataseries.DataSeries for an extra column.

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.

getPriceDataSeries()

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

getVolumeDataSeries()

Returns a pyalgotrade.dataseries.DataSeries with the volume.

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

Bases: pyalgotrade.dataseries.bards.BarDataSeries, pyalgotrade.dataseries.resampled.DSResampler

A BarDataSeries that will build on top of another, higher frequency, BarDataSeries. Resampling will take place as new values get pushed into the dataseries being resampled.

Parameters:
  • dataSeries (pyalgotrade.dataseries.bards.BarDataSeries) – The DataSeries instance being resampled.
  • frequency – The grouping frequency in seconds. Must be > 0.
  • maxLen (int.) – The maximum number of values to hold. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.

Note

  • Supported resampling frequencies are:
    • Less than bar.Frequency.DAY
    • bar.Frequency.DAY
    • bar.Frequency.MONTH
checkNow(dateTime)

Forces a resample check. Depending on the resample frequency, and the current datetime, a new value may be generated.

Parameters:dateTime (datetime.datetime) – The current datetime.

Previous topic

bar – Instrument prices

Next topic

feed – Basic feeds

This Page