GregoryMorse / trendln

Support and Resistance Trend lines Calculator for Financial Analysis
MIT License
663 stars 162 forks source link

Error when using calc_support_resistance with certain parameters #10

Open dchhetri opened 4 years ago

dchhetri commented 4 years ago

I want to first thank you for this contribution. This library is great.

I am using Python 3.7.5

Using extmethod=METHOD_NAIVECONSEC throws the following error

File "pandas/_libs/tslibs/c_timestamp.pyx", line 236, in 
pandas._libs.tslibs.c_timestamp._Timestamp.__add__
TypeError: Addition/subtraction of integers and integer-arrays with Timestamp is no longer 
supported.  Instead of adding/subtracting `n`, use `n * obj.freq`

Using method=trendln.METHOD_HOUGHPOINTS throws the following error

File "/usr/local/lib/python3.7/site-packages/trendln/__init__.py", line 587, in hough_points
rhos = np.linspace(-diag_len, diag_len, diag_len * 2.0)
File "<__array_function__ internals>", line 6, in linspace
File "/usr/local/lib/python3.7/site-packages/numpy/core/function_base.py", line 121, in linspace
.format(type(num)))
TypeError: object of type <class 'float'> cannot be safely interpreted as an integer.

Furthermore, I'm wondering if you're open to taking feature request like more efficient calculation given stream of data?

GregoryMorse commented 4 years ago

Hello, thanks for the report and feedback! Can you tell me the version of Python and numpy you are using? The METHOD_HOUGHPOINTS error looks easy to sort out probably just need an int() cast or change 2.0 to 2. The first one also looks like a relatively easy fix as long as its backwards compatible. My suspicion is this could be broken in the latest python versions that I have not used yet.

As for weighted volume, I don't see why it is not supported, simply pass the already weighted volume to the library and it should return the support and resistance lines for it. If you mean the plotting of it, then yes its a good request and the plotting area need some rewriting anyway based on other requests too and the way it should not chain to the main library function but instead let you specify what from that you want to display. Displaying volume should be straight forward for inclusion in next version.

For streams of data, probably a small helper function is likely needed. Since there is a window size, all you have to do is pass the new data plus a window size preceding the new data, and then just merge the trend lines with the ones you already have. But I can add a function which takes the old trend line data, the final window of that trendline data, as well as new data and simply returns the trend line set again. Although not stream lined for this use, it should not be hard to do, but yes merging the trend line code is already in there and not really accessible for this purpose. I will consider this for the next version for sure.

Meciah commented 4 years ago

I had the same issue as @dchhetri and changing the 2.0 to 2 in line

{ rhos = np.linspace(-diag_len, diag_len, diag_len * 2.0) }

Worked!

Thank you @GregoryMorse !! I have really enjoyed this package. I believe it is an issue with numpy versions because I switched to my Mac from my PC anaconda environment and the same code started producing the error on my Mac.