LIVE
connecting to the live quote stream…
--:--:--UTC
easyTrading○
#39

VWAP

easyTradingacceptance —~15 min

Implement vwap(bars) — the session volume-weighted average price. Each bar is [high, low, close, volume]; use the typical price (high + low + close) / 3 for the bar and weight it by the bar's volume: Σ typical·volume / Σ volume.

VWAP is the benchmark every execution desk is measured against, and the line this site once drew wrong — the confession is at /learn/broken-vwap. Return the price rounded to 4 decimal places.

example 1
input
bars=[[101.0, 99.0, 100.0, 1000.0], [102.0, 100.0, 101.0, 1000.0], [103.0, 101.0, 102.0, 1000.0]]
output
101
example 2
input
bars=[[101.0, 99.0, 100.0, 3000.0], [102.0, 100.0, 101.0, 1000.0], [103.0, 101.0, 102.0, 500.0]]
output
100.4444
note

Three times the volume traded at the low bar — the VWAP has to sit lower than the plain average.

constraints
  • 1 ≤ len(bars) ≤ 390
  • total volume > 0
teacher · 3 hints · the first is free
↗ read the theory
the chapter this problem is cut from
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to vwap()
bars=[[101.0, 99.0, 100.0, 1000.0], [102.0, 100.0, 101.0, 1000.0], [103.0, 101.0, 102.0, 1000.0]]
expected
101

the judge calls vwap() with exactly these inputs · outputs are compared to 6 decimal places

● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice