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: |
|
---|
Note
This is a base class and should not be used directly.
This method has to be overriden to add the filtering logic and return a new value.
Parameters: |
|
---|
Returns the pyalgotrade.dataseries.DataSeries being filtered.
Returns the window size.
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
Simple Moving Average filter.
Parameters: |
|
---|
Exponential Moving Average filter.
Parameters: |
|
---|
Weighted Moving Average filter.
Parameters: |
|
---|
Relative Strength Index filter as described in http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:relative_strength_index_rsi.
Parameters: |
|
---|
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: |
|
---|
Returns a pyalgotrade.dataseries.DataSeries with the %D values.
Rate of change filter as described in http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:rate_of_change.
Parameters: |
|
---|
The Slope filter calculates the slope of the least-squares regression line.
Parameters: |
|
---|
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: |
|
---|
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: |
|
---|