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:
- Find start time (time_start) of first trade.
- Find end time (time_end) of last trade.
- Define a suitable sample interval (interval, e.g 15s).
- From time_start to time_end in increments of interval do
- Count the number of open trades at sample point: count[n x interval]
- Generate mean value from sampled list (maybe ignore samples with zero count).
- Alternatively: Use a sliding window and reduce further.
- Potential refinement: Ignore some of the first and last samples (transients).
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:
- Trade#1: open=10:10/close=11:15/duration=01:05;
- Trade#2: open=10:12/close=10:18/duration=00:06;
- Trade#3: open=10:15/close=10:26/duration=00:11;
=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).
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.