How to calculate the following in real time with every tick

I want to calculate value of mavg with every tick. I have OHLCV data which updates in real time with every tick. Please help me.

I have saved it in this file  x.zip 

Now I want to calculate mavg(om5,3),mavg(hm5,3),mavg(lm5,3),mavg(cm5,3),mavg(vm5,3).

If I calculate directly on tick data (in x.zip) It wont get the desired results.

I want output as under. Here you can see at ts=2022.01.15T16:06:01.139  mavg of 3 places for the column vm5 is (72.9278+36.4143+5.7554) / 3 = 38.3659

y=select * from x limit 26705

select symbol,ts,ts_m5,om5,hm5,lm5,cm5,vm5,mavg(om5,3),mavg(hm5,3),mavg(lm5,3),mavg(cm5,3),mavg(vm5,3 ) from y where isDuplicated([ts_m5,symbol],LAST)==false

And it updates at ts= 2022.01.15T16:06:01.648 to (72.9278+36.4143+5.7559) / 3 = 38.366

select symbol,ts,ts_m5,om5,hm5,lm5,cm5,vm5,mavg(om5,3),mavg(hm5,3),mavg(lm5,3),mavg(cm5,3),mavg(vm5,3 ) from x where isDuplicated([ts_m5,symbol],LAST)==false

attachments-2022-01-iyMg4LZt61e2a7b217d7e.png

I have tried many thing like using tmavg for 15min but it did not work. The results are very different. As shown under.

attachments-2022-01-PV60pjau61e2ad1a3ebc3.png

attachments-2022-01-PV60pjau61e2ad1a3ebc3.pngplease refer https://ask.dolphindb.net/question/1140 for updates and / or solutions

请先 登录 后评论

1 个回答

Jason Tang - 时序数据库技术支持
time = (0..9)*1000*60*5 + now()
symbol = take("00001", 10)
open = take(1..11, 10)
t = table(time, symbol, open)

result = table(1:0, `symbol`time`mavgOpen, [SYMBOL, TIMESTAMP, DOUBLE])

createReactiveStateEngine(name="reactiveDemo", metrics =[<time>, <mavg(open, 3)>], dummyTable=t, outputTable=result, keyColumn="symbol")

getStreamEngine(`reactiveDemo).append!(t)

the result Table is:

attachments-2022-01-miGQdSyW61e4cf1faeb38.png

请先 登录 后评论
  • 1 关注
  • 0 收藏,900 浏览
  • Vishvesh Upadhyay 提出于 2022-01-15 19:17

相似问题