ta.beta
Estimate how strongly one series moves with another, such as a stock against an index.
ta.beta(y, x, length, min=length)Rolling beta of y against x: cov(y, x) / var(x) over the window, with population moments over the valid pairs. Take it over returns, where it is a risk exposure. The same arithmetic over levels is a position size and has its own id, ta.hedgeratio. Neither operator checks what you passed.
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 |
|---|---|---|---|---|---|
y | Series | number | - | - | The dependent series, usually returns of the chart's instrument. |
x | Series | number | - | - | The reference series, usually returns of the benchmark. |
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. na when x has zero variance over the window.
Example
ta.beta(ta.ret(close), ta.ret(spy.close), 100)spy = series(symbol="SPY")
plot(ta.beta(ta.ret(close), ta.ret(spy.close), 100), "Beta 100")