ta.cov
Measure how two series vary together, in the product of their units.
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.
| Name | Kind | Type | Default | Range | Description |
|---|---|---|---|---|---|
a | Series | number | - | - | The series to read. |
b | Series | number | - | - | The series to read. |
length | Constant | number | - | 1 to 10000 | Window in observed bars. |
min | Constant | number | - | 1 to 10000 | Valid 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
| Name | Type |
|---|---|
value | number |
Warm-up and missing values
- Warm-up
lengthbars. Names in the warm-up are this operator’s parameters.- Missing values
- Returns na until the last
lengthbars hold at leastminpairs where both series are present. Pairs with an na on either side are skipped. With min absent (= length) that islengthconsecutive 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
ta.cov(ta.ret(close), ta.ret(open), 50)spy = series(symbol="SPY")
plot(ta.cov(ta.ret(close), ta.ret(spy.close), 50), "Covariance 50")