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

Feature request: deviation for EMA #24

Open
dimitriyfomin opened this issue May 15, 2014 · 0 comments
Open

Feature request: deviation for EMA #24

dimitriyfomin opened this issue May 15, 2014 · 0 comments

Comments

@dimitriyfomin
Copy link

Standard deviation doesn't work well for EMA. It's better to use deviation by the same way as EMA is calculated.

my suggestion...
var emaVariance = function(vector, options, callback) {
// Single numeric argument defining the smoothing period
if (typeof options === 'number') {
options = {
period: options,
ratio: function(n) { return 2 / (n + 1); }
};
}
var variance = vector.slice(0, options.period).toVector().variance(),
ratio = options.ratio(options.period),
emaVariance = [variance].toVector();
emaVariance.divide(options.period / (options.period - 1));
for (var i = 0, len = vector.length - options.period; i < len; i++) {
emaVariance.push(
ratio * Math.pow(vector[i + options.period], 2) + (1 - ratio) * emaVariance[i]
);
}
return result(emaVariance, callback);
};
var emaDev = function(vector, options, callback) {
return result(_(emaVariance(vector, options)).map(function (v) { return Math.sqrt(v) }), callback);
};

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