Ejemplo n.º 1
0
        public RelativeStrength(IEnumerable <TInput> inputs, Func <TInput, decimal> inputMapper, int periodCount) : base(inputs, inputMapper)
        {
            _closePriceChange = new DifferenceByTuple(inputs.Select(inputMapper));

            Func <int, decimal?> u = i => i > 0 ? Math.Max(_closePriceChange[i].Value, 0) : (decimal?)null;
            Func <int, decimal?> l = i => i > 0 ? Math.Abs(Math.Min(_closePriceChange[i].Value, 0)) : (decimal?)null;

            _uEma = new GenericMovingAverage(
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(u) : null,
                u,
                i => 1.0m / periodCount,
                inputs.Count());

            _dEma = new GenericMovingAverage(
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(l) : null,
                l,
                i => 1.0m / periodCount,
                inputs.Count());

            PeriodCount = periodCount;
        }
 public NegativeDifference(IEnumerable <TInput> inputs, Func <TInput, decimal?> inputMapper, int periodCount = 1) : base(inputs, inputMapper)
 {
     PeriodCount = periodCount;
     _diff       = new DifferenceByTuple(inputs.Select(inputMapper), periodCount);
 }