Libraryless. Click here for Pure Java version (10967L/61K).
srecord noeq SmoothedMovingAverage(double period) { selfType period(double period) { this.period = period; this; } gettable double value = Double.NaN; gettable long steps; double get() { ret value; } double add(double x) { ++steps; if (isNaN(value)) value = x; else value = blend(value, x, alpha()); ret value; } double alpha() { ret reciprocal(period); } void reset { resetFields(this, "steps value"); } bool complete() { ret steps >= period; } }
Began life as a copy of #1036438
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036444 |
Snippet name: | SmoothedMovingAverage - TODO: rename to ExponentialMovingAverage |
Eternal ID of this version: | #1036444/7 |
Text MD5: | 6edb6cce0f07f0e59fdd24e29e632edc |
Transpilation MD5: | d649167dbda1cd24e6b9f24f87021810 |
Author: | stefan |
Category: | javax / trading |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-04-12 10:17:11 |
Source code size: | 557 bytes / 29 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 177 / 255 |
Version history: | 6 change(s) |
Referenced in: | [show references] |