TWAP Execution
Install and import
npm install fintech-algorithmsimport { twapExecution } from "fintech-algorithms/execution-and-transaction-cost-analysis/schedule-based-execution/twap-execution";Signature
twapExecution(total_quantity, start_time_ms, end_time_ms, bucket_count, lot_size)Splits an order into equal slices across equal time buckets. The simplest schedule and the most predictable — predictable enough that it can be detected and traded against, which is the argument for the volume-based alternatives.
Parameters
| Name | Type | Notes |
|---|---|---|
total_quantity | number | Total quantity to execute. min: 1 · integer: true |
start_time_ms | number | Schedule start, epoch milliseconds. |
end_time_ms | number | Schedule end, epoch milliseconds. |
bucket_count | number | Number of time buckets. min: 1 · integer: true |
lot_size | number | Lot size; slices round to it and the remainder must be placed somewhere explicit. min: 1 · integer: true |
Returns
{ schedule, bucket_quantity, remainder_placement, … }
The child-order schedule with how the lot-rounding remainder was distributed.
Errors
- When end_time_ms is not after start_time_ms, or bucket_count is not positive — throws
Complexity: time O(buckets),
space O(buckets).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
120000144000024100Call
twapExecution(total_quantity, start_time_ms, end_time_ms, bucket_count, lot_size)Returns
object with 7 fields: total_quantity, lot_size, bucket_count, scheduled_quantity, remaining_quantity, schedule, state
{
"total_quantity": 12000,
"lot_size": 100,
"bucket_count": 24,
"scheduled_quantity": 12000,
"remaining_quantity": 0,
"schedule": [
{
"bucket": 1,
"start_time_ms": 0,
"end_time_ms": 60000,
"target_quantity": 500,
"target_cumulative_quantity": 500
},
{
"bucket": 2,
"start_time_ms": 60000,
"end_time_ms": 120000,
"target_quantity": 500,
"target_cumulative_quantity": 1000
},
{
"bucket": 3,
"start_time_ms": 120000,
"end_time_ms": 180000,
"target_quantity": 500,
"target_cumulative_quantity": 1500
}
],
"state": "complete-schedule"
}Other exports
This module also exports
historicalVwapExecution, adaptiveVwapExecution, percentageOfVolumeExecution, calculate. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- FIX Algorithmic Trading Definition Language Online Specification — FIX Trading Community
- Staff Report on Algorithmic Trading in U.S. Capital Markets — Staff of the U.S. Securities and Exchange Commission
- Evidence boundary