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.
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:
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: