FastPrepDebug the Tape Cleaner
Problem · Database

Debug the Tape Cleaner

MediumMillennium logoMillenniumNEW GRADOA

Problem statement

The desk runs clean_tape over the raw market-data tape before any strategy reads it. It has been in production for months. Recently the traders have started reporting occasional bad prints slipping through, stale fills appearing at the wrong time, the odd zero or negative price reaching the book, and a few rows that simply look wrong. Most of the time the output looks fine, which is why nobody caught it sooner. Your job is to find out what the cleaner is getting wrong and fix it.

The Job

clean_tape(prices) already ships (it is in the editor). It is supposed to satisfy the spec below exactly. It does not. Diagnose where it diverges and repair it so that it meets the contract for every input, not just the easy ones.

The Contract

Given a raw price tape, clean_tape must return a cleaned table that obeys all of these rules, in this order:

  1. Sort the rows ascending by timestamp.
  2. Drop duplicate timestamps, keeping the first occurrence after sorting.
  3. Treat any price that is zero or negative as missing.
  4. Forward-fill each asset column from its last valid (post-sort) price.
  5. A leading missing value with no prior valid price stays null (it cannot be filled).

Forward-fill means: if a price is missing, carry forward the most recent valid price for that asset. Each asset column is filled independently.

Table schema

MySQLPostgreSQLPandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

prices

Raw tape rows in arbitrary table order; source_row preserves arrival order.

ColumnTypeNullableDescription
source_rowPKIntegerNoUnique arrival-order position in the raw tape.
timestampIntegerNoMilliseconds since the session opened.
asset_1DecimalYes
asset_2DecimalYes
asset_3DecimalYes

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
row_indexIntegerNo
timestampIntegerNo
asset_1DecimalYes
asset_2DecimalYes
asset_3DecimalYes

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • Input Format: prices is a pd.DataFrame with these columns.
  • timestampint — Milliseconds since session open.
  • FastPrep execution-adapter details (not visible in the source image): The input contains between 1 and 2000 rows.
  • source_row values are unique positive integers and preserve source arrival order when timestamps tie.
  • Each asset value is an exact decimal or NULL.
  • The returned columns are row_index, timestamp, asset_1, asset_2, and asset_3.

More Millennium problems