TulipCharts / tulipy

[NOT ACTIVELY MAINTAINED] Tulipy - Financial Technical Analysis Indicator Library (Python bindings for Tulip Charts)
https://github.com/TulipCharts/tulipindicators
GNU Lesser General Public License v3.0
330 stars 83 forks source link

Passing integers in tulipy.kvo #22

Closed Taqhee closed 6 years ago

Taqhee commented 6 years ago

Passing an integer array as either of the options doesn't work in kvo.

For example,

>>> import numpy as np
>>> import tulipy
>>> tulipy.kvo(np.array([6407, 6409]), np.array([6397.5, 6407.0]), np.array([6407.0,6409.5]), np.array([2910712.0, 1121741.0]), 34.0, 55.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Arshad\Anaconda3\lib\site-packages\tulipy\__init__.py", line 611, in kvo
    return lib.kvo([high, low, close, volume], [short_period, long_period])
  File "tulipy\lib\__init__.pyx", line 108, in tulipy.lib._Indicator.__call__
ValueError: Buffer dtype mismatch, expected 'float64_t' but got 'long'
>>>

Works after I change [6407, 6409] to [6407.0, 6409.0]

>>> tulipy.kvo(np.array([6407.0, 6409.0]), np.array([6397.5, 6407.0]), np.array([6407.0,6409.5]), np.array([2910712.0, 1121741.0]), 34.0, 55.0)
array([ 0.])

Fix1(init.py) : Convery all options into float in the function definition. Ex: x = [float(i) for i in x]

def kvo(high, low, close, volume, short_period, long_period):
    """
    Klinger Volume Oscillator
    """
    return lib.kvo([high, low, close, volume], [short_period, long_period])

Fix2 (tulipy/tulipy/lib/init.pyx):

In the class "class _Indicator:" , under def call(self, inputs, options):

Change this line cdef np.ndarray[np.float64_t, ndim=1, mode='c'] c_options = np.array(option_list)

as

cdef np.ndarray[np.float64_t, ndim=1, mode='c'] c_options = np.array(option_list, dtype=np.float64)

cirla commented 6 years ago

c_options already has the dtype=np.float64. The error you're getting is because the input array is not the right dtype. You could specify it explicitly:

tulipy.kvo(np.array([6407, 6409], dtype=np.float64), np.array([6397.5, 6407.0]), np.array([6407.0,6409.5]), np.array([2910712.0, 1121741.0]), 34.0, 55.0)

but I think the bindings should support any numeric dtype. I'll work up a PR to address this. Thanks!

cirla commented 6 years ago

Please update to 0.3.1