Efficient code for current volume from cumulative volume

I have found a code which converts cumulative volume into current volume. (from https://gitee.com/dolphindb/Tutorials_CN/blob/master/hf_factor_streaming.md)

def calcVolume(mutable dictVolume, mutable tsAggrOHLC, msg){ 
	t = select Symbol, DateTime, Price, Volume from msg context by Symbol limit -1 
	update t set prevVolume = dictVolume[Symbol] 
	dictVolume[t.Symbol] = t.Volume 
	tsAggrOHLC .append!(t.update!("Volume", <Volume-prevVolume>).dropColumns!("prevVolume")) 
}

I have some questions as under:

1) is this code efficient?

2) what is the meaning of  update t set prevVolume = dictVolume[Symbol] & dictVolume[t.Symbol] = t.Volume  ? Please explain.

3) if the code is not efficient what can I do to make it efficient?

请先 登录 后评论

1 个回答

Shena Mao

That case is used for snapshot market data. "limit -1 " is used to filter duplicate values.

(1) since it is a pretreatment for data, this step is neccessary and efficient for this instance.

(2)update t set prevVolume = dictVolume[Symbol] here we add a new column which equals to previous cumulative volume that we saved last time.

 dictVolume[t.Symbol] = t.Volume and then we update dict to current cumulative volume.

tsAggrOHLC .append!(t.update!("Volume", <Volume-prevVolume>).dropColumns!("prevVolume")) finally we get current volume and input to TimeSeriesAggregator.


请先 登录 后评论
  • 1 关注
  • 0 收藏,1038 浏览
  • Vishvesh Upadhyay 提出于 2021-09-13 21:03

相似问题