﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WhiteLightCommon.Utils
{
    public static class MovingAverageHelper
    {
        public static double GetSimpleMovingAverage(int index, int averageNumber, StockData data)
        {
            if (index <= averageNumber)
            {
                throw new Exception("Need warm up period");
            }
            double result = 0;
            for (int i = 0; i < averageNumber; i++)
            {
                result += data[index - i].close;
            }

            return result / averageNumber;
        }
    }
}
