Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing an issue with the crossover indicator in python 3.7 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

demattia
Copy link

The current version of the crossing indicator failed in Python 3.7.6 with numpy 1.18.1 and 0.25.3. The error is due to computing the difference of two boolean arrays in the modified line.

data["mcross"] = btalib.crossover(data["macd"], data["macd_signal"]).crossover
  File "/home/demattia/miniconda3/envs/yuco/lib/python3.7/site-packages/btalib/indicator.py", line 152, in __call__
    b_init(self, *args, **kwargs)
  File "/home/demattia/miniconda3/envs/yuco/lib/python3.7/site-packages/btalib/indicators/crossover.py", line 108, in __init__
    self.o.crossover = self._cup - self._cdown
  File "/home/demattia/miniconda3/envs/yuco/lib/python3.7/site-packages/btalib/meta/lines.py", line 129, in real_binary_op
    result[minidx:] = r = binop(other, *args, **kwargs)  # exec / store
  File "/home/demattia/miniconda3/envs/yuco/lib/python3.7/site-packages/pandas/core/ops/__init__.py", line 1048, in wrapper
    result = na_op(lvalues, rvalues)
  File "/home/demattia/miniconda3/envs/yuco/lib/python3.7/site-packages/pandas/core/ops/__init__.py", line 970, in na_op
    result = masked_arith_op(x, y, op)
  File "/home/demattia/miniconda3/envs/yuco/lib/python3.7/site-packages/pandas/core/ops/__init__.py", line 447, in masked_arith_op
    result[mask] = op(xrav[mask], com.values_from_object(yrav[mask]))
TypeError: numpy boolean subtract, the `-` operator, is not supported, use the bitwise_xor, the `^` operator, or the logical_xor function instead.

The fix simply converts the arrays to floating point so as to obtain the intended behavior of the crossing returning -1, 0 or +1.

@JavierAntoran
Copy link

Thanks! I encountered the same issue and this fix worked for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants