Hello all, I am a ruby novice who would really appreciate some guidance with the following: I am trying to calculate a 5 day weighted moving average based on a set of numbers in a data series. The most recent is given a * 5 weight, the next * 4 etc etc. with the oldest (the 5th number) * 1. n=5 dataset=[ 25.0000,24.8750,24.7813,24.5938,24.5000,24.6250,25.2188,27.2500,26.2500,26.5938] n.times do |period| a = period+1 b = dataset[period] c = a*b puts c end output: 25.0 49.75 74.3439 98.3752 122.5 but what I now want it to do is add up the output and / 15, to give me one number, approx 26.6646 Then using a loop, do the same again starting with the next number, 24.8750, and so on until it has gobe through the data series? Many thanks for your time, David -- Posted via http://www.ruby-forum.com/.