in reply to Recursive method to check overlap of many date ranges

I do not think that recursion is helpful here, though not impossible. First step seems to come up with a proper definition of average number of trades open at the same time (What time? How to deal with inactivity?).

Maybe you can just re-sample your data like so:

Update: Instead of the synchronous sampling method suggested above, count parallel trades asynchronously at open/close times (events) - including/excluding the opened/closed trade respectively. You might weight the count with its duration (relative to observation period) to get an average value. Here, duration of count might differ from duration of given trade since it is the time span between adjacent events.

Example:

=Asynchronous Method= =Sampling Method= Time Action Count Duration Weight Count 15s-Samples ----------------------------------------------- ------------------- 10:10 open#1 1 2 2/65 1 8 10:12 open#2 2 3 3/65 2 12 10:15 open#3 3 3 3/65 3 12 10:18 close#2 2 8 8/65 2 32 10:26 close#3 1 49 49/65 1 196 11:15 close#1 0 - - - - ----------------------------------------------- -------------------
Observation period: 10:10-11:15 = 65 (Minutes) = 260 15s-samples
Asynchronous Method: Weighted sum (count * weight) = 82/65; Events = 6; Duration = 65; Average = 82/65 = 1.26
Sampling Method: Sum = 328; Samples = 260; Duration = 260; Average = 328/260 = 1.26
(Pardon me for leaving out the units...)

Seems, the asynchronous method is more efficient (same result, lesser computations).

Replies are listed 'Best First'.
Re^2: Recursive method to check overlap of many date ranges
by bigbot (Beadle) on Sep 17, 2011 at 20:40 UTC

    Thanks for the responses. I should have been more specific regarding what I meant when I said the "average number of open trades".

    I do not care if there are no trades at all open. I also do not care about how long a trade is open. If two trades are open at the same time even for 1 minute I consider that two trades open at once. So I'm not exactly sure the best calculation to use.. Perlbotics your asynchronously at open/close times seems to be what I'm looking for. So far the testing shows that it's pretty accurate. Thanks! Let me know if you have any update considering the definition I presented for average number of open trades.