Dynamic Programming Problems in Trading Interviews

Dynamic programming in trading interviews tests execution, position sizing and price path problems, not a memorized textbook recurrence.

Dynamic programming problems in trading interviews test whether a candidate can spot overlapping subproblems and optimal substructure inside a story about execution, position sizing or price paths, not whether they can recite the recurrence for a textbook coin change problem. The stock trading with cooldown, the exact order-splitting problem and the target position problem below are the three shapes that recur most often, each solvable with a small state per day or per unit of size and a transition that follows directly from the story.

State the problem precisely: given a sequence of daily prices, find the maximum profit achievable with at most k buy-sell transactions, where a share must be sold before it is bought again and a one day cooldown follows every sale before another purchase. The standard approach defines a state for each day and each transaction count that tracks whether a position is held, not held, or in cooldown, with a transition that either holds the current state, sells into cooldown, or buys out of cooldown into a hold. Complexity runs O(n times k) in time and can be reduced to O(k) space by keeping only the previous day's row.

The follow-up almost always removes the cap on k, which changes the profitable strategy entirely: with unlimited transactions the optimal policy collapses to summing every positive day-to-day price difference, since a chain of small profitable trades dominates a few large ones. A candidate who only memorized the k-transaction recurrence has to notice that the state space itself becomes unnecessary once the constraint that motivated it disappears.

State the problem precisely: an order of size S must be filled over T time slices, and executing size x in a given slice costs a known convex function of x reflecting market impact, with the objective to minimize total cost across all slices while filling exactly S. The standard approach defines a state over remaining size and remaining slices, taking the minimum over every way to split the next slice's size, which is O(S squared times T) with a naive nested loop but drops close to O(S times T) once the convexity of the cost function is used to bound the search with a pointer that only moves forward.

The follow-up asks what happens once the cost function also depends on the size executed in the previous slice, modeling the fact that recent trading pressure moves the price further against the next slice. That extra dependency breaks the simple two-dimensional state and forces a third dimension tracking the previous slice's size, and the interviewer is checking whether the candidate notices the dependency before writing code rather than after.