I am using Pyalgotrade (usually in combination with ta-lib indicators), but I am missing a function to find a local maxima and minima in the data series.
I am aware of the min and max functions, but this is not what I am looking for. E. g. MIN(low, count=5) would give me the lowest of 5 bars, but this does not look outside the 5 values. I am looking for a function returning the value of a "local low" over a certain period, i. e. the value was lower then two days before and after that day.
Example
Series [2,3,2,1,3,4,5,6,6]
MIN(5) -> returns 3, but the lowest value is on the left border of the observed window
and the day before, the value was even lower!
whatiamlookingfor() -> should return 1,
because it is the last local low over a +/-2 days period
I hope it's clear what I mean. Is ther any function for this purpose that I might have overlooked.
EDIT
To find a low in a data series, I came up with something like this ...
def min_peak(series, interval):
reference = -1
left = reference - interval
while -reference < len(series):
if min(series[left:]) == min(series[reference:]):
return min(series[left:])
reference -= 1
left -= 1
... but I am not very happy with this solution, because I think it's not very efficient to parse the series backwards. I assume something built-in running natively would probably be way faster.
Kind Regards,
Ale