A faster way of finding historical highs/lows

Peter Hansen peter at engcorp.com
Fri Jun 11 08:09:40 EDT 2004


Eamonn Sullivan wrote:

> 1. Find the most recent date when there was an equal or higher (or
> lower) value than X. 

The fastest algorithm might depend on how you use the data, as well.
For example, do you update the data often, and search it rarely,
or update it rarely and do the search very often?  If searching
many times between updates, some preprocessing will likely make things
go much faster.

Both of your examples sound to me like they would benefit by
using sort(), then a binary search.  Sort is very fast relative
to things like the Python loops you are doing, so using it to
prepare the data before the search can be a good step.

-Peter



More information about the Python-list mailing list