balipour

Durbin Watson Test Statistic [pig]

In statistics, the Durbin–Watson statistic is a test statistic used to detect the presence of autocorrelation at lag 1 (AR(1) process) in the residuals (prediction errors) from a regression analysis. With the new array function tradingview implemented, we are able to do our calculations on the residuals.

The residual is given by subtracting the actual value (in this case it's log returns) from the prediction value (generated by linear regression ). The following chart displays who we get the error term from the regression.
Then we do our calculation based on the residuals. The formula is basically sum of squared of the difference between error and it's 1 lagged term divided by sum of squared of all the error terms. It's a very simple test on residual sum of squares. The value you get is from 0 to 4.
When DW > 2, there's a possible negative autocorrelation.
When DW < 2, there's a possible positive autocorrelation.
Note: above 2 and below 2 is only possible autocorrelation, it might not be statistically significant.

If we want to know if the autocorrelation presence is significant or not. We need a Durbin Watson Stats Table. Based on the lookback period you use, you can find the critical value on the table (usually the first column).
Durbin Watson 0.05 Table
For the default setting 30 lookbacks, the 5% critical level for positive autocorrelation is 1.35. (We round to 1.4 on the default setting for convenience ). The other side for negative autocorrelation is just 4 - 1.35 = 2.65 due to its symmetry. For other lookbacks like 50, the critical value is 1.5 and 2.5, we just need to check the table to find the corresponding value. The user only has to find the lower threshold, the indicator will automatically give you the 4- lower threshold value on the other side.

As we have mentioned in the autocorrelation function and Hurst exponent . Positive autocorrelation means positive returns are more likely to be followed by positive returns and negative returns are more likely to be followed by negative returns. People may call it trending. Negative autocorrelation means positive returns are more likely to be followed by negative returns and negative returns may be followed by positive returns. People may call it mean-reverting.
The Durbin Watson test only tests the first-order autocorrelation. But there might also be significant autocorrelation in other lagged values. You can see the autocorrelation of other lags in our ACF.
We may also publish more advanced autocorrelation tests in the future.
發布通知: A typo in graph one displaying the error as distance between the points and the regression line. "E5" should be "E3".
發布通知: Implemented 0.05 Significance Dubrin Watson Statistics Table in the code. No need to check the table or type in the critical value. The value will be automatically adjusted according to the lookback period.

Changed the color theme.

White means DW > 2, possible - autocorrelation / mean reversion
Orange means DW < 2, possible + autocorrelation / trending

Blue background means DW > upper critical value, Significant - autocorrelation / mean reversion
Red background means DW < lower critical value, Significant + autocorrelation / trending


開源腳本

本著真正的TradingView精神,該腳本的作者將其開源發布,以便交易者可以理解和驗證它。為作者喝彩吧!您可以免費使用它,但在出版物中重複使用此代碼受網站規則的約束。 您可以收藏它以在圖表上使用。

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?