Simple Moving Average

xixi.li.7 0 Tallied Votes 224 Views Share

I have a project to calculate simple moving average of a data, and the data contains over 4000 values. And requires me to skip the first 14 days and calculate the simple moving average on rest of data. I never experience use moving average and ask me to use LINQ to do this. Can anyone help me out? The output should be display something like this:

Moving averager with sums array:

Date Avg Close
06/07/2012 562.49 571.72
06/08/2012 565.84 580.32
06/11/2012 568.56 571.17
06/12/2012 569.55 576.16
06/13/2012 570.56 572.16
06/14/2012 570.63 571.53
06/15/2012 571.21 574.13
06/18/2012 572.78 585.78
06/19/2012 573.79 587.41
06/20/2012 574.23 585.74
06/21/2012 574.22 577.67
06/22/2012 575.63 582.10
06/25/2012 576.06 570.77
06/26/2012 576.68 572.03
06/27/2012 576.88 574.50
06/28/2012 576.7 569.05
06/29/2012 576.95 584.00
07/02/2012 578.37 592.52
07/03/2012 579.92 599.41
07/03/2012 581.74 599.41

//calculate a 15-day simple moving averager based on the closing price 
//Display the date, moving average, and the original closing price for the last (most recent) 20 days
        private static void Moving(List<DailyValues> googleValues)
        {

            Console.WriteLine("Moving averager with sums array:");
            Console.WriteLine("================================= ");
        }

            decimal CSumMovingAverage(decimal[] csum, int period, int ii)
            {
                 if(period == 0 || ii <= period)
                return -1;
              return csum[ii] - csum[ii - period];

            }

                 
        }