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

Kaufman Adaptive Moving Average (KAMA) #22

Open
dadajonovich opened this issue Aug 30, 2023 · 0 comments
Open

Kaufman Adaptive Moving Average (KAMA) #22

dadajonovich opened this issue Aug 30, 2023 · 0 comments

Comments

@dadajonovich
Copy link

dadajonovich commented Aug 30, 2023

Hello everyone, I can't say for sure, but maybe the KAMA method is not working correctly

function kama(data, len1=10, len2=2, len3=30) {
  for(var i = len1 + 1, ka = module.exports.sma(data, len1), ka = [ka[ka.length - 1]]; i < data.length; i++) {
    var vola = 0, change = Math.abs(data[i] - data[i - len1]);
    for(var a = 1; a < len1; a++) vola += Math.abs(data[(i-a)] - data[(i-a)-1]);
    var sc = (change/vola * (2/(len2+1) - 2/(len3+1) + 2/(len3+1))) ** 2;
    ka.push(ka[ka.length - 1] + sc * (data[i] - ka[ka.length - 1]));
  }
  return ka;
}

If you try to console.log change/vol (ER), sometimes a number above 1 jumps in the array, which should not be.

Also in the line var sc = (change/vola * (2/(len2+1) - 2/(len3+1) + 2/(len3+1))) ** 2; incorrect brackets

The right option kind of has to be:
var sc = (change/vola * (2/(len2+1) - 2/(len3+1)) + 2/(len3+1)) ** 2;

Please correct me if I'm wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant