PIXELBANKv9.1.0
Menu

Return Standardization Baseline

Problem Statement

A common variance-reduction trick standardizes the batch of returns before using them as weights:

G^i=Gi−μσ+ϵ\hat{G}_i = \frac{G_i - \mu}{\sigma + \epsilon}

where mu and sigma are the mean and (population) standard deviation of the returns, and epsilon guards against divide-by-zero. Implement standardize_returns(returns, eps) returning the standardized list.

Example:

Input:
standardize_returns([1.0, 2.0, 3.0], 1e-8)
Output:
[-1.2247, 0.0, 1.2247]
Reasoning:
  • Calculate the mean (μ\mu) of the returns [1.0,2.0,3.0][1.0, 2.0, 3.0] to determine the center of the distribution: μ=1.0+2.0+3.03=2.0\mu = \frac{1.0 + 2.0 + 3.0}{3} = 2.0.
  • Compute the population variance by averaging the squared deviations from the mean: var=(1.0−2.0)2+(2.0−2.0)2+(3.0−2.0)23=1+0+13=23≈0.6667\text{var} = \frac{(1.0 - 2.0)^2 + (2.0 - 2.0)^2 + (3.0 - 2.0)^2}{3} = \frac{1 + 0 + 1}{3} = \frac{2}{3} \approx 0.6667.
  • Determine the standard deviation (σ\sigma) by taking the square root of the variance: σ=23≈0.8165\sigma = \sqrt{\frac{2}{3}} \approx 0.8165.
  • Standardize each return value by subtracting the mean and dividing by the sum of the standard deviation and the epsilon guard (10−810^{-8}), which is effectively just σ\sigma:
    • For 1.01.0: 1.0−2.00.8165+10−8≈−1.2247\frac{1.0 - 2.0}{0.8165 + 10^{-8}} \approx -1.2247
    • For 2.02.0: 2.0−2.00.8165+10−8=0.0\frac{2.0 - 2.0}{0.8165 + 10^{-8}} = 0.0
    • For 3.03.0: 3.0−2.00.8165+10−8≈1.2247\frac{3.0 - 2.0}{0.8165 + 10^{-8}} \approx 1.2247
  • The final output is [-1.2247, 0.0, 1.2247]

Constraints:

  • len(returns) >= 1.
  • Use the population standard deviation (divide by N).
  • Return a list of floats.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Return Standardization Baseline - Medium | PixelBank