technical – Technical indicators

class pyalgotrade.technical.EventWindow(windowSize, skipNone=True)

An EventWindow class is responsible for making calculation over a moving window of values.

Parameters:
  • windowSize (int.) – The size of the window. Must be greater than 0.
  • skipNone (boolean.) – True if None values should not be included in the window.

Note

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

getValue()

Override to calculate a value using the values in the window.

getValues()

Returns the values in the window.

getWindowSize()

Returns the window size.

class pyalgotrade.technical.EventBasedFilter(dataSeries, eventWindow, maxLen=1024)

Bases: pyalgotrade.dataseries.SequenceDataSeries

An EventBasedFilter class is responsible for capturing new values in a pyalgotrade.dataseries.DataSeries and using an EventWindow to calculate new values.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • eventWindow (EventWindow.) – The EventWindow instance to use to calculate new values.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
getDataSeries()

Returns the pyalgotrade.dataseries.DataSeries being filtered.

getEventWindow()

Returns the EventWindow instance to use to calculate new values.

Example

The following example shows how to combine an EventWindow and an EventBasedFilter to build a custom filter:

from pyalgotrade import dataseries
from pyalgotrade import technical

# An EventWindow is responsible for making calculations using a window of values.
class Accumulator(technical.EventWindow):
	def getValue(self):
		ret = 0
		for value in self.getValues():
			if value != None:
				ret += value
		return ret

# Build a sequence based DataSeries.
seqDS = dataseries.SequenceDataSeries()
# Wrap it with a filter that will get fed as new values get added to the underlying DataSeries.
accum = technical.EventBasedFilter(seqDS, Accumulator(3))

# Put in some values.
for i in range(0, 50):
	seqDS.append(i)

# Get some values.
print accum[0] # Not enough values yet.
print accum[1] # Not enough values yet.
print accum[2] # Ok, now we should have at least 3 values.
print accum[3]

# Get the last value, which should be equal to 49 + 48 + 47.
print accum[-1]

The output should be:

0
1
3
6
144

Moving Averages

class pyalgotrade.technical.ma.SMA(dataSeries, period, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

Simple Moving Average filter.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • period (int.) – The number of values to use to calculate the SMA.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
class pyalgotrade.technical.ma.EMA(dataSeries, period, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

Exponential Moving Average filter.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • period (int.) – The number of values to use to calculate the EMA. Must be an integer greater than 1.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
class pyalgotrade.technical.ma.WMA(dataSeries, weights, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

Weighted Moving Average filter.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • weights (list.) – A list of int/float with the weights.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
class pyalgotrade.technical.vwap.VWAP(dataSeries, period, useTypicalPrice=False, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

Volume Weighted Average Price filter.

Parameters:
  • dataSeries (pyalgotrade.dataseries.bards.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.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.

Momentum Indicators

class pyalgotrade.technical.rsi.RSI(dataSeries, period, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

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.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
class pyalgotrade.technical.stoch.StochasticOscillator(barDataSeries, period, dSMAPeriod=3, useAdjustedValues=False, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

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.bards.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.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
getD()

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

class pyalgotrade.technical.roc.RateOfChange(dataSeries, valuesAgo, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

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.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.

Other Indicators

class pyalgotrade.technical.trend.Slope(dataSeries, period, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

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

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • period (int.) – The number of values to use to calculate the slope.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
class pyalgotrade.technical.highlow.High(dataSeries, period, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

This filter calculates the highest value.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • period (int.) – The number of values to use to calculate the highest value.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
class pyalgotrade.technical.highlow.Low(dataSeries, period, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

This filter calculates the lowest value.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • period (int.) – The number of values to use to calculate the lowest value.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
pyalgotrade.technical.cross.cross_above(values1, values2, start=-2, end=None)

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

It returns the number of times values1 crossed above values2 during the given period.

Parameters:

Note

The default start and end values check for cross above conditions over the last 2 values.

pyalgotrade.technical.cross.cross_below(values1, values2, start=-2, end=None)

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

It returns the number of times values1 crossed below values2 during the given period.

Parameters:

Note

The default start and end values check for cross below conditions over the last 2 values.

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, maxLen=1024)

Bases: pyalgotrade.dataseries.SequenceDataSeries

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.bards.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.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end. This value can’t be smaller than reversalLines.
class pyalgotrade.technical.stats.StdDev(dataSeries, period, ddof=0, maxLen=1024)

Bases: pyalgotrade.technical.EventBasedFilter

Standard deviation filter.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • period (int.) – The number of values to use to calculate the Standard deviation.
  • ddof (int.) – Delta degrees of freedom.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
class pyalgotrade.technical.bollinger.BollingerBands(dataSeries, period, numStdDev, maxLen=1024)

Bollinger Bands filter as described in http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:bollinger_bands.

Parameters:
  • dataSeries (pyalgotrade.dataseries.DataSeries.) – The DataSeries instance being filtered.
  • period (int.) – The number of values to use in the calculation. Must be > 1.
  • numStdDev (int.) – The number of standard deviations to use for the upper and lower bands.
  • maxLen (int.) – The maximum number of values to hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.
getLowerBand()

Returns the lower band as a pyalgotrade.dataseries.DataSeries.

getMiddleBand()

Returns the middle band as a pyalgotrade.dataseries.DataSeries.

getUpperBand()

Returns the upper band as a pyalgotrade.dataseries.DataSeries.

Table Of Contents

Previous topic

barfeed – Bar providers

Next topic

broker – Order management classes

This Page