using System;
using System.Text;
using System.Linq;
using MarketData.Numerical;

namespace MarketData.MarketDataModel
{
  public class ExponentialDecay
  {
    private double[] decays=null;
    public ExponentialDecay()
    {
    }
    public double this[int sample]
    {
      get{return decays[sample];}
    }
    public void Prime(float[] samples,double deviations=2.00)
    {
      double[]factors=new double[samples.Length];
      decays=new double[samples.Length];
      double stddev=Numerics.StdDev(ref samples);
      for(int index=0,ordinal=samples.Length;index<samples.Length;index++,ordinal--)
      {
        factors[index]=(ordinal*ordinal)+(deviations*stddev);
      }
      double min=factors.Max();
      double max=factors.Min();
      for(int index=0;index<samples.Length;index++)
      {
        decays[index]=factors[index]*(100.00/(max-min))/100.00;
      }
    }
  }
}
