Esempio n. 1
0
        public static IEnumerable <decimal> Diff <T>(this RollingWindow <T> window1, RollingWindow <IndicatorDataPoint> window2, Func <T, decimal> selector = null, int lookback = 1)
            where T : IBaseDataBar
        {
            selector = selector ?? (x => x.Value);

            return(window1.Take(lookback).Select((w1, index) => selector(w1) - window2[index]));
        }
        /// <summary>
        ///      Computes the average value
        /// </summary>
        /// <param name="time"></param>
        /// <param name="input">The data for the calculation</param>
        /// <returns>The average value</returns>
        protected override DoubleArray Forward(long time, DoubleArray input)
        {
            var price = (input[HighIdx] + input[LowIdx]) / 2;

            _high.Add(input[HighIdx]);
            _low.Add(input[LowIdx]);

            // our first data point just return identity
            if (_high.Samples <= _high.Size)
            {
                return(price);
            }

            var hh = _high.Take(_n / 2).Max();
            var ll = _low.Take(_n / 2).Min();
            var n1 = (hh - ll) / (_n / 2);

            hh = _high.Skip(_n / 2).Take(_n / 2).Max();
            ll = _low.Skip(_n / 2).Take(_n / 2).Min();

            var n2 = (hh - ll) / (_n / 2);
            var n3 = (_high.Max() - _low.Min()) / _n;

            double dimen = 0;

            if (n1 + n2 > 0 && n3 > 0)
            {
                dimen = Math.Log((n1 + n2) / n3) / Math.Log(2);
            }

            var alpha = Math.Exp(_w * (dimen - 1));

            if (alpha < .01d)
            {
                alpha = .01d;
            }

            if (alpha > 1)
            {
                alpha = 1;
            }

            return(alpha * price + (1 - alpha) * Current.Value);
        }
Esempio n. 3
0
 public IEnumerable <TradeBar> NDaysDailyHistory(int n) => _dailyCloses.Take(n).Reverse();
Esempio n. 4
0
 public static IEnumerable <decimal> Diff(this RollingWindow <IndicatorDataPoint> window1, RollingWindow <IndicatorDataPoint> window2, int lookback = 1)
 {
     return(window1.Take(lookback).Select((w1, index) => w1 - window2[index]));
 }
Esempio n. 5
0
 public static bool Falling(this RollingWindow <IndicatorDataPoint> window, int lookback = 1, decimal tolerance = 0m)
 {
     return(window.Take(lookback).Zip(window.Skip(1).Take(lookback), (w1, w2) => Tuple.Create(w1, w2)).All((w) => w.Item1 < w.Item2 * (1 - tolerance)));
 }
Esempio n. 6
0
 public static bool Rising(this RollingWindow <decimal> window, int lookback = 1, decimal tolerance = 0m)
 {
     return(window.Take(lookback).Zip(window.Skip(1).Take(lookback), (w1, w2) => Tuple.Create(w1, w2)).All((w) => w.Item1 > w.Item2 * (1 + tolerance)));
 }