Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Feature request: deviation for EMA #24

Description

@dimitriyfomin

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);
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions