CHAPTER 11A Few Use Cases
We conclude the Data Operations part of the book by illustrating some common time series operations in kdb+/q
and a demo of a real-time CEP engine.
11.1 ROLLING VWAP
The first example originates in high-frequency finance. Any update in the market will result in an update (tick) in our data. It is of fundamental importance for any market participant to understand the current state of the market. For this purpose, various statistics and indicators are needed to monitor market activity. Let us assume that we wish to calculate a moving VWAP (Volume Weighted Average Price) over a rolling window. We will cover two use cases.
11.1.1 N Tick VWAP
Here, we can make use of the msum
function we saw in Chapter 3 to calculate the moving VWAP for, say, 2 consecutive ticks. Using our standard trades table trd
from our hdb mydb
:
and the definition of a -tick VWAP at tick i
The 2-tick vwap for each symbol is
11.1.2 Time Window VWAP
For a moving time-window ...
Get Machine Learning and Big Data with kdb+/q now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.