Skip to main content

VWAP Algorithm

The Volume Weighted Average Price (VWAP) Algorithm uses the historical volume pattern of order instrument to determine a trading trajectory.

Overview

VWAP algorithm is designed to trade a fixed quantity of an instrument over a specified time period. The algorithm uses historical volume patterns to determine a trading trajectory.

Its implementation is very similar to TWAP in that it also splits the trading period into equal intervals and issues child orders at the beginning of each interval. However, the parent order quantity is not split evenly among the orders issued for each interval. Each clip size is determined according to the historical weekly and daily volume profile of the instrument.

Similarly to TWAP, VWAP will try to keep the last clip quanty at the passive price, while placing any additional quantity at the aggressive price. It will use the same “market chasing” approach as TWAP.

Order Parameters

Standard order Parameters

FIX TagField nameTypeReq'dModifiableComments
1AccountStringNNTrading Order account. All child orders will have the same trading account.
55SymbolStringYNThis tag is required. Human-readable instrument name as it is defined in Deltix Security Metadata.
54SideCharYNOrder side ("1"=BUY or "2"=SELL)
50SenderSubIDStringYNTrader ID
44PricePriceYYLimit Price. Child orders price is calculated based on the current market price but cannot be worse than the parent order limit price.
38OrderQtyQtyYYOrder quantity
76BrokerIDStringYN"VWAP" (Deployment key of algo strategy)
40OrdTypeCharYN"X" (Denotes custom algo order)
59TimeInForceCharNYTime in Force of the child orders. All child orders are canceled at the end of order duration period regardless of time in force. ('0' = Day, '1' = Good Till Cancel)

VWAP Specific Order Parameters

FIX TagField nameTypeReq'dModifiableComments
6002OrderDurationStringNNOrder duration in HH:MM:SS or HH:MM:SS.sss format. For example, 05:03:30 would be 5 hours, 3 minutes, and 30 seconds from the order start time. This parameter is required when StopTime is not specified. The maximum value is 29:59:59. Use StartTime and StopTime parameters for longer duration.
6013FixedQtyFloatNYFixed quantity is the threshold lean quantity. Disabled at 0 (default). Algorithm ignores quotes that are smaller than fixed quantity when it determines passive price.
6021StartTimeTimestampNNDefines order execution start time in UTC timestamp format: YYYYMMDD-HH:MM:SS.sss. If missed, start time will be order’s arrival time.
6022StopTimeTimestampNNDefines order exit time in UTC timestamp format: YYYYMMDD-HH:MM:SS.sss. Required when OrderDuration is not specified.
6023PercentFloatYNPercentage used to split time.
Example: "25" means 25%. Order duration will be split in four equal intervals.
6027IntervalVarianceFloatNYPercentage in the range from 0 to 50% that randomizes the fixed time interval between child orders. For instance, when a 10% interval variance is specified, each next child order will be issued after interval within 10% of the fixed time interval specified by Duration and Percent attributes.
6034WeeklyVolumeRatioFloatNYDefines ratio of Weekly trading volume profile relative to Daily volume profile. Value of this attribute must be between 0 and 100. The default value is 0: only previous day profile will be used. When set to 100 we will use the previous week profile for the same day and time of the week only.
6036MinPriceUpdateIntervalStringNYMin time interval that must pass between order price updates during market chasing. This attribute is in HH:MM:SS or HH:MM:SS.sss format
6044ActivePriceOffsetUnitIntNYPrice offset Unit: 0 for quote currency (default), 1 for percentage and 2 for offset in ticks. For example, to specify 2.5 % ActivePriceOffset, set 6044=1 and 6045=2.5.
6045ActivePriceOffsetFloatNYPrice offset in unit specified by price offset unit attribute or by default in quote currency. If specified, VWAP will use a more aggressive active price that instead of staying at market price will cross the market by specified offset. Also, when chasing the market VWAP will switch to using active price instead of passive price.
7002EligibleExchangesStringNYIf specified, restricts exchanges where order should be executed. Comma-separated list of exchange codes "COINBASE,BINANCE,GEMINI". Each exchange name must match the Deltix exchange code. This tag is used for children orders (for example when sending children to SOR).

Configuration

The following section shows how a VWAP algorithm instance can be configured in ember.conf:

algorithms {
VWAP: ${template.algorithm.default} {
factory = "deltix.ember.algorithm.pack.vwap.VWAPAlgorithmFactory"
subscription {
streams = ["COINBASE", "BINANCE", "KRAKEN"] # market data streams
symbols = ["BTCUSD", "LTCUSD"]
}
settings {
defaultOrderDestination = SIM # all child orders will be routed to SIM
volumeProfileStream = vwap-profile-stream # VWAP curve stream in TimeBase
}
}
}

Here is the complete list of supported configuration settings:

Parameter NameDescription
initialActiveOrdersCacheSizeOptional, int. Initial active orders cache size.
initialClientsCapacityOptional, int. Initial client capacity.
maxInactiveOrdersCacheSizeOptional, int. Maximum inactive orders cache size.
orderCacheCapacityOptional, int. Order cache capacity.
defaultOrderDestinationOptional, string, null by default. Destination of orders issued by the algorithm
volumeProfileStreamRequired, string. TimeBase stream that defines VWAP curve
maxCancellationsOptional, int. 3 by default. Parent order will be canceled when the number of child orders cancellations with no trades exceeds this number
applyRequestTagsOptional, array of strings. [ 7002 ] by default. List of tags of parent order custom attributes that should be included with child orders if available. This list can contain individual keys or a range of keys from a min and up to a max. Min and max key in the range will be separated by '-'. For example: "applyRequestTags = [ 7002, 1-1000 ]", where the second value is a range of keys that includes all keys from 1 to 1000

Please refer to Ember's Configuration Reference for more information about algorithm deployment options.

VWAP Profile Generation

Deltix provides Java and .NET samples that generate volume profiles consumed by VWAP Algorithm.

VWAP curves are expected in the following format (VolumeProfileMessage TimeBase message):

FieldTimeBase TypeDescription
symbolVARCHAR, REQUIREDInstrument ID
timestampTIMESTAMP, REQUIREDCaptures when this message is stored into TimeBase. Not used in calculations.
BuyQuantityDOUBLE, REQUIREDTotal volume of trades where BUY side was initiator
SellQuantityDOUBLE, REQUIREDTotal volume of trades where SELL side was initiator
StartTimeTIMESTAMP, REQUIREDTime when this profile will be actual. Only time of day part of this timestamp matter. VWAP will convert this time to Linux epoch time and build index using formula:

( timestamp % (24 * 60 * 60 * 1000)) / 60000

EndTimeTIMESTAMP, REQUIREDTime when this profile will be no longer actual (must be later than StartTime). Same handling as StartTime.

Each VolumeProfileMessage contains symbol volume data for a 1 minute interval specified by startTime and endTime in UTC. buyQuantity and sellQuantity attributes contain traded volume for this interval where the BUY or SELL side was the aggressor.

For markets that do not provide an aggressor side indicator in their trades, you can use the Lee / Ready heuristic or simply use total observed volume for Buy and Sell quantities.

A Java representation of a corresponding TimeBase message:

package deltix.ember.algorithm.pack.vwap.data;

import deltix.qsrv.hf.pub.InstrumentMessage;
import deltix.qsrv.hf.pub.md.FloatDataType;
import deltix.qsrv.hf.pub.md.TimeOfDayDataType;

@deltix.timebase.api.SchemaElement(name = "deltix.ember.algorithm.pack.vwap.data.VolumeProfileMessage")
public class VolumeProfileMessage extends InstrumentMessage {
public double BuyQuantity = FloatDataType.IEEE64_NULL;
public double SellQuantity = FloatDataType.IEEE64_NULL;
public int StartTime = TimeOfDayDataType.NULL;
public int EndTime = TimeOfDayDataType.NULL;
}

VWAP Curve Generation Utility

Ember provides a volume-profile-publisher utility to generate volume profiles based on market data. The following is a command line utility help screen:

Usage: volume-profile-publisher [-help] [-timebase <arg>] -marketStreams <arg> -profileStream <arg>
[-startTime <arg>] [-endTime <arg>] [-symbols <arg>] [-dryRun]
-help print this message
-timebase <arg> timebase URL (default is dxtick://localhost:8011)
-marketStreams <arg> comma-separated list of market data streams
-profileStream <arg> volume profile stream, where volume profile messages will be written
-startTime <arg> start time from which profile should be generated from market data. By
default publisher will process market data starting one week back
-endTime <arg> end time at which to stop generating profile from market data. If not
specified publisher will keep processing messages in live mode
-symbols <arg> comma-separated list of symbols of instruments for which volume profile
should be generated. If not specified profile will be generated for all
market data symbols
-dryRun execute a dry run with volume profile messages written to the console only

The script is located in /opt/deltix/ember/bin folder.

Example use (as docker-compose):

vwap-profile-generator:
image: "registry.deltixhub.com/deltix.docker/anvil/deltix-ember-pack:1.10.42"
depends_on: [ timebase ]
environment:
- JAVA_OPTS=
-Xms256m
-Xmx256m
entrypoint:
- /opt/deltix/ember/bin/volume-profile-publisher.sh
- $${JAVA_OPTS}
- -timebase
- dxtick://timebase:8011
- -marketStreams
- COINBASE,BINANCE,KRAKEN
- -profileStream
- vwap-profile