Algorithmic trading and trading bots have become ubiquitous in both traditional and decentralized finance. There’s a wide range of algorithms that pre-configured bots execute as an automatic reaction to market conditions, minimizing or eliminating human oversight wherever and whenever possible.
And whereas such approach does offer a lot of benefits, it always also comes with a risk of losing a lot of money should the bot be misconfigured against one’s expectations of how the market would behave. It is also, obviously, highly dependent on the kind of product being traded on the market traded (e.g., whether currency, commodities, financial products, instruments and derivatives, decentralized crypto-assets, and cryptocurrencies)
Algorithms are essentially mathematical models or instructions/recipes, containing a series of micro-decisions that take place automatically and in sequence, designed to achieve some specific goal under the circumstances of particular market conditions.
These can be relatively simple and straightforward, common, run-of-the-mill order types that have built-in support by the exchanges, or highly customized and complex ones designed to meet a range of unique trading needs under specific circumstances (such as, for example, when dealing with sophisticated financial derivatives).
Institutional traders and investors that tend to make large orders tend to avoid making those as a single order as to minimize or eliminate the impact that might have on the market price, causing volatility and increasing risk among all market participants involved (or, in other cases, stop market price from rising further, etc.)
There are, thus, three main types of algorithms institutional investors use in those cases – TWAP (Time Weighted Average Price, which will be the subject of this article), VWAP (Volume Weighted Average Price, which tries to distribute a trade-in proportion to the underlying trading dynamics of the day) and Steps.
Time-Weighted Average Price Strategy
The Time-Weighted Average Price strategy (or TWAP, for short) is one common algorithmic execution strategy (a transaction cost reduction type of strategy, in the category of which most algorithmic strategies fall) used by traders that trade in high-volume products (or “whales” in the common jargon of the space).
The purpose is to split up large orders into parts of smaller ones over time in order to curtail the effect it might exert on market price too much (as well as help traders reduce slippage when buying or selling such large orders). By spreading out these trades strategically over time, the TWAP algorithm also ensures markets maintain a stable amount of liquidity.
How it all works is relatively simple and straightforward – one splits his order into equally divided smaller ones, incorporating time delays between them. The orders are then split into quantized amounts and executed in the sequence with the given interval of time delays in-between the orders (and without any time delay before the first order).
More technically speaking, this requires a simple state machine for the purpose of emitting those multiple orders over the clock ticks while maintaining important information about the state when processing the orders by adding state variables.
There are two main input parameters in TWAP – order period and the total investment to be evenly spread over that period. TWAP is generally based on the weighted average price when distributing a large order and allocating the amounts over time, with the equation being as follows:
Average price of the asset for a single day =
(Open + High + Low + Close)/4
Average price of asset over 24 days =
(Average of 1st day + Average of 2nd day + …….. + Average of 24th day’s price)/24
It assumes uniform distribution, although trades tend to very often be distributed in U-shapes during the day, indicating higher volume at the beginning and end of the day (that being one of TWAP’s minor drawbacks).
Why use a trading bot for TWAP?
Bots are used for automation purposes and perform as instructed, uninterrupted, with precision, and without errors (but from a human perspective, they are, of course, blind, deaf, and dumb). That makes them incredibly useful for programmatically organizing repetitive processes easily.
TWAP strategy is useful when:
- Placing and executing a large order within a short time horizon without affecting market price too much.
- Anticipating extreme high-volume price movements (in case of which TWAP may give better results and execution price than its alternative, the VWAP, or Volume Weighted Average Price strategy).
- Aiming to reduce the impact on the market by splitting a single large order into smaller volume portions and carry them out in quick succession (also may use iceberg orders). Institutional investors, being by definition conservative, have the capacity to issue strong economic signals which may have a significant impact on the market price valuation of an asset and the behavior of other market participants involved, which is why TWAP is commonly used algorithm among institutional players’ toolbox.
- TWAP strategy discloses minimal order quantities so that TWAP signals do not affect market volatility, reducing or eliminating immediate impact on market price and stability.
- Useful whenever a predictable systematic order execution schedule is required.
- Can be applied to illiquid assets (applying volume limit in percentage).
- The TWAP algorithm tends to be favored by traders who deal with HFT (High-Frequency Trading) and other types of Quantitative/Algorithmic trading (who also try to conduct trades stealthily without affecting market perceptions too much by dumping a large number of shares in a single block, etc.)
- TWAP strategies and signals cover a considerable surface of risk.
- Generally, it is recommended to apply TWAP over short durations or on assets that do not seem to have any volume profile.
Selling 1 Ether using TWAP by adjusting investment period to one hour and a total investment of 1 ETH. Thus, according to system estimation, that will result in the selling of 0.1666 ETH every 10 minutes, stopping after one hour as the full amount of Ether is sold, without affecting market price in the process.
There are indicators that help in deciding what is essential for the TWAP strategy, though the actual TWAP strategy parameters depend on the trader himself.
What market conditions are the best for TWAP?
Periods of high liquidity and rising markets (bull runs) are the most favorable market conditions for implementing TWAP strategies. There are two major factors that contribute to market impact – liquidity and signaling (when the trade triggers a noticeable signal about the value of the asset being traded).
Other factors and variables which define market conditions (and whether or not they are favorable for and conducive to a particular strategy’s success) include asset prices and noise, capacity (discrepancies between supply and demand), political stability, etc. Of course, the manner in which the strategy or algorithm is implemented to behave within the circumstances is crucial.
Asset prices themselves relate to business cycles of investor enthusiasm (for a particular investment at a point in time) and historically, asset prices tend to go through boom and bust cycles of dramatic increases (bubble and micro-bubble formations), followed by corrections and crashes.
What can go wrong with TWAP strategy?
Algorithmic and High-Frequency Trading (HFT) is also associated with things such as flash crashes and things slipping out of control as the markets tend to in the long run mutate in their unpredictability (especially in the short-term, which is often mostly noise as compared to the isolating of the general trend of the longue durée). Or, to quote Paul Virilio, “the invention of the ship was also the invention of the shipwreck.”
And TWAP too, is, of course, not ideal. For one, it doesn’t fully incorporate and reflect the trading activity that goes on throughout the middle of the day – it may trade too little when there’s liquidity and too much when there’s less liquidity during the day (although that obviously also depends on how liquid the underlying asset is and how much is traded).
In the end, it is all heavily dependent on the input parameters set by the trader himself and any algorithmic trading automata requires at least occasional human oversight to make sure the key fits the padlock, so to speak.
How to automate TWAP strategy?
As already mentioned above, TWAP is derived by averaging the whole day’s price bar, i.e., open, high, low, and close prices of the day. After that, on the basis of time decided to execute an order, every day’s averaged price is taken for calculating the average of the entire duration’s prices in the process of running the algorithm’s strategy.
There’s a variety of available services and bots (web/cloud-based and client-side software) that offer TWAP among the automation strategies and algorithms their services offer. Those can connect to either centralized exchanges like Binance and KuCoin or decentralized trading and exchange protocols (mostly Ethereum-based, but also Bitcoin’s Liquid and in all likelihood Cardano, Tezos, and others in the near future) – or both.
Most of these products also include market-making, cross-exchange market making, arbitrage, and other strategies that come pre-built, while allowing you to construct your own, either from building blocks or from scratch. Bots usually come with ready-made exchange and protocol connectors and bridges but also allow you to build your own.