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 value in self.getDataSeries()[firstPos:lastPos+1]:
            # 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[0] # Not enough values yet.
print ds[1] # Not enough values yet.
print ds[2] # Ok, now we should have at least 3 values.
print ds[3]

# Get the last value, which should equals 49 + 48 + 47.
print ds[-1]

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:
class pyalgotrade.technical.vwap.VWAP(dataSeries, period, useTypicalPrice=False)

Volume Weighted Average Price filter.

Parameters:
  • dataSeries (pyalgotrade.dataseries.BarDataSeries.) – The DataSeries instance being filtered.
  • period (int.) – The number of values to use to calculate the VWAP.
  • useTypicalPrice (boolean.) – True if the typical price should be used instead of the closing price.

Momentum Indicators

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

Relative Strength Index filter as described in http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:relative_strength_index_rsi.

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. Must be > 1.
class pyalgotrade.technical.stoch.StochasticOscillator(barDataSeries, period, dSMAPeriod=3, useAdjustedValues=False)

Stochastic Oscillator filter as described in http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:stochastic_oscillato. Note that the value returned by this filter is %K. To access %D use getD().

Parameters:
  • barDataSeries (pyalgotrade.dataseries.BarDataSeries.) – The BarDataSeries instance being filtered.
  • period (int.) – The period. Must be > 1.
  • dSMAPeriod (int.) – The %D SMA period. Must be > 1.
  • useAdjustedValues (boolean.) – True to use adjusted Low/High/Close values.
getD()

Returns a pyalgotrade.dataseries.DataSeries with the %D values.

class pyalgotrade.technical.roc.RateOfChange(dataSeries, valuesAgo)

Rate of change filter as described in http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:rate_of_change.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • valuesAgo (int.) – The number of values back that a given value will compare to. Must be > 0.

Other Indicators

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

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

Parameters:
class pyalgotrade.technical.cross.CrossAbove(ds1, ds2, period=2)

Checks for a cross above conditions over the specified period between two DataSeries objects.

It returns the number of times ds1 crossed above ds2 during the given period.

Parameters:
class pyalgotrade.technical.cross.CrossBelow(ds1, ds2, period=2)

Checks for a cross below conditions over the specified period between two DataSeries objects.

It returns the number of times ds1 crossed below ds2 during the given period.

Parameters:
class pyalgotrade.technical.linebreak.Line(low, high, dateTime, white)

A line in a line break chart.

getDateTime()

The datetime.

getHigh()

The high value.

getLow()

The low value.

isBlack()

True if the line is black (falling prices).

isWhite()

True if the line is white (rising prices).

class pyalgotrade.technical.linebreak.LineBreak(barDataSeries, reversalLines, useAdjustedValues=False)

Line Break filter as described in http://stockcharts.com/help/doku.php?id=chart_school:chart_analysis:three_line_break . This is a DataSeries of Line instances.

Parameters:
  • barDataSeries (pyalgotrade.dataseries.BarDataSeries.) – The DataSeries instance being filtered.
  • reversalLines (int.) – The number of lines back to check to calculate a reversal. Must be greater than 1.
  • useAdjustedValues (boolean.) – True to use adjusted high/low/close values.

Table Of Contents

Previous topic

barfeed – Bar providers

Next topic

broker – Order management classes

This Page