I would like to know if there is any technique which is capable to detect online (i.e. considering a sliding window) if there is a correlation between two time series. In particular, I'm trying to detect when there is an inversion between the tendency of the two time series, i.e. when the two time series are negatively correlated according to the Spearman Correlation coefficient.
To be more precise, considering the figure I've reported, I would like to detect as soon as possible (i.e. through an online detection algorithm) when the situations represented by the two yellow ovals.
In normal condition, this two time series as more or less the same trend (they differ only in term of amplitude as you can see in the figure), but there are particular situations (that I injected during the experiments) which cause these possible situations:
The green time series grows with the blu one, but after few seconds the green time series decreases and instead the blue one maintains its normal behaviour (situation represented by the big oval). This happens a few second after I've injected the particular condition, i.e. at time 600.
The green time series decreases with the blu one when I've returned to the situation of normal operation, i.e. at time 1400, and after few seconds the green time series goes below the blue one which instead maintains its normal behaviour (situation represented by the small oval).
So, I know what cause this inversion in the behavior of the two time series because I injected such a situation, but I'm interested in how I can detect as quickly as possible (so with few samples) when such a inversion occurs.
Have you any idea on what could be the right technique to adopt?