ta
ta copied to clipboard
Mistake in computing On-balance volume (OBV)
https://github.com/bukosabino/ta/blob/84ced26e07cb676d1033703dfd81e1ee81285b07/ta/volume.py#L84
There is a problem in computing OBV. Regarding the formula from wikipedia (and several other resources that I checked to make sure) when the close price is equal to previous close price, the amount that should be added to obv is 0 but here it adds volume.
I know it's really rare that the close price equals the previous close price but it happens (I ran into a problem using GOOG).
P.S. This is my first issue on the open source community, sorry for any inconvenience in advance. Also, I have the solution for this as well, if you let me do the work I'll appreciate it.
OMG it's not fixed yet? Man, you did good job mentioned it... I don't know why they didn't fix it...
pretty easy solution could be done by
np.where(
self._close < self._close.shift(1), -self._volume,
np.where(self._close == self._close.shift(1), 0, self._volume)
)
It should be fixed ... In intraday data (and in non-liquid tickers) previous close can be equal to the next close a lot.