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

kdj columns and rsv_9 all NaN #2

Closed
think-nice-things opened this issue Aug 14, 2016 · 4 comments
Closed

kdj columns and rsv_9 all NaN #2

think-nice-things opened this issue Aug 14, 2016 · 4 comments
Labels

Comments

@think-nice-things
Copy link

Hi,

there are cases where the kdj columns are all NaN. This seems to be related to rsv_9 beeing NaN.

Here is sample data (the first 20 lines of ASML stock quote) which shows the problem:

date        adj_close     close      high       low      open     volume
2010-01-01   29.28827  23.99998  23.99998  23.99998  23.99998        0.0
2010-01-04   29.60560  24.26000  24.31999  23.89002  23.90003  1563900.0
2010-01-05   29.66047  24.30497  24.62498  24.05996  24.11501  1550300.0
2010-01-06   29.97780  24.56500  24.56500  24.18000  24.20503  1133900.0
2010-01-07   29.42866  24.11501  24.45004  23.80001  24.45004  2648700.0
2010-01-08   28.44013  23.30497  24.08498  23.27502  23.99998  3064200.0
2010-01-11   27.37239  22.43002  23.45497  22.43002  23.31999  4640500.0
2010-01-12   27.82389  22.80001  22.92998  22.60004  22.65001  3098000.0
2010-01-13   28.28762  23.18000  23.39999  22.75003  22.80001  3732600.0
2010-01-14   28.26319  23.15998  23.59996  23.09499  23.46998  1851800.0
2010-01-15   27.89709  22.85999  23.43002  22.69498  23.28996  2738400.0
2010-01-18   27.93985  22.89503  22.98504  22.62499  22.90003  1132900.0
2010-01-19   27.67129  22.67496  22.91997  22.62499  22.80501  2392200.0
2010-01-20   28.53165  23.37997  23.87000  22.87501  22.98997  6490400.0
2010-01-21   29.00759  23.76998  24.06997  23.65001  23.74503  4068900.0
2010-01-22   28.53165  23.37997  23.82003  23.33500  23.53998  3842600.0
2010-01-25   27.78725  22.76998  23.18501  22.69998  22.70999  3091000.0
2010-01-26   28.34861  23.22998  23.37004  22.81002  22.99998  2716300.0
2010-01-27   28.12290  23.04502  23.13503  22.71500  23.08999  2130900.0
2010-01-28   27.86656  22.83497  23.73001  22.83497  23.44003  3445800.0

if rsv_9 is calculated with stockstats, the first value is NaN. This leads to all kdj columns beeing NaN as well. I guess this is due to a division by zero error in _get_rsv in line 251:

df[column_name] = ((df['close'] - low_min) /
                   (high_max - low_min).astype('float64') * 100)  

How should the code be modified so that this bug doesn't appear?
(or what's the correct value for rsv if high_max - low_min == 0?)

@jealous jealous added the bug label Aug 15, 2016
@jealous
Copy link
Owner

jealous commented Aug 15, 2016

Hi,

I cannot reproduce it in my environment. Could you please try to upgrade to v0.1.1 and see if the problem persists? I am using the almost latest pandas and maybe pandas fixed it.

Here is the script I used to do the test.

import pandas.io.data as web
import datetime
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2013, 1, 27)
f = web.DataReader("ASML ", 'yahoo', start, end)

from stockstats import StockDataFrame
df = StockDataFrame.retype(f)
df[['kdjk', 'kdjd', 'kdjj']]

Please let me know if the problem persists. It would be very helpful if you could also supply the script that reproduce the problem.

Thanks.

@think-nice-things
Copy link
Author

Thanks for testing.
If you use ASML.AS (instead of ASML) you'll get the problem.
There are other stocks where it happens too.

@jealous
Copy link
Owner

jealous commented Aug 15, 2016

I was able to reproduce the issue.
You are correct that the issue is caused by 0 division.
I am update the 'NaN' values in 'RSV' to 0 to fix this issue. At least we get rid of the 'NaN' values in KDJ for now.
But to tell the truth, I don't really know the correct way to calculate this, either.
The fix is in version 0.1.2.

@think-nice-things
Copy link
Author

thanks - works great!

jhmenke added a commit to jhmenke/stockstats that referenced this issue Nov 2, 2021
jealous pushed a commit that referenced this issue Nov 20, 2021
* implement money flow index

* update README for mfi

* minor fix in MFI calculation (- instead of +) and better tests for MFI

* adhere to line length

* add kama indicator

* shorter line

* python 2.7 compatibility

* flake8

* flake8 #2

* additional test

* add one more test case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants