行情数据做日切,可以怎么区分出来?

我想对行情数据做日切,在DolphinDB database GUI中执行下列代码:

n_move=5
t1=
select concatDateTime(trade_date,trade_time) as time,secu_code,
 (close/close.move(n_move))-1 as r_close, //等价于ratios(close)-1 
 (volume/volume.move(n_move))-1 as r_volume,
 (turnover/turnover.move(n_move))-1 as r_turnover
from quote_1min
where trade_date between date_begin:date_end
context by secu_code

执行后结果如下:
image.png
图中选中的这5根分钟bar,其实是不能参照昨日尾盘的最后5根计算,应该取0了。这句执行后 update一下每日前5根分钟bar数据为0,也是可以达到目的,但我想精炼到一条语句,请问有什么方法?

阅读 1.9k
1 个回答

DolphinDB针对时序数据处理,在SQL中增加了一个context by子句,也就是说数据先按照context by后面指定的字段进行分组,每一个组内部再应用序列函数。

上面的例子其实已经使用了context by,只不过只按照股票一个字段进行分组,再增加一个日期字段即可。

n_move=5
t1=
select concatDateTime(trade_date,trade_time) as time,secu_code,
 (close/close.move(n_move))-1 as r_close, //等价于ratios(close)-1 
 (volume/volume.move(n_move))-1 as r_volume,
 (turnover/turnover.move(n_move))-1 as r_turnover
from quote_1min
where trade_date between date_begin:date_end
context by secu_code, trade_date
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进