createDailyTimeSeriesEngine doesnot align time according to sessionBegin

When using createDailyTimeSeriesEngine it does not align to session begin.

For example, if sessionBegin is 09:15:00 and windowSize is 30 min, first candle time starts from 09:15:00. But in createDailyTimeSeriesEngine time starts from 09:00:00 which is not correct.

In this example code given below, I created a DailyTimeSeriesEngine with 30 min windowSize and sessionBegin at 09:15:00 which outputs first candle at 09:00:00 which is not true.

But when using dailyAlignedBar(ts, 09:15:00, 60*30) it gives correct results.


I am using version 2.00.3 released on 22-11-2021


Please solve this problem as soon as possible.


code:-

share streamTable(1000:0, `ts`sym`volume, [DATETIME, SYMBOL, INT]) as trades
output1 = table(10000:0, `time`sym`sumVolume, [DATETIME, SYMBOL, INT])

agg1 = createDailyTimeSeriesEngine(name="agg1", windowSize=60*30, step=60*30, metrics=<[sum(volume)]>, dummyTable=trades, outputTable=output1, timeColumn=`ts, useSystemTime=false, keyColumn=`sym, garbageSize=50, useWindowStartTime=true, sessionBegin=09:15:00, sessionEnd=15:30:00, mergeSessionEnd=true)

subscribeTable(tableName="trades", actionName="agg1", offset=0, handler=append!{agg1}, msgAsTable=true);

insert into trades values(2018.10.08T09:15:02,`A,26)
insert into trades values(2018.10.08T09:30:02,`A,26)
insert into trades values(2018.10.08T09:30:10,`B,14)
insert into trades values(2018.10.08T11:29:46,`A,30)
insert into trades values(2018.10.08T11:29:50,`B,11)
insert into trades values(2018.10.08T11:30:00,`A,14)
insert into trades values(2018.10.08T11:30:00,`B,4)
insert into trades values(2018.10.08T13:00:10,`A,16)
insert into trades values(2018.10.08T13:00:12,`B,9)
insert into trades values(2018.10.08T14:59:56,`A,20)
insert into trades values(2018.10.08T14:59:58,`B,20)
insert into trades values(2018.10.08T15:00:00,`A,10)
insert into trades values(2018.10.08T15:00:00,`B,29)

select * from output1 //gives incorrect results as time wont align to sessionBegin 09:15:00

select sum(volume) from trades group by sym,dailyAlignedBar(ts, 09:15:00, 60*30) as k30 //gives correct results as time wont align to sessionBegin 09:15:00

Results from DailyTimeSeriesEngine: (As you can see time of first candle is 09:00:00 but it should be start at 09:15:00)

time 	               sym 	sumVolume
2018.10.08T09:00:00 	A 	26
2018.10.08T09:30:00 	A 	26
2018.10.08T09:30:00 	B 	14
2018.10.08T11:00:00 	A 	30
2018.10.08T11:00:00 	B 	11
2018.10.08T11:30:00 	A 	14
2018.10.08T11:30:00 	B 	4
2018.10.08T13:00:00 	A 	16
2018.10.08T13:00:00 	B 	9
2018.10.08T14:30:00 	A 	20
2018.10.08T14:30:00 	B 	20

Results from dailyAlignedBar: (Correct Results. As you can see the first candle starts from 09:15:00 which is correct.)

sym 	k30 	               sum_volume
A 	2018.10.08T09:15:00 	52
B 	2018.10.08T09:15:00 	14
A 	2018.10.08T11:15:00 	44
B 	2018.10.08T11:15:00 	15
A 	2018.10.08T12:45:00 	16
B 	2018.10.08T12:45:00 	9
A 	2018.10.08T14:45:00 	30
B 	2018.10.08T14:45:00 	49

please refer https://ask.dolphindb.net/question/1140 for updates and / or solutions

请先 登录 后评论

1 个回答

Jason Tang - 时序数据库技术支持

Time series engine includes createDailyTimeSeriesEngine and createTimeSeriesEngine, Their rounding rules are different from the dailyAlignedBar. In order to observe and compare the calculation results, the system will adjust the start time of the first data window, and determine the integer type adjustment scale alignmentsize according to the step parameter, the time accuracy of the data, and the roundtime parameter. When the time series engine uses grouping calculation, all grouping windows are uniformly regularized. The data window at the same time has the same boundary in each group.

If the time accuracy of the data is seconds, like DATETIME(yyyy-MM-dd HH:mm:ss)、SECOND(HH:mm:ss), the values of alignmentSize are as follows:

  1. roundTime=false

attachments-2022-01-nVyoRDmy61db8b0a4ae27.png

2. roundTime=true

When step <= 30, the value of alignmentsize is the same as in the table above. When step > 30, the value of alignmentsize is shown in the following table:

attachments-2022-01-MWLqNExa61db8d8b79fbf.png



请先 登录 后评论
  • 1 关注
  • 0 收藏,1085 浏览
  • Vishvesh Upadhyay 提出于 2022-01-08 16:37

相似问题