admin管理员组文章数量:1289858
I have a streaming table of ticks and I want to segment K-lines based on volume, for example, creating a new bar for every 10,000 shares traded, and calculating the OHLC values.
How can I implement a function similar to volumeBar on streaming data?
it might be handled with the built-in time-series engine, but I've read the official description of the parameters for the time-series engine documentation(:.html?hl=time-series%2Cstream%2Cengine), but I can't find a use case for it.
I have a streaming table of ticks and I want to segment K-lines based on volume, for example, creating a new bar for every 10,000 shares traded, and calculating the OHLC values.
How can I implement a function similar to volumeBar on streaming data?
it might be handled with the built-in time-series engine, but I've read the official description of the parameters for the time-series engine documentation(:https://docs.dolphindb/en/Tutorials/stream_aggregator.html?hl=time-series%2Cstream%2Cengine), but I can't find a use case for it.
Share Improve this question asked Feb 21 at 7:06 bigmacsetnotenoughbigmacsetnotenough 1141 silver badge7 bronze badges1 Answer
Reset to default 0Since the time-series aggregation engine can only calculate fixed-length sliding windows, and the state engine currently does not directly support the volumeBar function as a state function for calculation.
For now, we can only implement the logic ourselves using a class, with a reference script as follows:
// Function: Group by stock ID, segment windows based on the cumulative volume, and calculate the average price of each window entry by entry.
// Input data
securityID = `st001`st002`st001`st002`st001`st002
time = 2022.01.01 2022.01.01 2022.01.02 2022.01.02 2022.01.03 2022.01.03
price = 30.15 30.21 30.09 30.13 30.18 30.16
volume = 190 212 198 211 205 199
t = table(securityID, time, price, volume)
class MyVolumeBarFilter{
totalVol :: LONG
interval :: LONG
def MyVolumeBarFilter(interval_) {
groupNum = 0
totalVol = 0
interval = interval_
}
def append(volume) {
if (totalVol > interval) {
totalVol = 0
}
totalVol += volume
return totalVol>interval
}
}
class MyVolumeBar{
groupNum :: LONG
totalVol :: LONG
sumPrice :: DOUBLE
count :: LONG
interval :: LONG
def MyVolumeBar(interval_) {
totalVol = 0
sumPrice = 0.0
count = 0
interval = interval_
}
def append(volume, price) {
if (totalVol > interval) {
totalVol = 0
sumPrice = 0.0
count = 0
}
totalVol += volume
sumPrice += price
count += 1
avgPrice = sumPrice\count
return avgPrice
}
}
result = table(1:0, `securityID`time`price`volume`avgPrice, [SYMBOL, DATE, DOUBLE, LONG, DOUBLE])
try { dropStreamEngine(`demo) } catch(ex) {}
rse = createReactiveStateEngine(name="demo", metrics =<[time, price, volume, MyVolumeBar(400).append(volume, price) as `avgPrice]>, dummyTable=t, outputTable=result, keyColumn="securityID", filter=<MyVolumeBarFilter(400).append(volume)>)
rse.append!(t)
本文标签: time seriesHow to implement volumeBar Kline in stream computingStack Overflow
版权声明:本文标题:time series - How to implement volumeBar K-line in stream computing? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741401565a2376697.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论