Docs

ta.hedgeratio

Size a hedge: how many units of one series offset one unit of another.

itm
ta.hedgeratio(y, x, length, min=length)

Rolling ordinary least squares slope of y on x over levels: cov(y, x)/var(x), how many units of x hedge one unit of y. The arithmetic is exactly ta.beta's. It has a separate id because the two are used on different inputs. ta.beta is customarily taken over returns and is a risk exposure. ta.hedgeratio is taken over prices and is a position size. Neither operator checks which 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.

NameKindTypeDefaultRangeDescription
ySeriesnumber--The series to be hedged, in levels.
xSeriesnumber--The hedging series, in levels.
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. na when x has zero variance over the window.

Example

itm
ta.hedgeratio(close, spy.close, 60)
itm
spy = series(symbol="SPY")
plot(ta.hedgeratio(close, spy.close, 60), "Hedge ratio 60")