ESPER: Find Max and Min of 24 hours and check if price goes above the Max of previous 24 hours value

StackOverflow https://stackoverflow.com/questions/18954306

  •  29-06-2022
  •  | 
  •  

Question

I am unable to solve an Esper problem. I have to calculate Max and Min of 24 hours and then i have to check if tick price goes above this value ( This has to be done on multiple securities .) Here is the code which i am using. But i am betting alot of performance hit and getting an event fired more than once.

create context
GroupSecurity
partition by 
security
from 
Tick;

context
GroupSecurity
select
currentData.last, max(groupedData.last)
from
Tick as currentData unidirectional, Tick.win:time_batch(24 hour) as groupedData
having
currentData.last > max(groupedData.last);

How can i Improve this code?

Was it helpful?

Solution

The "Tick.win:time_batch(24 hour)" tells the engine to retain in memory all 24 hours of Tick events that may arrive, and only spit these out after 24 hours. I think a better approach would be to have the engine compute say 1-minute maximums and take the 1-minute maximums for 24 hours and take the max of that, i.e. retain and build a max from no more then 24*60 rows where each row keeps a 1-minute max.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top