FastPrepRange of a Third Correlation

Range of a Third Correlation

Tower Research Capital logoTower Research Capital● EasyINTERNPHONE SCREEN

Problem statement

Three random variables x1, x2 and x3 each have a positive, finite variance. You know r12 = corr(x1, x2) and r23 = corr(x2, x3), but not corr(x1, x3).

A value is possible for corr(x1, x3) when some joint distribution of the three variables has all three correlations at once. The possible values form one closed interval. Return its two ends as [low, high], with low <= high.

Each returned number is accepted within 10^-9 of the exact value.

Function

correlationRange(r12: double, r23: double) → double[]

Examples

Example 1

r12 = 0.5r23 = 0.5return = [-0.5,1.0]

This is the case from the interview. The two ends of the range are r12 * r23 minus and plus sqrt((1 - r12^2) * (1 - r23^2)). Here r12 * r23 = 0.25 and sqrt(0.75 * 0.75) = 0.75, so corr(x1, x3) can be anything from 0.25 - 0.75 = -0.5 to 0.25 + 0.75 = 1. The upper end is reached when x1 and x3 are the same variable.

Example 2

r12 = 0.6r23 = 0.8return = [0.0,0.96]

Here r12 * r23 = 0.48 and sqrt((1 - r12^2) * (1 - r23^2)) = sqrt(0.64 * 0.36) = 0.48, so the range is [0, 0.96]. Even though both given correlations are positive, x1 and x3 can be uncorrelated, but they cannot be negatively correlated.

Example 3

r12 = -0.6r23 = 0.8return = [-0.96,0.0]

Flipping the sign of x1 flips the signs of corr(x1, x2) and corr(x1, x3). So this range is the previous one with signs flipped and its ends swapped: [-0.96, 0].

Constraints

  • -1 <= r12 <= 1
  • -1 <= r23 <= 1

More Tower Research Capital problems

See Tower Research Capital hiring insights
Saved
public double[] correlationRange(double r12, double r23) {
    // Write your code here.
}
Checking account…