TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.49k stars 1.74k forks source link

Volume Indicators ADA / OBV - extra inconsistent with slightly different time window #513

Open MichalRIcar opened 2 years ago

MichalRIcar commented 2 years ago

Hi,

I am checking the consistency of results with slightly different time windows and especially ADA/OBV volume indicators are providing extremely different results.

E.g. Data set → Having a time window of 5000 observations where t0 is the present moment and t4999 is a 5000th-time unit in the past. Result1: checking the very last calculation of AD/OBV (i.e. in t0). Result2: checking the very last calculation of AD/OBV, (i.e. in t0), however, this time we deleted the very first obs 5000 (t4999).

In the financial dynamics and indicator sense, the observation from the very beginning of the time series at t4999 shouldn't have any impact on the present value in t0, but that is not the case in the indicators AD/OBV.

I have checked the illustration calculation in excel and it seems that the algo is using the fixed value from the very beginning of the data regardless of the length or is there any other reason for the incosistency?

I am curious if you consider a dynamic "beginning" for the indicator calculation rather than keep it at the one fixed point forever.

The implications for real-world calculations are quite huge and in our case indicators with fixed beginning can't be used.

Thank you for Your ideas, and opinion.

Best, Michal

mrjbq7 commented 2 years ago

I think that's how those indicators are defined.

For example, in OBV:

https://github.com/TA-Lib/ta-lib/blob/master/src/ta_func/ta_OBV.c#L267

/* Generated */    prevOBV  = inVolume[startIdx];
/* Generated */    prevReal = inReal[startIdx];
/* Generated */    outIdx = 0;
/* Generated */    for(i=startIdx; i <= endIdx; i++ )
/* Generated */    {
/* Generated */       tempReal = inReal[i];
/* Generated */       if( tempReal > prevReal )
/* Generated */          prevOBV += inVolume[i];
/* Generated */       else if( tempReal < prevReal )
/* Generated */          prevOBV -= inVolume[i];
/* Generated */       outReal[outIdx++] = prevOBV;
/* Generated */       prevReal = tempReal;
/* Generated */    }
MichalRIcar commented 2 years ago

I see, thank you. Then it behaves a little bit randomly when plugged into dynamic computation with moving (time dynamic) underlying data. Good to know!

mrjbq7 commented 1 year ago

If you operate the indicator on a sliding fixed window, maybe using the stream API then I bet you get the consistent numbers you are looking for.

On Apr 14, 2022, at 11:28 AM, MichalRIcar @.***> wrote:

 I see, thank you. Then it behaves a little bit randomly when plugged into dynamic computation with moving (time dynamic) underlying data. Good to know!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

MichalRIcar commented 1 year ago

Thx for the hint! In the end, I solved it by removing all TA indicators conditioned by time window length. Luckily the impact to the overall ML performance is negligible as an algo substituted kicked predictors by different sets with the overall same performance..