public RelativeStrength(IEnumerable <TInput> inputs, Func <TInput, decimal?> inputMapper, int periodCount) : base(inputs, inputMapper)
        {
            PeriodCount = periodCount;

            _u = new PositiveDifferenceByTuple(inputs.Select(inputMapper), 1);
            _d = new NegativeDifferenceByTuple(inputs.Select(inputMapper), 1);

            _uEma = new GenericMovingAverage(
                periodCount,
                i => Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => _u[j]),
                i => _u[i],
                Smoothing.Mma(periodCount),
                inputs.Count());

            _dEma = new GenericMovingAverage(
                periodCount,
                i => Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => _d[j]),
                i => _d[i],
                Smoothing.Mma(periodCount),
                inputs.Count());
        }
Пример #2
0
        public RelativeMomentum(IEnumerable <TInput> inputs, Func <TInput, decimal?> inputMapper, int rmiPeriod, int mtmPeriod) : base(inputs, inputMapper)
        {
            _u = new PositiveDifferenceByTuple(inputs.Select(inputMapper), mtmPeriod);
            _d = new NegativeDifferenceByTuple(inputs.Select(inputMapper), mtmPeriod);

            _uEma = new GenericMovingAverage(
                rmiPeriod + mtmPeriod - 1,
                i => Enumerable.Range(i - rmiPeriod + 1, rmiPeriod).Average(j => _u[j]),
                i => _u[i],
                i => 2.0m / (rmiPeriod + 1),
                inputs.Count());

            _dEma = new GenericMovingAverage(
                rmiPeriod + mtmPeriod - 1,
                i => Enumerable.Range(i - rmiPeriod + 1, rmiPeriod).Average(j => _d[j]),
                i => _d[i],
                i => 2.0m / (rmiPeriod + 1),
                inputs.Count());

            MtmPeriod = mtmPeriod;
            RmiPeriod = rmiPeriod;
        }