The Index That Rounded Itself Poor — Python Bug Hunt

Inspired by the Vancouver Stock Exchange index, which truncated to three decimals after every single trade in 1982 — and quietly lost half its value in 22…

  • Language: Python
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Floating Point, Rounding
  • Modelled on: Vancouver Stock Exchange
  • Visible tests: tiny ticks accumulate at full precision; display rounds instead of truncating; plain arithmetic still works
  • Reward: 50 XP for a complete fix

Briefing

Inspired by the Vancouver Stock Exchange index, which truncated to three decimals after every single trade in 1982 — and quietly lost half its value in 22 months while the market went up.

index_calc.py applies deltas to the index. Precision must be kept in full and rounded only for display.

Bug report

BUG-VSE-1982 · Priority: High · Reported by: quant desk

  • apply_deltas(start, deltas): accumulate at FULL precision
  • display(value): round (not truncate!) to 3 decimals, only here

Observed: truncation inside the loop bleeds value on every update. Five +0.0006 ticks from 1000.0 should display 1000.003 — we show 1000.0.

Logs

[index] 22 months of drift: computed 524.811, true value 1098.892

The code as shipped

src/market/index_calc.py (editable)

# Maintains the exchange index.

def apply_deltas(start, deltas):
    value = start
    for d in deltas:
        value = int((value + d) * 1000) / 1000
    return value

def display(value):
    return int(value * 1000) / 1000

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Python bug hunts.