TradingView
QuantNomad
9 Th03 2021 09:53

Hurst Exponent 

S&P 500 IndexTVC

Mô tả

My first try to implement Full Hurst Exponent.

The Hurst exponent is used as a measure of long-term memory of time series. It relates to the autocorrelations of the time series and the rate at which these decrease as the lag between pairs of values increases

The Hurst exponent is referred to as the "index of dependence" or "index of long-range dependence". It quantifies the relative tendency of a time series either to regress strongly to the mean or to cluster in a direction.

In short, depending on the value you can spot the trending / reversing market.
  • Values 0.5 to 1 - market trending
  • Values 0 to 0.5 - market tend to mean revert


Hurst Exponent is computed using Rescaled range (R/S) analysis.
I split the lookback period (N) in the number of shorter samples (for ex. N/2, N/4, N/8, etc.). Then I calculate rescaled range for each sample size.
The Hurst exponent is estimated by fitting the power law. Basically finding the slope of log(samples_size) to log(RS).

You can choose lookback and sample sizes yourself. Max 8 possible at the moment, if you want to use less use 0 in inputs.

It's pretty computational intensive, so I added an input so you can limit from what date you want it to be calculated. If you hit the time limit in PineScript - limit the history you're using for calculations.


####################

Disclaimer
Please remember that past performance may not be indicative of future results.
Due to various factors, including changing market conditions, the strategy may no longer perform as good as in historical backtesting.
This post and the script don’t provide any financial advice.
Bình luận
PineCoders
balipour
Nice try, very good script. I made a rescaled range HE before the array function was implemented on tv. Was going to update my code and publish it but didn't have the time. Now your script does the job with more efficient code. Good job.
Some small suggestions:
Regression slope is best when there are ten or more points on log-log plot.
For rescaled range HE, you can't really tell if there's significant autocorrelation by just looking at if it's above or below 0.5. There's an expected value for rescaled range HE, for 1024 lookback you used, it should be around 0.54. Then you can calculate the standard error of the regression and divide it by the absolute value of HE - 0.54 (expected value) to get the Z score. Or you can just compute a confidence interval around the expected value.
QuantNomad
@balipour, Thanks for your input.
I probably have to optimize code bit more for 10 > points. It can easily hit 200ms bar limit with it.
I'll continue working on it. Confidence interval can be a really nice addition. Will keep you posted with future updates.
jonnatakusuma
Hi,

Great code, quick q...is there an empiric evidence as to why you use a lookback period for 1024? i.e. 4 trading years?

Thanks,
Jon
PineCoders
This publication is now featured in our Editors' Picks: tradingview.com/scripts/editors-picks/ .
In the name of all TradingViewers, thank you for your valuable contribution to the community, and congrats!
oneanalyst
Is there any possibility to make a video about its usage?
QuantNomad
@oneanalyst, I'll try to create a video about it at some point
Merseytrader
How to use this? pls do include some guidance instruction
theheirophant
lookin good homie!
Thêm nữa