Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find a Bug in Code

MediumCoding00:00
Practice interviewer
In session
5 left
00:00

Your question is Find a Bug in Code. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

Two Sigma engineers spend as much time reading quantitative code as writing it. You're reviewing a teammate's function that computes a rolling volume-weighted average price (VWAP) for a trade blotter before it feeds the next backtest run.

def rolling_vwap(trades, window=5, seen_symbols=[]):
    results = []
    for i in range(len(trades)):
        seen_symbols.append(trades[i]["symbol"])
        start = i - window
        chunk = trades[start:i]
        total_value = sum(t["price"] * t["volume"] for t in chunk)
        total_volume = sum(t["volume"] for t in chunk)
        vwap = total_value // total_volume
        results.append(vwap)
    return results, seen_symbols

Find every bug in this function and explain what a backtest run would actually show because of each one, before describing your fix.