Distribution shift

Distribution shift is an alert that checks every 1 hour and fires at most once per bar.

statistics and matrices

distribution-shift.abx
1alert "Distribution shift"
2check: every 1h
3repeat: once per bar
4warmup: 300
5
6r = returns(close)
7skewness = skew(r, 100)
8tails = kurtosis(r, 100)
9memory = autocorrelation(r, 100, lag: 1)
10
11when abs(skewness) > 1 and tails > 5:
12notify "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}".

Try this in the Terminal. AlgoBars is free: $0 a month, no card needed.

Create my free account