VWAP and TWAP

526 views
Skip to first unread message

dave.smit...@gmail.com

unread,
Nov 2, 2016, 5:20:39 AM11/2/16
to Kdb+ Personal Developers
All,

I would like to find the most efficient way to calculate a series of time weighted average prices from a trade and quote table such as those supplied by kx for kdb+ tick

What is the optimum design layout for this type of set up?

Questions I would help with::

a) The TWAP and VWAP windows will be fixed at the start of day with values such as "allay" "5 minutes" "1 hour "  and so on

b) I have a simple FIX robot sending quotes to a Torq based ticker plant from https://github.com/AquaQAnalytics

c) Are we better performing these calculations as soon as the robot gets a relevant update, or should I have a dedicated engine to calculate these metrics

d) Do we advise any issues publishing updates from multiple sources into a single ticker plant?

e) Does anyone have any advice on how I should proceed? I like to create a simple strategy to identify momentum price shifts, as well as spot simple arbitrage opportunities

Thanks for help

D

Jonathon McMurray

unread,
Nov 16, 2016, 2:19:37 AM11/16/16
to Kdb+ Personal Developers

Hi David

 

The best option for this will be a real time subscriber process, subscribed to your tickerplant to track the necessary data and perform the calculations of these metrics as required.

 

We have developed a real time subscriber to achieve this. I have attached the code for this process. This code will work with a standard kdb+tick setup (or with the kdb+ framework setup you mentioned).

 

The subscriber will subscribe to the TP, and will recover historical messages by replaying the log file up until the point of subsciption.

 

In order to get this up & running, you will need to modify the connection details for the TP in the init function. You may also need to modify the column names in the following line in the upd function to match the schema for your trade table:

 

x: flip `time`sym`price`size`stop`cond`ex!x

 

The windows for calcuation of the metrics can be defined in the "windows" variable at the top of the file, though the subscriber is flexible enough to calculate VWAP + TWAP over any period, e.g. you could also use it to calculate the VWAP/TWAP from 20 minutes ago until 5 minutes to go. 

 

To obtain the metrics at any time, call the metrics[] function with a list of syms as the argument e.g. metrics[`AAPL`MSFT]

 

You also posted this on our other google group - we’ll post a slightly modified version over there. 

 

Hope this helps

Jonathon

metrics_tick.q
Reply all
Reply to author
Forward
0 new messages