Click here to Skip to main content
15,888,521 members
Articles / Programming Languages / C#

Volume Weighted Average Price (VWAP) Algorithm

Rate me:
Please Sign up or sign in to vote.
4.94/5 (11 votes)
11 Jan 20063 min read 137.7K   1.9K   76  
Calculates Volume Weighted Average Price for Financial Time series.
All files in this Solution Copyright (C) 2006 Andrew Peters and Fabrefactum Software LLC
This code is for educational purposes only.  Commercial use is prohibited except with author's permission

Contact the Author:
Andrew Peters
apeters@fabrefactum.com
www.fabrefactum.com

Build/Installation Notes:

The TestVWAP project uses StockChartX, a 3rd party COM component.  Unless you have purchased a 
license for its use and it is registered on your machine, you will not be able to build or run
this project.  You may run the compiled executable, provided you register the StockChartX.ocx component.
For most users, this test code is useful as example only.  

The tester reads in a comma-delimited text file in the following format:
Date, Time, Open, High, Low, Close, Volume
It is hard-coded for this column order.  Any custom column orders have to be changed in the code.
It would be very straightforward to pull out the column manipulation code into its own class to make it more
flexible.

VWAP is primarily used by institutional traders.  Make broker dealers offer VWAP orders so that a basket of orders' 
fill price will average out to the VWAP.  This places risk on the broker dealer, so there are often higher spreads
or fees for this type of order, or are only offered to high-volume traders.  VWAP orders balance time versus impace and
often traders will use VWAP orders to send a packet of a few hundred shares every few seconds over the course of an entire day.

While many electronic broker dealers now offer VWAP orders, it is often difficult for traders to calculate VWAP realtime.  This simple
VWAP class automates the calculation for a time series.

Before calculating volume weighted average price for a time series, we first need to construct a TimeSeries class that holds our data.

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Andrew Peters is a systems developer interested in non-trivial trading systems and financial systems architecture. He is currently focused on realtime, high performance multi-threaded applications running on the server and the desktop.

After a 4 year stint in China learning Mandarin and Tibetan, Andrew returned to the US to learn more about enterprise development and financial markets. While in China, he translated meetings between demure Communist officials and angry American businessmen, served coffee and fetid tofu in his 'BaiSuiFang' Coffee Shop, started Fabrefactum Software and was generally laughed at for his stupid jokes in Chinese.

He currently helps the pricing/analytics team hack on code at Chatham Financial, an interest rate and foreign exchange derivative consulting company.

Comments and Discussions