TS_VWAP function [Time Series]

NoteThis function is available only with RAP – The Trading Edition Enterprise.

Function

VWAP stands for volume-weighted average price. TS_VWAP calculates the ratio of the value traded to the total volume traded over a particular time horizon. VWAP is a measure of the average price of a stock over a defined trading horizon. You can use TS_VWAP as both a simple and an OLAP-style aggregate function.

Unlike the other time series functions, TS_VWAP does not call the IMSL libraries.

Syntax 1

TS_VWAP (price_expression, volume_expression)

Syntax 2

TS_VWAP (price_expression, volume_expression)
OVER (window-spec)

Parameters

price_expression A numeric expression specifying the price to be incorporated into a volume-weighted average.

volume_expression A numeric expression specifying the volume to be used in calculating a volume-weighted average.

window-spec If used with Syntax 2, TS_VWAP is an OLAP function requiring an OVER () clause.

Usage

Sybase IQ calculates TS_VWAP using the following formula:

Figure 4-1: VWAP calculation

VWAP calculation

Pvwap = volume weighted average price Pj = price of trade j. Qj = quantity of trade j. j = an individual trade that occurred during the time horizon.

Example

This example shows an input data table, a SQL statement containing the TS_VWAP function, and the data values returned by the function. This example uses the following table (called VWAP_DATASET) as its input data. The VWAP_DATASET table contains three rows of time series data:

Table 4-61: Input data table VWAP_DATASET

rownum

price

volume

1

1

1

2

2

2

3

5

1

The following SQL statement calculates the volume weighted average price:

select ts_vwap(price,volume) over (order by rownum Rows between unbounded preceding and unbounded following) as res FROM VWAP_DATASET

Sybase IQ returns three rows:

Table 4-62: Values returned from TS_VWAP

res

2.5

2.5

2.5

Standards and compatibility

See also

Chapter 2, “Using OLAP” in the System Administration Guide: Volume 2