Interactive TWAP scheduling and execution cost estimation tool using intraday equity data.
This model does not execute trades — it only generates an execution schedule, estimates expected trading costs, and compares expected TWAP performance versus VWAP.
Simulate a TWAP-style execution plan for a user-defined equity order and estimate the expected trading cost per slice and in total, subject to participation and liquidity constraints. Benchmark expected TWAP execution performance against VWAP.
| Input | Description | Example |
|---|---|---|
ticker |
Equity ticker | AAPL |
Q |
Parent order size (shares) | 50,000 |
direction |
Trade direction | Long or Short |
start_time |
Start time of execution | 10:00 |
bin_minutes |
Time bucket size | 5, 10, or 15 |
p_max |
Max participation rate | 0.02 – 0.10 |
- yfinance intraday OHLCV data
- Intraday bars are resampled to the selected time bucket size (
bin_minutes) - VWAP is computed using an OHLCV-based approximation, not true trade-level VWAP
- Max participation per bucket:
p_max(2%–10%) - Scheduling & cost estimation only (no execution)
- No persistence — all results are displayed immediately
- Execution runs from
start_timeuntil order completion or market close
V_i is the expected market trading volume for time bucket i, estimated using a 20-day rolling window of historical intraday volume for the same time-of-day bucket.
This mirrors the methodology used to estimate volatility.
- Pull intraday OHLCV data for the last ≥20 trading days
- For each trading day, resample volume into
bin_minutesbuckets - Label buckets by time-of-day (e.g.
10:00–10:05) - For each bucket
i, collect historical volumes:
[ {V_{d-1,i}, V_{d-2,i}, \ldots, V_{d-20,i}} ]
- Compute expected bucket volume:
[ V_i = \text{mean}\left(V_{d-k,i}\right), \quad k = 1 \ldots 20 ]
If fewer than 20 observations exist:
- Use available data if ≥10 observations
- Otherwise return a warning:
Insufficient intraday history to estimate bucket volume
The same V_i is used consistently for:
- Participation caps
- POV reporting
- Trading cost model
Before scheduling, check whether the parent order can be completed under the participation constraint using expected intraday liquidity.
[ q^{max}i = p{\text{max}} \times V_i ]
[ Q_{max} = \sum_i q^{max}_i ]
- If ( Q \le Q_{max} ): proceed with full schedule
- If ( Q > Q_{max} ):
- Generate a partial schedule only (through market close)
- Display a feedback box below user input:
Feedback Box
- Status:
Cannot complete order within participation constraint - Requested shares:
Q - Max executable shares today:
Q_max - Unfilled shares:
Q - Q_max
Cost and VWAP comparisons are calculated only on executed shares.
[ T = \left(\frac{Q}{p_{\text{max}} \times ADV}\right) \times 390 ]
Where:
T= minutes to complete tradeQ= parent order sizeADV= average daily volumep_max= max participation rate390= minutes per trading day
[ N = \left\lfloor \frac{T}{\text{bin_minutes}} \right\rfloor ]
[ q = \frac{Q}{N} ]
For each bucket i:
[ q_{\text{executed},i} = \min\left(q,\ p_{\text{max}} \times V_i,\ \text{remaining shares}\right) ]
[ POV_i = \frac{q_{\text{executed},i}}{V_i} ]
This realized POV% is reused directly in the trading cost model.
For each intraday bar j:
[ \text{price}_j = \frac{H_j + L_j + C_j}{3} ]
Compute VWAP using all intraday bars from start_time through the final executed slice end time:
[ VWAP_{\text{window}} = \frac{\sum_j (\text{price}_j \times \text{volume}_j)} {\sum_j \text{volume}_j} ]
This is the only VWAP used for benchmarking.
[ C_i = \text{halfspread} + G \times S \times POV_i ]
Where:
| Variable | Description |
|---|---|
halfspread |
Half of quoted bid-ask spread (bps) |
G |
Impact coefficient |
S |
Volatility over the time slice |
POV_i |
Realized participation rate from schedule |
- Compute log returns over matching intraday intervals for the last 20 trading days:
[ L_x = \ln\left(\frac{P_x}{P_{x-1}}\right) ]
- Compute standard deviation:
[ S = \text{stdev}(L_x) ]
| Liquidity Bucket | ADV | G |
|---|---|---|
| MEGA | > 50M | 0.10 |
| LARGE | 10–50M | 0.25 |
| MID | 2–10M | 0.50 |
| SMALL | 0.5–2M | 0.90 |
| MICRO | ≤ 0.5M | 1.50 |
| Liquidity Bucket | Halfspread |
|---|---|
| MEGA | 0.5 |
| LARGE | 1.0 |
| MID | 2.0 |
| SMALL | 5.0 |
| MICRO | 7.5 |
Costs are computed in basis points and converted using the single VWAP benchmark.
[ \text{TotalCost}{$} = \sum_i \left( q{\text{executed},i} \times \frac{C_i}{10{,}000} \times VWAP_{\text{window}} \right) ]
Let:
[ \Delta P = \frac{\text{TotalCost}{$}}{\sum_i q{\text{executed},i}} ]
-
Long (Buy): [ P_{\text{TWAP,allin}} = VWAP_{\text{window}} + \Delta P ]
-
Short (Sell): [ P_{\text{TWAP,allin}} = VWAP_{\text{window}} - \Delta P ]
-
Feedback Box (if insufficient liquidity)
- Requested shares
Q - Max executable shares
Q_max - Unfilled shares
Q - Q_max
- Requested shares
-
Execution Schedule Table
- Time bucket
- Slice size
- Cumulative shares
- Expected bucket volume
V_i - POV%
- Expected slice cost (
C_i, bps)
-
Schedule Chart
- Bars: shares executed per slice
- Optional cumulative overlay
-
Expected Cost Summary
- Total expected cost (bps and $)
- Expected cost per share
-
Benchmark vs VWAP
- ( VWAP_{\text{window}} )
- ( P_{\text{TWAP,allin}} )
- Relative performance (bps and $), direction-aware:
- Long: lower than VWAP is better
- Short: higher than VWAP is better
- Intraday volume is estimated from historical data (expected liquidity)
- VWAP is OHLCV-approximated
- No order book, queue priority, or adverse selection modeling
- Expected costs, not realized outcomes
- Execution research and education
- Strategy prototyping
- Market impact intuition
Not intended for live trading or production execution.