This function is available only with RAP – The Trading Edition Enterprise.
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.
TS_VWAP (price_expression, volume_expression)
TS_VWAP (price_expression, volume_expression)
OVER (window-spec)
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.
Sybase IQ calculates TS_VWAP using the following formula:
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.
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:
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:
res |
---|
2.5 |
2.5 |
2.5 |
Chapter 2, “Using OLAP” in the System Administration Guide: Volume 2