Proportional Momentum Investment Statistics
Updated
Problem statement
You are given an N x T matrix of positive asset prices. Row i contains the prices of asset i on consecutive days.
Compute one portfolio log return for every day transition from day 0 to day T - 1:
- For the first transition, hold cash, so the portfolio return is 0.
- For transition
t, wheret >= 2, compute each asset's simple return over the preceding transitiont - 1. Ignore nonpositive returns. If no asset had a positive return, hold cash. - Otherwise, assign each positive-return asset a weight equal to its preceding return divided by the sum of all positive preceding returns. Apply those weights to the asset's simple return over transition
t. - Convert the resulting portfolio simple return
rtoln(1 + r). A cash transition has log return 0.
Return [mean, standardDeviation] over all T - 1 daily log returns. Use the population standard deviation, divide by T - 1, and round both outputs to five digits after the decimal point using half-up rounding.
Function
proportionalMomentumStatistics(prices: double[][]) → double[]Examples
Example 1
prices = [[100.0,115.0,117.3],[200.0,210.0,199.5]]return = [0.00125,0.00125]The first transition stays in cash. The preceding positive returns for the second transition are 15% and 5%, so the weights are 0.75 and 0.25. The portfolio simple return is 0.0025 and its log return is about 0.00249688; the mean and population deviation of that value with the initial zero both round to 0.00125.
Constraints
1 <= N <= 2002 <= T <= 10000- Every row has exactly
Tvalues. - Every price is finite and in
[10^-6, 10^9]. - Every weighted portfolio simple return is greater than -1.
- Each unrounded result is at least
10^-10away from a half-way five-decimal rounding boundary.
More Optiver Online Assessment questions
- Overheat Prevention ControllerOA · Seen Nov 2026
- Power Cell BankOA · Seen Nov 2026
- Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026
- Fastest Average Speed over a Rolling KilometerOA · Seen Sep 2026
- Multi-Level Inventory Storage SystemOA · PHONE SCREEN · Seen Aug 2026
- Count Bounded Share TransactionsOA · Seen Aug 2026
- Count Ordered Size SequencesOA · Seen Aug 2026
- Profitable Currency Exchange CycleOA · Seen Aug 2026
- Construct Binary Tree S-ExpressionOA · Seen Jul 2026
- Days BetweenOA · Seen Jul 2026
Similar questions at other companies
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions
- Daily Settlement for Long and Short PositionsBelvedere Trading · OA
- Prime Factor VisitationMaven Securities · OAMaven Securities interview questions
- Sort an Array with Rotate and FlipAmazon · OA
- Total Waiting Time for Handmade ItemsMicrosoft · OAMicrosoft interview questions
- Prefix Scores With the Running MaximumC3.ai · OAC3.ai interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions