Repository navigation
VWAP
VWAP (Volume-Weighted Average Price) is the ratio of the cumulative price--volume product to the cumulative volume over a given trading session. It represents the average price at which a security has traded throughout the day, weighted by the volume at each price level.
In Navier-Stocks, VWAP serves as the anchor line for the breakout detection engine. When the 1-minute candle close crosses decisively above VWAP (with volume confirmation), a long intent may be generated; conversely, a close below VWAP may trigger a short intent.
For a sequence of
When working with OHLCV candles instead of raw ticks, the closing price is used as the representative price:
An alternative uses the typical price of each candle:
| Value | Meaning |
|---|---|
| Price |
Fair value — no directional bias |
| Price |
Buyer-dominated session; possible bullish momentum |
| Price |
Seller-dominated session; possible bearish momentum |
The VWAP Band measures how far the current price has strayed from VWAP:
TickStore.RecentPrices() + RecentVolumes()
│
▼
VWAP(prices, volumes) ────► VWAPResult.VWAP
│
▼
VWAPBand(price, vwap) ────► deviation, deviation%
│
▼
Breakout Detector (1.6) ──► signal.intent.*
The breakout detector checks:
- VWAP crossover: The 1-min candle close crosses above (long) or below (short) the VWAP line.
-
Volume confirmation: The candle volume must be at least
$2\times$ the rolling 10-minute volume SMA (see Volume Breakout).
For live tick-by-tick processing, a CumulativeVWAP accumulator maintains running sums:
Each new tick updates both sums and returns the latest ratio immediately. This avoids re-scanning the full history on every tick.
File: src/analysts/quantitative/indicators/vwap.go
| Function | Input | Returns |
|---|---|---|
VWAP |
prices []float64, volumes []int64 |
VWAPResult{VWAP, TotalVolume, PriceVolume, Valid} |
VWAPFromCandles |
candles []Candle |
VWAPResult (uses close) |
VWAPFromCandlesTypical |
candles []Candle |
VWAPResult (uses typical price) |
CumulativeVWAP.Add |
price float64, volume int64 |
updated VWAP float64
|
VWAPBand |
price, vwap float64 |
deviation, deviationPct float64 |
Underlying math primitives: src/pkg/math/math.go — WeightedAverage() powers the core computation.
| Condition | Behaviour |
|---|---|
| Empty input slices | Valid = false |
| Mismatched price/volume lengths | Valid = false |
| Total volume = 0 | Valid = false |
| Single tick | VWAP = tick price (trivial) |
| Zero volume ticks | Contribution ignored (price × 0 = 0) |
| VWAP = 0 in VWAPBand | Returns (0, 0) to avoid division by zero |
- Volume Breakout Indicator — downstream volume confirmation
- Bollinger Bands Indicator — complementary volatility bands
-
src/analysts/quantitative/indicators/vwap_test.go— comprehensive test suite -
wiki/High-Level-Design.md— architecture placement description
- Home
- Core Architecture
- Indicator Reference
-
Developer Sandbox
- Local Environment & Quickstart (Pending)
- Testing & Backtesting Strategy (Pending)
-
Operational Systems
- Infrastructure Runbook & Recovery (Pending)