technical – Technical indicators

class pyalgotrade.technical.DataSeriesFilter(dataSeries, windowSize, cacheSize=512)

A DataSeriesFilter is a pyalgotrade.dataseries.DataSeries instance that decorates another pyalgotrade.dataseries.DataSeries instance to make some calculations with the values from the DataSeries being decorated.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • windowSize (int.) – The amount of values to use from the filtered DataSeries to calculate our own values. Must be > 0.
  • cacheSize (int.) – The values that this filter calculates will be cached so they don’t have to be calculated twice. This parameter controls how many results will be kept in the cache.

Note

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

calculateValue(firstPos, lastPos)

This method has to be overriden to add the filtering logic and return a new value.

Parameters:
  • firstPos (int.) – Absolute position for the first value to use from the DataSeries being filtered.
  • lastPos (int.) – Absolute position for the last value to use from the DataSeries being filtered.
getDataSeries()

Returns the pyalgotrade.dataseries.DataSeries being filtered.

getWindowSize()

Returns the window size.

Example

Creating a custom filter is easy:

from pyalgotrade import dataseries
from pyalgotrade import technical

class Accumulator(technical.DataSeriesFilter):
    def __init__(self, dataSeries, windowSize):
        technical.DataSeriesFilter.__init__(self, dataSeries, windowSize)

    def calculateValue(self, firstPos, lastPos):
        accum = 0
        for i in range(firstPos, lastPos + 1):
            value = self.getDataSeries().getValueAbsolute(i)
            # If any value from the wrapped DataSeries is None then we abort calculation and return None.
            if value is None:
                return None
            accum += value
        return accum

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

# Wrap it with a 3 element Accumulator filter.
ds = Accumulator(ds, 3)

# Get some values.
print ds.getValueAbsolute(0) # Not enough values yet.
print ds.getValueAbsolute(1) # Not enough values yet.
print ds.getValueAbsolute(2) # Ok, now we should have at least 3 values.
print ds.getValueAbsolute(3)

# Get the last value, which should equals 49 + 48 + 47.
print ds.getValue()

The output should be:

None
None
3
6
144

Moving Averages

class pyalgotrade.technical.ma.SMA(dataSeries, period)

Simple Moving Average filter.

Parameters:
class pyalgotrade.technical.ma.EMA(dataSeries, period)

Exponential Moving Average filter.

Parameters:
class pyalgotrade.technical.ma.WMA(dataSeries, weights)

Weighted Moving Average filter.

Parameters:

Momentum Indicators

class pyalgotrade.technical.rsi.RSI(dataSeries, period)

Relative Strength Index filter.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • period (int.) – The period. Note that if period is n, then n+1 values are used.

Other Indicators

class pyalgotrade.technical.trend.Slope(dataSeries, period)

The Slope filter calculates the slope of the least-squares regression line.

Parameters:

Table Of Contents

Previous topic

barfeed – Bar providers

Next topic

strategy – Basic strategy classes

This Page