Last active
March 10, 2020 17:40
-
-
Save jinglescode/3ab8c047984c28244976d007b348f6cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ComputeSMA(data, window_size) | |
{ | |
let r_avgs = [], avg_prev = 0; | |
for (let i = 0; i <= data.length - window_size; i++){ | |
let curr_avg = 0.00, t = i + window_size; | |
for (let k = i; k < t && k <= data.length; k++){ | |
curr_avg += data[k]['price'] / window_size; | |
} | |
r_avgs.push({ set: data.slice(i, i + window_size), avg: curr_avg }); | |
avg_prev = curr_avg; | |
} | |
return r_avgs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment