Docs

ITMScript

Measure rolling beta to SPY

Measure how much a symbol moves for each move in SPY, as a rolling beta of returns.

Measure how far this symbol moves for each unit that SPY moves, over a rolling window of returns.

itm
//@itmscript 2
study("Rolling beta", overlay=false)
len = input.int(60, "Window", min=10, max=500)
step = input.int(1, "Return length", min=1, max=20)
bench = series(symbol="SPY")
own = ta.ret(close, step)
other = ta.ret(bench.close, step)
beta = ta.beta(own, other, len)
plot(beta, "Beta to SPY", color=color.purple, width=2, style=line)
hline(1, "Moves with SPY", color=color.gray, style=dashed)
hline(0, "No link", color=color.gray, style=dotted)

What you see

A purple line in its own pane shows the beta. A dashed line marks one and a dotted line marks zero. At one the symbol has moved as far as SPY. Above one it has moved further. Below one it has moved less. Below zero it has moved the other way.

The beta is taken over returns. The same arithmetic over prices gives a different number with a different use. The line starts once the window has filled.

Change these inputs

  • Window. The number of bars in the rolling window, from 10 to 500.
  • Return length. The number of bars each return spans, from 1 to 20. At 1 each return is the change from one bar to the next.

The benchmark is written in the script. Replace SPY in the series line to measure against another symbol.