← 返回 optiver 的题目列表Proportional Momentum Investment
类型:online_judge
You manage a fund containing N stocks. You are given an N × T matrix prices of positive prices, where prices[i][t] is the closing price of stock i on trading day t.
The fund follows this one-day-lagged momentum strategy:
For the holding period from the close of day t-1 to the close of day t (t >= 1), positions are determined by returns from the preceding day.
For t = 1, no earlier return is available, so the fund holds only cash and its portfolio return is 0.
For t >= 2, compute each stock's previous-day simple return:
r[i][t-1] = prices[i][t-1] / prices[i][t-2] - 1
If r[i][t-1] > 0, the stock's raw weight is r[i][t-1]; otherwise, its raw weight is 0.
If at least one raw weight is positive, normalize all positive raw weights to sum to 1. If none is positive, hold all capital in cash.
During period t, the portfolio simple return is:
R[t] = Σ(weight[i] × (prices[i][t] / prices[i][t-1] - 1))
Cash has return 0.
The portfolio log return for period t is log(1 + R[t]).
Compute, over all T-1 holding periods:
the arithmetic mean of daily portfolio log returns; and
the population standard deviation of those log returns, using denominator T-1 rather than T-2.
Print the two values separated by a space and rounded to six decimal places.
Input Format
First line: integers N and T.
Next N lines: T positive floating-point prices for one stock.
Constraints
1 <= N <= 1000
2 <= T <= 1000
All prices are positive.
Example
Input:
2 3
100 115 117.3
200 210 199.5
Output:
0.001248 0.001248
For the first holding period, no historical return exists, so the fund holds cash and has log return 0. For the second period, the previous-day returns are 15% and 5%, giving weights 0.75 and 0.25. The portfolio simple return is 0.75 × 2% + 0.25 × (-5%) = 0.25%, and the log return is log(1.0025).
Example
Input
2 3
100 115 117.3
200 210 199.5
Output
0.001248 0.001248