Quite some time ago I implemented the analysis described in [1] in R. It was long and unreadable -- I reimplemented it in Python in 46 lines. The function local_uncertainty calculates the next state uncertainty after a measured trajectory ngram. An ngram describes the quantised stock movements of the last n days, e.g. for 5 days. The local uncertainty h_5 then describes the uncertainty of the next symbol.

The example usage below describes the analysis from the paper.

importlocalorderfrompandasimportSeriesdefpart(x):ifx<-0.0025:return0elifx>0.0034:return2else:return1# get returns series and quantiseret=Series(log(dji['DJI.Close'])).diff(1)dji_binary=map(part,ret)# local uncertainty of the 6th symbol when 5 symbols have been seenorder=localorder.local_uncertainty(dji_binary,5,3)

Looking at the local uncertainty time series shows a similar plot than in the paper. The uncertainty is mostly very close to one, with occiasional dips below 90%.

References

[1] Lutz Molgedey and Werner Ebeling, Local Order, Entropy and Predictability of Financial Time Series, Eur. Phys. J. B 15, 733–737