Skip to main content

TWAP Algorithm

The Time-Weighted Average Price (TWAP) algorithm spreads out order execution over a fixed time window (e.g., few seconds, or a few days). A time window is defined for each order. This may be attractive for clients who want to execute an order in a simple, predictable manner. The TWAP algorithm performs market chasing, described below.

TWAP Execution in TCA

Standard TWAP Order Parameters

FIX TagField nameTypeReq'dComments
1AccountStringNTrading Order account. All child orders will have the same trading account.
55SymbolStringYThis tag is required. Human-readable instrument name as it is defined in Deltix Security Metadata.
54SideCharYOrder side ("1"=BUY or "2"=SELL)
50SenderSubIDStringYTrader ID
44PricePriceYLimit Price
38OrderQtyQtyYOrder quantity
76BrokerIDStringY"TWAP" (Deployment key of algo strategy)
40OrdTypeCharY"X" (Denotes custom algo order)

Custom TWAP Order Parameters

FIX TagField nameTypeReq'dComments
6002OrderDurationStringNOrder 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.
The maximum value is 29:59:59. Use StopTime for longer duration.
6013FixedQtyFloatNFixed quantity is the threshold lean quantity. Disabled at 0 (default). Algorithm ignores quotes that are smaller than fixed quantity when it determines passive price.
6021StartTimeTimestampNDefines order execution start time. If this field is not specified, the start time will be order submission time (order will start executing immediately)
6022StopTimeTimestampNDefines order exit time. Required when OrderDuration(6002) is not specified.
6023PercentFloatYPercentage used to split time and quantity.
Example: "25" means 25%. Order duration will be split in four equal intervals.
6027IntervalVarianceFloatNPercentage 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. For example, value “10.5” means 10.5% or 0.105 variance.
6028QuantityVarianceFloatNPercentage in the range from 0 to 50% that randomizes the quantity of the child orders. For instance, when 10% quantity variance is specified, each next child order will be issued with the quantity within 10% of the fixed quantity specified by Percent and OrderQty attributes. For example, value “10.5” means 10.5% or 0.105 variance.
6035SubmitRemainingQuantityStringNIf “true” TWAP will submit more aggressive IOC order for remaining quantity at the end of the last clip. The order will be issued with active price (market price or the price crossing the market by specified offset) but only if currently issued orders haven’t reached the parent order limit price yet.
6036MinPriceUpdateIntervalStringNMin 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
6044ActivePriceOffsetUnitIntNPrice offset Unit: 0 for quote currency (default), 1 for percentage and 2 for offset in ticks
6045ActivePriceOffsetFloatNPrice offset in unit specified by price offset unit attribute or by default in quote currency. If specified, TWAP 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 TWAP will switch to using active price instead of passive price.
7002EligibleExchangesStringNIf 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).

Percent Parameter

The Percent parameter takes the total time between start and stop to determine the time interval between new orders. Percent also splits each clip into smaller clips based on the interval. 

For example, consider a TWAP order with the following parameters:

FieldValue
OrderQty(38)500
Percent(6023)5
EntryTime(6021)2017-10-21 2:00:00 PM EST
StopTime(6022)2017-10-21 4:00:00 PM EST

Each clip is (500 * (5/100)) = 25 lots.

The time period between clips = 7200 seconds => 7200 * 0.05 = every 360 seconds.

Percent, EntryTime, and StopTime (and/or Duration) cannot be changed during the course of an order. Everything else can be modified after order entry.

Market Chasing

In TWAP, parent order quantity is split into clips and each clip becomes available to trade over time one by one. As each clip becomes available, it is placed to the market with the child order sent to the configured defaultOrderDestination.

TWAP will issue its child orders either at passive or active price. It will maintain up to the last clip quantity at passive price, and any additional quantity is placed with a more aggressive active limit price. 

Passive and active prices are based on the current market price, but are limited by the parent order limit price. 

Passive price is computed as either the market price or the price that is 1 tick worse than the market price. TWAP will use a more aggressive market price in this case when:

  • The parent order has the optional fixed quantity parameter specified
  • The market is narrow (the spread is 1 tick)
  • The market lean quantity is smaller than the fixed quantity.

This optional FixedQty parameter can be set on the order via the custom attribute 6013.

Active price is computed as either the market price or a more aggressive price that is crossing the market by a price offset specified by the user. This optional price offset parameter can be set on the parent order with the custom attribute 6045.

If each clip quantity is completely filled during each interval, TWAP issues all its child orders using passive prices. If clip quantity is only partially filled, TWAP splits the next clip into two orders and places only up to the last clip quantity at passive price and any remaining quantity at active price. 

TWAP monitors the market, and when it moves away, such that all current child orders become less aggressive than the current passive price, TWAP chases the market by updating its child orders. 

When updating the orders, normally, TWAP follows the same rules it uses when it issues the child orders: it keeps one order with the available quantity (up to the last clip quantity) at the current passive price, and if needed, issues another order at active price for the remaining available quantity. However, in cases where an order has a price offset specified, TWAP uses more aggressive market chasing. Instead of splitting the available quantity between passive and active orders, it issues a single order for all available quantity at the current active price.

Changing Order Working Price

The child order is entered at the passive price (the price one tick above the bid price when selling and one tick below the offer when buying), subject to the maximum price specified by the user.

There are various conditions that force the order to change prices to a maximum limit. An order can change price if any one of the following conditions are met:

  • Parameter FixedQty(6013) quantity is breached: Best Qty _≤ Fixed Qty(6013).

    Action: Aggress to the best market price.

  • The market is wide: market is wider than the best price ± one tick.

    Action: Move the order to the passive price.

  • Order price is not on passive price (missed). This occurs when the price flips without any of the other conditions being met.

    Action: The order is then moved to the passive price.

Each of the above conditions moves the order price to at least the passive price. If the working price of the order was changed, all active child orders will be moved to the new price.

note

Best Bid is the quantity of the top of the book on the other side of the market. For example, for SELL orders "Best Qty" is the size of the best bid on the market.

At the beginning of the new TWAP period, any remaining quantity or the previous slice is moved to an aggressive price. The new slice follosw the passive price algorithm described above.

Other Considerations

IOC Orders

The TWAP algorithm chases the market it usually makes starting with passive price (see the previous section). From this angle, it usually makes no sense to apply a IOC (Immediate-or-Cancel) time in force condition to the order. IOC orders will not be posted to the order book and are unlikely to discover hidden liquidity (unless the market supports hidden orders).

Deployment Options

Default Destination

When defined, this parameter ensures that all child orders are routed to a specific destination. For example, SIMULATOR.

Configuration Example

The following stanza shows how a TWAP algorithm can be configured in ember.conf:

algorithm {
TWAP: ${template.algorithm.default} {
factory = "deltix.ember.algorithm.pack.twap.TWAPAlgorithmFactory"
subscription {
streams = ["COINBASE", "BINANCE", "KRAKEN"] # market data streams
symbols = [BTC/USD, LTC/USD, ETH/USD, LTC/BTC, BCH/USD, BCH/BTC, ETH/BTC]
}
settings {
defaultOrderDestination = "SOR"

// maximum number of canceled child orders in a row without any trades before parent order is canceled
maxCancellations = 3
}
}
}

Configuration

Here is the complete list of supported config 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
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.