Latticework

Command Palette

Search for a command to run...

Financial Markets Fundamentals

Market Structure

16 min

Explanation

At any moment, a market has a bid (the highest price a buyer is currently willing to pay) and an ask (the lowest price a seller is currently willing to accept). The gap between them — the bid-ask spread — is effectively the cost of trading immediately (via a market order) rather than waiting for a better price:

def bid_ask_spread(bid, ask):
    return ask - bid

print(bid_ask_spread(99.98, 100.02))   # 0.04 -- a tight, liquid spread

A narrow spread means the market is liquid — lots of buyers and sellers actively trading, closely agreeing on price. A wide spread signals thin trading and higher cost to transact right now.

Try it

The same absolute spread (a few cents) means very different things on a $12 stock vs. a $150 stock -- in practice spread is often compared as a PERCENTAGE of price, not an absolute dollar amount.

Loading editor…
Explanation

VWAP (Volume-Weighted Average Price) is the average price a security traded at over some period, weighted by how much volume traded at each price — a large trade at one price counts more than a tiny trade at another:

def vwap(prices, volumes):
    return sum(p * v for p, v in zip(prices, volumes)) / sum(volumes)

# three trades during the day: at 100 (10 shares), 101 (20 shares), 99 (10 shares)
print(round(vwap([100, 101, 99], [10, 20, 10]), 2))   # 100.25

VWAP is both a benchmark (fund managers are often evaluated against "did you trade better or worse than VWAP?") and a trading strategy in its own right (large orders get algorithmically split up to trade AT roughly the VWAP, to avoid moving the price against yourself).

Exercise

Write `bid_ask_spread(bid, ask)`, returning `ask - bid` rounded to 4 decimals.

Exercise

Write `vwap(prices, volumes)` — the Volume-Weighted Average Price: `sum(price * volume) / sum(volumes)`, rounded to 4 decimals.

Quiz

Why is a narrow bid-ask spread generally seen as a sign of a liquid, well-functioning market?

Checkpoint

You can compute bid-ask spread as a liquidity signal, and VWAP as a volume-weighted price benchmark.