My current dilemma involves an Observable
that continuously generates a rapid sequence of positive-integer values.
I am seeking a way to transform this sequence into value-change percentages, particularly when those values exceed a certain threshold within a specified time interval (in milliseconds).
Snippet:
function getPressurePercents(input: Observable, minChange: number, iw: number) {
// Create an observable that emits value-change percentages outside
// the designated minimum change percentage during each interval window
}
const obs = getPressurePercents(input, 0.5, 3000).subscribe(val => {
// Notify when input values have changed by at least 0.5% in the last 3 seconds
// The emitted value represents the percent change, where Math.abs(value) >= 0.5
// Positive values indicate percent increases, while negative values signify decreases
});
In the scenario outlined above, I aim to receive an observable that notifies me of any value-change percentages exceeding 0.5% within a 3-second timeframe.
The objective is to identify sudden spikes in value changes and react to all percentages outside the defined threshold, such as abrupt fluctuations in equity prices (price spikes).
CRUCIAL NOTE: The solution should account for both upward and downward changes, meaning a decrease in percentage within the window should emit a corresponding negative percent value.
RESOLUTION
After exploring various options, I devised my own solution that operates independently from the RXJS pipeline but can be seamlessly integrated into it. This approach is more straightforward and compact compared to previously suggested pure RXJS methods. Check out my answer below for details.