Esempio n. 1
0
        public ModifiedMovingAverage(IEnumerable <TInput> inputs, Func <TInput, decimal?> inputMapper, int periodCount) : base(inputs, inputMapper)
        {
            _gma = new GenericMovingAverage(
                i => inputs.Select(inputMapper).ElementAt(i),
                1.0m / periodCount,
                inputs.Count());

            PeriodCount = periodCount;
        }
        public ExponentialMovingAverage(IEnumerable <TInput> inputs, Func <TInput, decimal?> inputMapper, int periodCount) : base(inputs, inputMapper)
        {
            _ema = new GenericMovingAverage(
                i => inputs.Select(inputMapper).ElementAt(i),
                Smoothing.Ema(periodCount),
                inputs.Count());

            PeriodCount = periodCount;
        }
        public KaufmanAdaptiveMovingAverage(IEnumerable <TInput> inputs, Func <TInput, decimal> inputMapper, int periodCount, int emaFastPeriodCount, int emaSlowPeriodCount) : base(inputs, inputMapper)
        {
            _er = new EfficiencyRatioByTuple(inputs.Select(inputMapper), periodCount);

            Func <int, decimal> sc = i =>
            {
                double erValue = Convert.ToDouble(_er[i]);
                return(Convert.ToDecimal(Math.Pow(erValue * (2.0 / (emaFastPeriodCount + 1) - 2.0 / (emaSlowPeriodCount + 1)) + 2.0 / (emaSlowPeriodCount + 1), 2)));
            };

            _gema = new GenericMovingAverage(
                periodCount - 1,
                i => inputs.Select(inputMapper).ElementAt(i),
                i => inputs.Select(inputMapper).ElementAt(i),
                sc,
                inputs.Count());

            PeriodCount        = periodCount;
            EmaFastPeriodCount = emaFastPeriodCount;
            EmaSlowPeriodCount = emaSlowPeriodCount;
        }
        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());
        }
        public KaufmanAdaptiveMovingAverage(IEnumerable <TInput> inputs, Func <TInput, decimal> inputMapper, int periodCount, int emaFastPeriodCount, int emaSlowPeriodCount) : base(inputs, inputMapper)
        {
            _er = new EfficiencyRatioByTuple(inputs.Select(inputMapper), periodCount);

            Func <int, decimal> smoothingFactor = i =>
            {
                var s = Smoothing.Ema(emaSlowPeriodCount)(i) + _er[i].Value * (Smoothing.Ema(emaFastPeriodCount)(i) - Smoothing.Ema(emaSlowPeriodCount)(i));
                return(s * s);
            };

            _gma = new GenericMovingAverage(
                periodCount - 1,
                i => inputs.Select(inputMapper).ElementAt(i),
                i => inputs.Select(inputMapper).ElementAt(i),
                smoothingFactor,
                inputs.Count());

            PeriodCount        = periodCount;
            EmaFastPeriodCount = emaFastPeriodCount;
            EmaSlowPeriodCount = emaSlowPeriodCount;
        }
Esempio n. 6
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;
        }
Esempio n. 7
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;
        }