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

HMA throws exception with a misleading / incorrect message. #518

Closed
bobtabor opened this issue Aug 11, 2021 · 5 comments · Fixed by #520
Closed

HMA throws exception with a misleading / incorrect message. #518

bobtabor opened this issue Aug 11, 2021 · 5 comments · Fixed by #520
Labels
bug Something isn't working

Comments

@bobtabor
Copy link

The problem

I called:

var values = quotes.GetHma(9);

Where quotes only had 10 items. This throws an exception, which is fine. The text of the exception is not quite right. (See next section.)

Error message(s):

Skender.Stock.Indicators.BadQuotesException: 'Insufficient quotes provided for WMA.  You provided 2 periods of quotes when at least 3 is required. (Parameter 'quotes')'

To Reproduce

Call the GetHma() extension method passing in 9 as the number of lookback periods, calling from a List with 10 instances of Quote.

Expected behavior

I expected the error message use the term "HMA" rather than "WMA", and I expected the count of items to reflect the actual number of items in my collection (which was 10).

Screenshots or other reference materials

exception

@bobtabor bobtabor added the bug Something isn't working label Aug 11, 2021
@bobtabor
Copy link
Author

(BTW, love this library ... thank you so much for your hard work on it!!!)

@DaveSkender
Copy link
Owner

DaveSkender commented Aug 11, 2021

I'm glad you're enjoying it! Thank you.

And thanks for finding this interestingly strange bug. HMA uses WMA internally and on their face they have the same historical quotes requirements. HMA basically takes two WMAs then does another aggregate WMA calculation that uses square root of N lookback — square root of 9 is 3 — and then it uses N-1 quotes.

Clearly a rounding error in here that pops up with certain historical quote quantities or lookback periods. I may have to increase the minimum threshold if small quote quantities are the actual problem. I'll dig in on it this weekend.

DaveSkender added a commit that referenced this issue Aug 12, 2021
@DaveSkender
Copy link
Owner

Turns out this has less to do with the smallness of history, but rather the calculation of minimum history. Originally, I was saying you need a minimum of N periods of historical quotes, where N is the lookback period. The math on this is hard to follow in the formula, but it turns out the calculation needs a minimum of N+(integer of SQRT(N))-1 quotes.

@DaveSkender
Copy link
Owner

This was fixed in version 1.15.1

@github-actions
Copy link

This Issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new Issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants