TS_VWAP Function [Aggregate]

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)

Licensing Prerequisites

Available only with RAP – The Trading Edition Enterprise.

Parameters

Usage

Sybase IQ calculates TS_VWAP using the following formula:

VWAP Calculation
Displays the 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:

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:

Values Returned from TS_VWAP

res

2.5

2.5

2.5

Standards and Compatibility

Related concepts
Aggregate Time Series Forecasting and Analysis Functions