Aggregate. Returns the sample covariance of a set of number pairs.
covar_samp ( dependent-expression, independent-expression )
dependent-expression | The variable that is affected by the independent variable. The expression accepts only a range of integers. |
independent-expression | The variable that influences the outcome. The expression accepts only a range of integers. |
This function converts its arguments to float, performs the computation in double-precision floating point, and returns a float as the result. If the function is applied to an empty set, then it returns NULL. Both dependent-expression and independent-expression are numeric. The function is applied to the set of (dependent-expression, independent-expression) pairs after eliminating all pairs for which either dependent-expression or independent-expression is NULL.
(SUM(expr1 * expr2) - SUM(expr2) * SUM(expr1) / n) / (n -1)
Here x represents the dependent-expression, y represents the independent-expression, and n represents the number of (x,y) pairs where neither x or y is NULL.
The covariance of a sample may be used to indicate how two specific stocks may move together in the future, which is an important aspect before analyzing the standard deviation of a portfolio as a measure of risk.