using System;
using System.Collections.Generic;
using MarketData.Numerical;

namespace MarketData.MarketDataModel
{
  public class MovingDeviation
  {
    private MovingDeviation()
    {
    }
    public static DMADeviations GenerateMovingDeviation(Prices prices, int dayCount)
    {
      try
      {
        DMADeviations dmaDeviations = new DMADeviations();

        for (int index = 0; index < prices.Count; index++)
        {
          Price price = prices[index];
          DMADeviation dmaDeviation = new DMADeviation();
          dmaDeviation.Symbol = price.Symbol;
          dmaDeviation.Date = price.Date;
          float[] pricesArray = prices.GetPrices(index, dayCount);
          dmaDeviation.StDevPrice = Numerics.Volatility(ref pricesArray);
          if (double.IsNaN(dmaDeviation.StDevPrice)) continue;
          dmaDeviation.CurrentPrice = price.Close;
          dmaDeviations.Add(dmaDeviation);
        }
        return dmaDeviations;
      }
      catch (Exception exception)
      {
        MDTrace.WriteLine(LogLevel.DEBUG,exception);
        return null;
      }
    }
  }

}
