Free lesson · On-chain markets
Time-weighted reference prices
Open interactive lessonPractice calculationsExplore labs
Start with the idea
A time-weighted average gives longer-lived prices more influence than brief prices. It reduces sensitivity to a momentary observation while introducing lag.
Symbols, units & horizon
- P_i: reference price USD/base during interval i
- Δt_i: interval duration in seconds
- P-bar_T: arithmetic time-weighted USD/base average over the full covered horizon
- intervals nonoverlapping and exhaustive
When and why to use this
Reconstruct reference observations and compare lag, manipulation sensitivity and data availability.
A time-weighted average gives longer-lived prices more influence than brief prices. It reduces sensitivity to a momentary observation while introducing lag.
For a piecewise-constant arithmetic reference, weight each price by the duration it was in force. This is not the same as trade-volume weighting.
Protocols can average ticks/log prices, use cumulative observations or rely on off-chain aggregators. The arithmetic example should not be substituted for a protocol-specific geometric or median construction. Document update and availability times.
Time-weighted reference prices
- Multiply each price by seconds spent at that price.
- Sum price-time areas and total covered seconds.
- Divide area by duration and inspect missing intervals separately.
Price $100 for 30 seconds and $110 for 10 seconds gives (3000+1100)/40=$102.50, not the unweighted average $105.
Apply it in a strategy
- Reconstruct reference observations and compare lag, manipulation sensitivity and data availability.
- Record the input timestamp, executable quantity, currency and horizon. Reconcile the result with a cash-flow or state table.
- Stress this failure condition: Averaging cannot create reliable information if underlying liquidity is thin or input prices are systematically distorted.
Research deliverable
Build and explain a time-weighted reference prices worksheet. Reconstruct reference observations and compare lag, manipulation sensitivity and data availability.
Evidence boundary: Synthetic arithmetic and scenarios illustrate mechanics. They are not historical returns, a paper replication, or evidence of an executable edge. Research sources and their access limitations are recorded at the end of this module.
Python implementation
Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.
# Python 3.10+; standard library unless NumPy is imported below.
# Inputs and outputs use the units defined in this lesson. Synthetic teaching example.
def arithmetic_twap(prices,durations):
if not prices or len(prices)!=len(durations) or any(p<=0 for p in prices) or any(t<=0 for t in durations): raise ValueError("Aligned positive intervals required")
return sum(p*t for p,t in zip(prices,durations))/sum(durations)
print(arithmetic_twap([100,110],[30,10]))Continue learning
On-Chain Markets: Data, Oracles and Execution — all lessons- Raw token amounts and economic event types
- Transaction gas in a reporting currency
- Minimum output and ordering risk
- Time-weighted reference prices
- Stale oracle health versus executable collateral value
- Bridge fragmentation and capital lock-up
- Inclusion, finality and conditional loss scenarios
- A reproducible on-chain economics study
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations