A Trade Blotter, End to End

A reported three-hour assessment is built on pandas data tasks, and the blotter is its archetype: a table of fills, and questions about position, cost and profit. It looks like an exercise in grouping and summing. The part that separates candidates is that "profit" is not defined until you have chosen an accounting convention, and the conventions disagree.

The state a blotter accumulates

Walk the fills in time order and maintain three numbers per instrument: the signed position, the cost basis of what is currently held, and the realised profit banked so far. Each fill does one of three things.

  1. 1
    Adds to the position. The position grows and the cost basis absorbs the new fill. Nothing is realised.
    the common case
  2. 2
    Reduces the position. Part of the basis is released against the fill price, and the difference is realised profit. The position shrinks; the average cost does not change.
  3. 3
    Crosses through zero. The fill closes the whole position and opens a new one on the other side, which is two events in one and is where implementations break.

The rest of this lesson is for subscribers

Unlock every lesson in Programming for Quantitative Developers, and every other premium course.

Subscribe to continue

Test your knowledge

Questions are only available to subscribers.

Keep reading Programming for Quantitative Developers

25 lessons in this course, and every other premium course, on one subscription.

  • Every lesson in every course, with the worked examples and interactive simulators
  • Graded questions on every lesson, with explanations for the wrong answers as well as the right one
  • The trainers, timed assessments and brainteaser library that go with them