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

General Indicator Miscalculations #50

Closed
iocron opened this issue Aug 28, 2024 · 6 comments
Closed

General Indicator Miscalculations #50

iocron opened this issue Aug 28, 2024 · 6 comments
Labels
invalid This doesn't seem right

Comments

@iocron
Copy link

iocron commented Aug 28, 2024

Calculating the SMA20 of a dataset/series like 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 will result in 21.4 (previous last 20.4). But the real correct result should have been 20.5, if we consider the official mathematical formula of calculating a SMA (verified by investopedia, tradingview, other indicators, ..). The same problems happens on the EMA calculation (with a much worse result) the last time I checked (this might apply to other indicators as well).

@BusinessDuck
Copy link
Contributor

BusinessDuck commented Sep 18, 2024

Described problem does not exists. May be you can get some wrong values, but is not worked as you described. We have miscalculations but it's very very very small, that the machine precision error. It's especially visible on big integer numbers. It still ignored by me. Because does not produce visible deviations for strategies. Especially if we need to have high boost for performance, its a pay for highload.

  1. Let me create a unit test that will test the case that described by you.
  2. I will create a branch that i can use for experiments with machine precision error, i know the good way to improve and fix that problem.

@BusinessDuck
Copy link
Contributor

BusinessDuck commented Sep 18, 2024

You can find more details here

@BusinessDuck BusinessDuck added the bug Something isn't working label Sep 18, 2024
BusinessDuck pushed a commit that referenced this issue Sep 18, 2024
@BusinessDuck
Copy link
Contributor

BusinessDuck commented Sep 18, 2024

I did a PR for demonstrate the calculations of SMA.

image

The result is 20.5. As you described as ideal.

@BusinessDuck
Copy link
Contributor

Check the test here please https://github.com/debut-js/Indicators/pull/53/files

@iocron

@BusinessDuck BusinessDuck added invalid This doesn't seem right and removed bug Something isn't working labels Sep 19, 2024
@BusinessDuck
Copy link
Contributor

I have added the test for the difference between BigFloat (floating error fixed) and with native number SMA calculations. Here is the difference for 900_000 calculations.

image

I create a new issue with that #54

@BusinessDuck
Copy link
Contributor

I will close that issue because no activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants