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

Possible RSI bug #1116

Open
jorkey opened this issue Sep 29, 2023 · 7 comments
Open

Possible RSI bug #1116

jorkey opened this issue Sep 29, 2023 · 7 comments
Labels
bug Issue describing or discussing an bug in this library

Comments

@jorkey
Copy link

jorkey commented Sep 29, 2023

When averageLoss.isZero() and averageGain.isZero() RSI returns zero.
RSI must return 50 when averageLoss equals averageGain.
For loss 0.001 and gain 0.001 it returns 50, but for zeros values it returns zero.
I think it's illogical.

@jorkey jorkey added the bug Issue describing or discussing an bug in this library label Sep 29, 2023
@TheCookieLab
Copy link
Member

In what scenario would both the average gain and average loss both be zero? Periods with price losses are counted as zero for the average gain term, and periods with price gains are counted as zero for the average loss term. For both terms to be zero it would mean there was a price gain and loss within the same period which is contradictory.

I view the existing fail safe code of:

if (averageLoss.isZero()) {
            return averageGain.isZero() ? zero() : hundred();
}

as returning a "something is wrong" signal rather than a real RSI value, I know I would if I saw an RSI of 0 or 100. Returning 50 would mask such underlying problems resulting in false signals.

@TheCookieLab
Copy link
Member

An alternative is to return NaN, making the "exception"explicit. Any other suggestions?

@jorkey
Copy link
Author

jorkey commented Oct 6, 2023

I think it would be more logical to return 50, since for the same infinitesimal averageLoss and averageGain it returns 50.
For analysis there is no difference between infinitesimal numbers or zeros, but in the current implementation it returns 0 in one case and 50 in another.

@TheCookieLab
Copy link
Member

While there may be little to no difference on a number line, in this case it's quite literally the difference between valid and invalid. Silently swallowing signs you have something deeply wrong and instead presenting a business-as-usual signal is a poor approach, especially when there's money on the line.

@jorkey
Copy link
Author

jorkey commented Oct 11, 2023

Why do you consider the situation when both averageGain and averageLoss are zero invalid?
This happen when the price doesn't move in any direction.
The GainIndicator and LossIndicator both return zero when price is stable.
MMAIndicator also will return zero for zero values.

@TheCookieLab
Copy link
Member

After mulling this over I've come around to returning 50 in this scenario. @jorkey would you mind creating a PR?

@jorkey
Copy link
Author

jorkey commented Oct 30, 2023

Unfortunately, I can't edit XLS on my Mac. This is necessary to correct the test data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue describing or discussing an bug in this library
Projects
None yet
Development

No branches or pull requests

2 participants