[Numpy-discussion] trailing max
Tue Oct 30 17:51:53 CDT 2007
Pierre GM <pgmdevlist <at> gmail.com> writes:
> On Tuesday 30 October 2007 13:31:41 John Hunter wrote:
> > In financial time series, it is very common to keep track of things
> > like a trailing N day max, trailing N day average, etc.
> Have you ever tried the timeseries package in the scipy SVN ? We (Matt Knox
> and I) tried to address some of these issues for environmental and financial
> time series.
I have just added a trailing max and trailing min function to the timeseries
package to go along with the already existing trailing median function. These
functions are implemented in C and attempt to be memory and computationally
efficient, and should be much quicker than creating a 2D array as described in
another post. Here is some example code...
>>> from timeseries.lib.moving_funcs import mov_max, mov_median, mov_min
>>> import numpy as np
>>> a = np.arange(10)
>>> print mov_max(a, 4)
[-- -- -- 3 4 5 6 7 8 9]
>>> print mov_median(a, 4)
[-- -- -- 1.5 2.5 3.5 4.5 5.5 6.5 7.5]
>>> print mov_min(a, 4)
[-- -- -- 0 1 2 3 4 5 6]
Note that the function returns a MaskedArray from the maskedarray package
(currently in the sandbox), and maskedarray is a requirement for the
timeseries package. You can pass TimeSeries objects, regular ndarray's, or
MaskedArray's to these functions.
If you decide to give the timeseries package a shot, I'm happy to help with
any questions/concerns you may have.
More information about the Numpy-discussion