79540356

Date: 2025-03-28 01:43:13
Score: 1
Natty:
Report link

Use the interval function to slide the window according to the duration, and you can choose a handling scheme for encountering null values. In this case, we select the previous valid K-line to replace the missing K-line. Code demonstration.


n = 1000000
date = take(2019.11.07 2019.11.08, n)
time = (09:30:00.000 + rand(2*60*60*1000, n/2)).sort!() join (13:00:00.000 + rand(2*60*60*1000, n/2)).sort!()
timestamp = concatDateTime(date, time)
price = 100+cumsum(rand(0.02, n)-0.01)
volume = rand(1000, n)
symbol = rand(`600519`000001`600000`601766, n)
trade = table(symbol,date, time, timestamp, price, volume).sortBy!(`symbol`timestamp)
SQL:
select 
    first(price) as open, 
    max(price) as high, 
    min(price) as low, 
    last(price) as close, 
    sum(volume) as volume 
from trade 
group by symbol, date, interval(time,5m, 'prev')

the output is :

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: smile qian