Distribution shift
Distribution shift is an alert that checks every 1 hour and fires at most once per bar.
statistics and matrices
1
alert "Distribution shift"2
check: every 1h3
repeat: once per bar4
warmup: 3005
6
r = returns(close)7
skewness = skew(r, 100)8
tails = kurtosis(r, 100)9
memory = autocorrelation(r, 100, lag: 1)10
11
when abs(skewness) > 1 and tails > 5:12
notify "Fat-tailed, skewed returns: skew {skewness:0.00}, kurtosis {tails:0.0}, lag-1 autocorrelation {memory:0.00}"What this script says
Distribution shift is an alert that checks every 1 hour and fires at most once per bar.
It calculates r as the returns of the close, skewness as the skew (source r, length 100), tails as the kurtosis (source r, length 100) and memory as the autocorrelation (source r, length 100, lag 1).
When the absolute value of skewness is above 1 and tails is above 5, it sends the notification "Fat-tailed, skewed returns: skew {skewness:0.00}, kurtosis {tails:0.0}, lag-1 autocorrelation {memory:0.00}".