0
votes

I have a table with price and volume information. For each stock and at each timestamp, I would like to calculate the sum of volume only for those rows in the last 60 rows with price>current price. It is like the msum function in dolphindb with a conditional filter. I tried to use the moving template function in dolphindb but still couldn't come up with a solution. Is there a way to do it in dolphindb?

1

1 Answers

0
votes

This example should help. It uses the higher order function moving in dolphindb. It is not as fast as the moving window functions such as msum but can get the job done.

t=table(09:30:00 + (0..59)*60 as time, (1..20) join (20..1) join (1..20) as x, rand(10.0, 60) as y)

f = def(x,y){return sum(y[x>x.tail()])}
select time, x, y, moving(f, [x, y], 10) from t