[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shaving microseconds (avoiding N * logN behavior)



PureBytes Links

Trading Reference Links

Risking using a lot of memmory, assuming you are using
TS, and most importantly assuming N is constant (will
not change throughout a 'run' of the study, like an
input for TS). You can have an array that stores in
every bar the sorted N last Open values. 
Then all your process is O(n) where m is the number of
data points studied.
In other words, save the results of the previos bars
in an array for reference, and only calculate (sort)
the current bar's values. So your process each bar
will be Sort N values, and reference M numbers.

H

--- Andy <ronin@xxxxxxxxxxx> wrote:
> 
> : I've got a system that does an EXPENSIVE
> calculation
> : and right now I'm using an algorithm with O(N *
> logN)
> : asymptotic behavior.  I hope somebody can offer a
> : suggestion on how to reduce this to O(N), or
> better
> : yet, O(logN).
> : 
> : Problem: for each day in the dataset, look back at
> :          the N most recent trading days and return
> the
> :          K'th largest Open price among those N
> bars.
> 
> 
> How about a simple binary search with 3 way
> comparision? That's O(log N). 
> 
>