Numerical Python question

Neil Hodgson nhodgson at bigpond.net.au
Sun Oct 12 07:36:18 EDT 2003


2mc:

> Assume an array in Numerical Python, the contents of which are the
> daily open, high, low, and last prices of the DOW Jones Industrial
> Average for its entire history.  How would one iterate throughout the
> entire array calculating the 10 day average of daily high price or the
> daily low price?

   The common technique for moving averages is to maintain a single
accumulator value over the last n points. For each new point, remove (by
subtracting) the value at the beginning of the window and add in the value
at the end of the window. The value of the accumulator divided by n is the
moving average. You will need to define what you want as output, if any,
before the nth point.

   Neil






More information about the Python-list mailing list