Optimal series with realtime

Problem: When running large workspaces with many long timeseries where the last point is updated by realtime data from Bloomberg or Refinitiv, the calculations can become very inefficient - if naively recalculating the historical part over and over again.

By only updating the last value in the series, either using its index or date depending on which “x-axis” type that is used, a very efficient calculation can be achieved.

//place some data in global variable
series<date>(number) ret;
logical need_init = true;
instrument_name g_i = "";
date g_d = today();

//function that will be run every time there is a realtime tick coming in.
out series<date>(number) t(instrument_name i){
	
	//initialize first time or re-fetch history for change of instrument
	if(need_init || g_i != i){
		ret = series(d:g_d-500, g_d;  instrument(i, d, "Mid").quote());
		need_init = false;
		g_i = i;
	}
	
	//get and subscribe to realtime value for instrument i
	number realtime = instrument(i, g_d, "Mid").quote();
	//update the last point i.e. todays date with the new realtime value
	ret[g_d] = realtime;
	
	return ret;
}

Also adding an example wsp with the code above.
Optimal-series-with-realtime.qlw (7.6 KB)

3 Likes