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 Tag | Field name | Type | Req'd | Comments |
---|---|---|---|---|
1 | Account | String | N | Trading Order account. All child orders will have the same trading account. |
55 | Symbol | String | Y | This tag is required. Human-readable instrument name as it is defined in Deltix Security Metadata. |
54 | Side | Char | Y | Order side ("1"=BUY or "2"=SELL) |
50 | SenderSubID | String | Y | Trader ID |
44 | Price | Price | Y | Limit Price |
38 | OrderQty | Qty | Y | Order quantity |
76 | BrokerID | String | Y | "VWAP" (Deployment key of algo strategy) |
40 | OrdType | Char | Y | "X" (Denotes custom algo order) |
VWAP Specific Order Parameters
FIX Tag | Field name | Type | Req'd | Comments |
---|---|---|---|---|
6002 | OrderDuration | String | N | Order 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 time the order was initially entered (entry time captured during initialization). The entry time would be statically assigned so if the user chooses later to modify the parameter to 03:00:00, the new calculated end time of the algo would be from the initial entry time plus 3 hours. Required when StopTime is not specified. |
6013 | FixedQty | Float | N | Fixed quantity is the threshold lean quantity. Disabled at 0 (default). Algorithm ignores quotes that are smaller than fixed quantity when it determines passive price. |
6021 | StartTime | Timestamp | N | Defines order execution start time. If missed, start time will be order’s arrival time. |
6022 | StopTime | Timestamp | N | Defines order exit time. Required when OrderDuration is not specified. |
6023 | Percent | Float | Y | Percentage used to split time. Example: "25" means 25%. Order duration will be split in four equal intervals. |
6027 | IntervalVariance | Float | N | Percentage 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. |
6034 | WeeklyVolumeRatio | Float | N | Defines 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. |
6036 | MinPriceUpdateInterval | String | N | Min 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 |
6044 | ActivePriceOffsetUnit | Int | N | Price 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. |
6045 | ActivePriceOffset | Float | N | Price 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. |
7002 | EligibleExchanges | String | N | If 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 Name | Description |
---|---|
initialActiveOrdersCacheSize | Optional, int. Initial active orders cache size. |
initialClientsCapacity | Optional, int. Initial client capacity. |
maxInactiveOrdersCacheSize | Optional, int. Maximum inactive orders cache size. |
orderCacheCapacity | Optional, int. Order cache capacity. |
defaultOrderDestination | Optional, string, null by default. Destination of orders issued by the algorithm |
volumeProfileStream | Required, string. TimeBase stream that defines VWAP curve |
maxCancellations | Optional, int. 3 by default. Parent order will be canceled when the number of child orders cancellations with no trades exceeds this number |
applyRequestTags | Optional, 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):
Field | TimeBase Type | Description |
---|---|---|
symbol | VARCHAR, REQUIRED | Instrument ID |
timestamp | TIMESTAMP, REQUIRED | Captures when this message is stored into TimeBase. Not used in calculations. |
BuyQuantity | DOUBLE, REQUIRED | Total volume of trades where BUY side was initiator |
SellQuantity | DOUBLE, REQUIRED | Total volume of trades where SELL side was initiator |
StartTime | TIMESTAMP, REQUIRED | Time 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 |
EndTime | TIMESTAMP, REQUIRED | Time 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