Rs
Module 9Covariance & CorrelationLesson 4 of 820 min

Covariance

Aligned return series and sample covariance.

Formula

Cov(x,y) = 1/(n-1) * sum (x_i - mean_x)(y_i - mean_y)

Requirements

Same length, aligned timestamps (in real systems: join on time).

Challenge

Assert length mismatch panics — or return Result instead.

Tips
  • zip pairs series
  • n-1 sample cov
  • Alignment is a data problem

Try it live

CovarianceRust 2021
Loading editor…
Output
Press Run to compile and execute.