Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

Optiver interview question

Backtest a momentum strategy that allocates by yesterday's positive returns

Company:
Optiver
Type:
Coding
Difficulty:
Medium
Reported:
October 19, 2026

Problem

You are given daily closing prices for several assets: prices[t][i] is the price of asset i on day t. Backtest the following momentum strategy.

  • The return of asset i on day t, for t >= 1, is r[t][i] = prices[t][i] / prices[t - 1][i] - 1.
  • On each day t >= 2, all capital is allocated across the assets in proportion to their positive returns on the previous day: the weight of asset i is max(r[t - 1][i], 0) divided by the sum of these values over all assets.
  • The strategy's return on day t is R[t] = sum_i weight_i * r[t][i], and its daily log return is log(1 + R[t]).

Return the average of the daily log returns and their standard deviation. Either the population standard deviation (dividing by the number of daily log returns) or the sample one (dividing by that number minus 1) is accepted, as long as you say which one you use; the examples give both.

The rule for a day after which no asset had a positive return is not specified; any stated choice is accepted, for example holding cash for that day. The examples avoid this case.

Example 1

Input:  prices = [[100, 100], [110, 90], [121, 99], [108.9, 118.8]]
Output: mean = 0.072050, std = 0.023260 (population) or 0.032894 (sample)

Day 2 puts everything in asset 0, the only riser on day 1, and earns 10%; day 3 splits 50/50 after both assets rose 10% and earns 0.5 x (-10%) + 0.5 x 20% = 5%, so the log returns are 0.095310 and 0.048790.

Example 2

Input:  prices = [[10, 20, 40], [11, 20, 44], [11, 21, 33]]
Output: mean = -0.133531, std = 0 (population; the sample version is undefined for a single value)

Assets 0 and 2 both rose 10% on day 1, so day 2 holds them half and half and returns 0.5 x 0% + 0.5 x (-25%) = -12.5%; log(0.875) = -0.133531.

Constraints

  • Every price is positive.
  • With fewer than three days of prices there is no trading day; report that case in any clear way.
  • There are no transaction costs.

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern