Docs

ta.cov

Measure how two series vary together, in the product of their units.

itm
ta.cov(a, b, length, min=length)

Rolling population covariance of a and b over the window (divisor length, matching ta.stdev and ta.variance). ta.beta computes this internally and divides it away. This exposes it, in the product of the two series' units. Take it over returns, not levels, unless you mean the levels. Moments are population moments over the valid pairs.

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeDefaultRangeDescription
aSeriesnumber--The series to read.
bSeriesnumber--The series to read.
lengthConstantnumber-1 to 10000Window in observed bars.
minConstantnumber-1 to 10000Valid pairs the window must hold before it reports (an option, written min=40). Pairs with an na on either side are skipped. Absent = length: the window must be full and gap-free, which is the reset rule.

Output

NameType
valuenumber

Warm-up and missing values

Warm-up
length bars. Names in the warm-up are this operator’s parameters.
Missing values
Returns na until the last length bars hold at least min pairs where both series are present. Pairs with an na on either side are skipped. With min absent (= length) that is length consecutive valid pairs, so an na in either series resets the window. Covariance is defined on any window, so there is no zero-variance case.

Example

itm
ta.cov(ta.ret(close), ta.ret(open), 50)
itm
spy = series(symbol="SPY")
plot(ta.cov(ta.ret(close), ta.ret(spy.close), 50), "Covariance 50")