예제 #1
0
        // SIMPLE MOVING AVERAGE of VOLUME
        /// <include file='./info.xml' path='indicator/*' />
        ///
        public static IEnumerable <VolSmaResult> GetVolSma <TQuote>(
            IEnumerable <TQuote> history,
            int lookbackPeriod)
            where TQuote : IQuote
        {
            // sort history and initialize results
            List <VolSmaResult> results = history.Sort()
                                          .Select(x => new VolSmaResult
            {
                Date   = x.Date,
                Volume = x.Volume
            })
                                          .ToList();

            // check parameter arguments
            ValidateVolSma(history, lookbackPeriod);

            // roll through history
            for (int i = lookbackPeriod - 1; i < results.Count; i++)
            {
                VolSmaResult h     = results[i];
                int          index = i + 1;

                decimal sumVolSma = 0m;
                for (int p = index - lookbackPeriod; p < index; p++)
                {
                    VolSmaResult q = results[p];
                    sumVolSma += q.Volume;
                }

                h.VolSma = sumVolSma / lookbackPeriod;
            }

            return(results);
        }
예제 #2
0
        // SIMPLE MOVING AVERAGE of VOLUME
        public static IEnumerable <VolSmaResult> GetVolSma(IEnumerable <Quote> history, int lookbackPeriod)
        {
            // clean quotes and initialize results
            List <VolSmaResult> results = Cleaners.PrepareHistory(history)
                                          .Select(x => new VolSmaResult
            {
                Index  = (int)x.Index,
                Date   = x.Date,
                Volume = x.Volume
            })
                                          .ToList();

            // check parameters
            ValidateVolSma(history, lookbackPeriod);

            // roll through history
            for (int i = lookbackPeriod - 1; i < results.Count; i++)
            {
                VolSmaResult h = results[i];

                decimal sumVolSma = 0m;
                for (int p = (int)h.Index - lookbackPeriod; p < h.Index; p++)
                {
                    VolSmaResult q = results[p];
                    sumVolSma += q.Volume;
                }

                h.VolSma = sumVolSma / lookbackPeriod;
            }

            return(results);
        }