public ModifiedExponentialMovingAverage(Equity equity, int periodCount) : base(equity, periodCount)
 {
     _gemaIndicator = new GenericExponentialMovingAverage(
         equity,
         0,
         i => Equity[i].Close,
         i => Equity[i].Close,
         i => 1.0m / periodCount);
 }
Exemple #2
0
 public ExponentialMovingAverage(Equity equity, int periodCount) : base(equity, periodCount)
 {
     _ema = new GenericExponentialMovingAverage(
         equity,
         0,
         i => Equity[i].Close,
         i => Equity[i].Close,
         i => 2.0m / (periodCount + 1));
 }
        public ExponentialMovingAverage(IList <decimal> closes, int periodCount) : base(closes)
        {
            _ema = new GenericExponentialMovingAverage <decimal>(
                closes,
                0,
                i => Inputs[i],
                i => Inputs[i],
                i => 2.0m / (periodCount + 1));

            PeriodCount = periodCount;
        }
Exemple #4
0
        public ModifiedExponentialMovingAverage(IEnumerable <TInput> inputs, Func <TInput, decimal> inputMapper, Func <TInput, decimal?, TOutput> outputMapper, int periodCount) : base(inputs, inputMapper, outputMapper)
        {
            _gema = new GenericExponentialMovingAverage(
                0,
                i => inputs.Select(inputMapper).ElementAt(i),
                i => inputs.Select(inputMapper).ElementAt(i),
                i => 1.0m / periodCount,
                inputs.Count());

            PeriodCount = periodCount;
        }
        public ModifiedExponentialMovingAverage(IList <decimal> closes, int periodCount) : base(closes)
        {
            _gema = new GenericExponentialMovingAverage <decimal>(
                closes,
                0,
                i => Inputs[i],
                i => Inputs[i],
                i => 1.0m / periodCount);

            PeriodCount = periodCount;
        }
Exemple #6
0
        public MovingAverageConvergenceDivergence(Equity equity, int emaPeriodCount1, int emaPeriodCount2, int demPeriodCount)
            : base(equity, emaPeriodCount1, emaPeriodCount2, demPeriodCount)
        {
            _emaIndicator1 = new ExponentialMovingAverage(equity, emaPeriodCount1);
            _emaIndicator2 = new ExponentialMovingAverage(equity, emaPeriodCount2);
            _diff          = i => _emaIndicator1.ComputeByIndex(i).Ema - _emaIndicator2.ComputeByIndex(i).Ema;

            _dem = new GenericExponentialMovingAverage(
                equity,
                0,
                i => _diff(i),
                i => _diff(i),
                i => 2.0m / (demPeriodCount + 1));
        }
Exemple #7
0
        public AverageTrueRange(Equity equity, int periodCount) : base(equity, periodCount)
        {
            _tr = i => i > 0 ? new List <decimal?> {
                Math.Abs(Equity[i].High - Equity[i].Low),
                Math.Abs(Equity[i].High - Equity[i - 1].Close),
                Math.Abs(Equity[i].Low - Equity[i - 1].Close)
            }.Max() :
            null;

            _trEma = new GenericExponentialMovingAverage(
                equity,
                periodCount,
                i => Enumerable.Range(i - periodCount + 1, periodCount).Average(j => _tr(j)),
                i => _tr(i),
                i => 1.0m / periodCount);
        }
        public KaufmanAdaptiveMovingAverage(Equity equity, int periodCount, int emaFastPeriodCount, int emaSlowPeriodCount)
            : base(equity, periodCount, emaFastPeriodCount, emaSlowPeriodCount)
        {
            _erIndicator = new EfficiencyRatio(equity, periodCount);

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

            _gemaIndicator = new GenericExponentialMovingAverage(
                equity,
                periodCount - 1,
                i => Equity[i].Close,
                i => Equity[i].Close,
                i => sc(i));
        }
        public KaufmanAdaptiveMovingAverage(IEnumerable <TInput> inputs, Func <TInput, decimal> inputMapper, Func <TInput, decimal?, TOutput> outputMapper, int periodCount, int emaFastPeriodCount, int emaSlowPeriodCount) : base(inputs, inputMapper, outputMapper)
        {
            _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 GenericExponentialMovingAverage(
                periodCount - 1,
                i => inputs.Select(inputMapper).ElementAt(i),
                i => inputs.Select(inputMapper).ElementAt(i),
                i => sc(i),
                inputs.Count());

            PeriodCount        = periodCount;
            EmaFastPeriodCount = emaFastPeriodCount;
            EmaSlowPeriodCount = emaSlowPeriodCount;
        }
Exemple #10
0
        public RelativeStrength(Equity equity, int periodCount) : base(equity, periodCount)
        {
            _closePriceChangeIndicator = new ClosePriceChange(equity);

            Func <int, decimal> u = i => Math.Max(_closePriceChangeIndicator.ComputeByIndex(i).Change.Value, 0);
            Func <int, decimal> l = i => Math.Abs(Math.Min(_closePriceChangeIndicator.ComputeByIndex(i).Change.Value, 0));

            _uEma = new GenericExponentialMovingAverage(
                equity,
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => u(j)) : (decimal?)null,
                i => u(i),
                i => 1.0m / periodCount);

            _dEma = new GenericExponentialMovingAverage(
                equity,
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => l(j)) : (decimal?)null,
                i => l(i),
                i => 1.0m / periodCount);
        }
        public DirectionalMovementIndex(Equity equity, int periodCount) : base(equity, periodCount)
        {
            _atrIndicator = new AverageTrueRange(equity, periodCount);

            Func <int, decimal?> pdm = i => i > 0 ? Equity[i].High - Equity[i - 1].High : (decimal?)null;
            Func <int, decimal?> mdm = i => i > 0 ? Equity[i - 1].Low - Equity[i].Low : (decimal?)null;

            Func <int, decimal?> tpdm = i => pdm(i) > 0 && pdm(i) > mdm(i) ? pdm(i) : 0;
            Func <int, decimal?> tmdm = i => mdm(i) > 0 && pdm(i) < mdm(i) ? mdm(i) : 0;

            var tpdmEma = new GenericExponentialMovingAverage(
                equity,
                periodCount,
                i => Enumerable.Range(i - periodCount + 1, periodCount).Select(j => tpdm(j)).Average(),
                i => tpdm(i),
                i => 1.0m / periodCount);

            var tmdmEma = new GenericExponentialMovingAverage(
                equity,
                periodCount,
                i => Enumerable.Range(i - periodCount + 1, periodCount).Select(j => tmdm(j)).Average(),
                i => tmdm(i),
                i => 1.0m / periodCount);

            _pdi = i => tpdmEma.ComputeByIndex(i).Ema / _atrIndicator.ComputeByIndex(i).Atr * 100;
            _mdi = i => tmdmEma.ComputeByIndex(i).Ema / _atrIndicator.ComputeByIndex(i).Atr * 100;
            _dx  = i =>
            {
                var value = (_pdi(i) - _mdi(i)) / (_pdi(i) + _mdi(i));
                return(value.HasValue ? Math.Abs(value.Value) * 100 : (decimal?)null);
            };

            _adx = new GenericExponentialMovingAverage(
                equity,
                periodCount,
                i => Enumerable.Range(i - periodCount + 1, periodCount).Select(j => _dx(j)).Average(),
                i => _dx(i),
                i => 1.0m / periodCount);
        }
        public KaufmanAdaptiveMovingAverage(IList <decimal> closes, int periodCount, int emaFastPeriodCount, int emaSlowPeriodCount)
            : base(closes)
        {
            _er = new EfficiencyRatio(closes, 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 GenericExponentialMovingAverage <decimal>(
                closes,
                periodCount - 1,
                i => Inputs[i],
                i => Inputs[i],
                i => sc(i));

            PeriodCount        = periodCount;
            EmaFastPeriodCount = emaFastPeriodCount;
            EmaSlowPeriodCount = emaSlowPeriodCount;
        }
Exemple #13
0
        public RelativeStrength(IList <decimal> closes, int periodCount) : base(closes)
        {
            _closePriceChange = new ClosePriceChange(closes);

            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 GenericExponentialMovingAverage <decimal>(
                closes,
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => u(j)) : null,
                i => u(i),
                i => 1.0m / periodCount);

            _dEma = new GenericExponentialMovingAverage <decimal>(
                closes,
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => l(j)) : null,
                i => l(i),
                i => 1.0m / periodCount);

            PeriodCount = periodCount;
        }
Exemple #14
0
        public RelativeStrength(IEnumerable <TInput> inputs, Func <TInput, decimal> inputMapper, Func <TInput, decimal?, TOutput> outputMapper, int periodCount) : base(inputs, inputMapper, outputMapper)
        {
            _closePriceChange = new ClosePriceChangeByTuple(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 GenericExponentialMovingAverage(
                periodCount,
                i => i > 0 ? Enumerable.Range(i - PeriodCount + 1, PeriodCount).Average(j => u(j)) : null,
                i => u(i),
                i => 1.0m / periodCount,
                inputs.Count());

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

            PeriodCount = periodCount;
        }