question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HMA throws exception with a misleading / incorrect message.

See original GitHub issue

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<Quote> 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DaveSkendercommented, Aug 12, 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.

0reactions
github-actions[bot]commented, Nov 13, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Message of Throwable shows wrong text
Message of Throwable shows wrong text ... We're mocking the service and we're throwing the exception that we sometimes get from the service:...
Read more >
Fixed defects - HCL Product Documentation
HMA -284415, Saving user Preference throws error in tcs tab. ... HMA-294556, Message displayed for text field length in misleading while creating form....
Read more >
Function returning true/false vs. void when succeeding and ...
Throwing an exception is simply an additional way of making a method return a value. The caller can check for a return value...
Read more >
Best Practice: Catching and re-throwing Java Exceptions
What is the correct Java™ programming best practice to catch, print, and re-throw Java exceptions?
Read more >
7 Common Mistakes You Should Avoid When Handling ...
Mistake 1: Specify a java. · Mistake 2: Catch unspecific exceptions · Mistake 3: Log and throw an Exception · Mistake 4: Use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found