Real-time ranking and percentile calculation on streaming data in DolphinDB
06:04 06 Nov 2025

I'm using DolphinDB's stream processing engine to handle a real-time data feed of financial metrics. My requirement is to maintain the latest f1 value for each unique symbol (sym). Every time a new record arrives (which could be an update to an existing symbol or a new symbol), I need to immediately compute:

  1. The absolute rank of the current symbol's f1 among the latest f1 values of all symbols.

  2. The percentile rank of that f1 value.

Here is an example of the input stream:

sym f1 datetime               
--- -- -----------------------
A   10 2022.01.04T09:00:00.000
A   12 2022.01.04T09:00:00.020
B   9  2022.01.04T09:00:00.120
C   12 2022.01.04T09:00:00.220
B   10 2022.01.04T09:00:00.320

For instance, after the last record (B updated to 10), the latest state is A:12, B:10, C:12. The expected output for symbol B would be:

  • abs_rank: 3 (since 10 is the lowest, assuming ascending rank where 1 is the highest)

  • percentile_rank: 0.0 (or calculated as (rank - 1) / (total_count - 1) = (3-1)/(3-1) = 1.0, depending on the formula. Please clarify the exact percentile calculation you need).

How to set up the stream engine to, on each update, recalculate ranks against the entire current state of all symbols?

I've looked at reactiveStateEngine but am stuck on accessing the full symbol state for a global ranking in the metrics function. A code example would be very helpful.

streaming real-time dolphindb