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).


In reply to Re: Recursive method to check overlap of many date ranges by Perlbotics
in thread Recursive method to check overlap of many date ranges by bigbot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.