Tuesday, August 11, 2009

Volume Weighted Average Price (VWAP)

Recently i was skimming through an ebook about electronic trading (Electronic and Algorithmic Trading Technology) after reading this news article. This ebook outlines algorithmic trading in a concise way. According to this book and wikipedia entry, more than half of the orders in London Stock Exchange in the last year were entered by algo traders.

According to the ebook, one of the fundamental and basic algo trading is Volume Weighted Average Price (VWAP). VWAP is the ratio of value traded to total quantity of trades in a time period. It is average price of an security in terms of quantity. It is calculated as follows:



VWAP algorithm implies that at a given time if VWAP is greater than the price of share, then the share is under valued and it is a good candidate for buying. But if VWAP is lesser than the price of share, then it should be considered for selling. Even though, it is a very simple algorithm, it and its variations are commonly used in electronic trading.

I have implemented a sample java application (algo trading) which estimates VWAP of an equity by fetching real time (15 min delayed) financial quotes from Yahoo Finance, UK. Equity quotes (15 min delated) can be downloaded free of charge from yahoo finance pages in CSV format. The sample application periodically downloads predetermined quotes (for example VODAFONE GRP --VOD.L) in CSV format and estimates VWAP. Unfortonately, since downloaded data do not consists of trade quantity values (CSV files has following data: symbol, mid trade, time, date, change, lowest trade, highest trade and volume), quantity value for each quote is estimated based on the volume and mid price.

The sample application has multi layered architecture with observer design pattern. It uses Apache HTTPClient to download CVS files periodically from yahoo finance pages. After quotes are extracted from CSV files, they are appended to a linkedlist based time series and then observers (VWAP estimator and then VWAP clients(UI layer)) are notified for the latest updates.

Click here to download source code of the sample application (algo trading) in java.