Example #1
0
        public override void HandleNextTick(Tick t)
        {
            double emaVal = EMA.HandleNextTick(t);
            LRValues.Enqueue(emaVal);

            double[] Y = LRValues.ToArray();

            LinearRegression l = new LinearRegression();
            l.Model(Y);
            
            HighData.Enqueue(EMA[0]+STDEV * l.STDERR);
            MiddleData.Enqueue(EMA[0]);
            LowData.Enqueue(EMA[0] - STDEV * l.STDERR);
             
        }
Example #2
0
        public static double CalculateHurstEstimate(double[] data, int minLength = 8)
        {
            List<double> n = new List<double>();
            List<double> avgRange = new List<double>();
            for (int i = 1; i <= data.Length; i *= 2)
            {
                double range = CalculateAverageRange(data, data.Length/i);
                if (!range.Equals(double.NaN))
                {
                    n.Add(i);
                    avgRange.Add(range);
                }
            }

            LinearRegression LR = new LinearRegression();
            LR.Model(n.Select(i=> Math.Log(i)).ToArray(),avgRange.Select(i=> Math.Log(i)).ToArray());
            return LR.X2;
        }
Example #3
0
        public static double CalculateHurstEstimate(double[] data, int minLength = 8)
        {
            List <double> n        = new List <double>();
            List <double> avgRange = new List <double>();

            for (int i = 1; i <= data.Length; i *= 2)
            {
                double range = CalculateAverageRange(data, data.Length / i);
                if (!range.Equals(double.NaN))
                {
                    n.Add(i);
                    avgRange.Add(range);
                }
            }

            LinearRegression LR = new LinearRegression();

            LR.Model(n.Select(i => Math.Log(i)).ToArray(), avgRange.Select(i => Math.Log(i)).ToArray());
            return(LR.X2);
        }
Example #4
0
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;
            MA.HandleNextTick(t);
            indicator.HandleNextTick(t);

            if (!MA[0].Equals(double.NaN))
            {
                double[] MAArray = MA.ToArray();
                double[] indArray = indicator.ToArray();
                SortedList<double, double> tickHighs = new SortedList<double, double>();
                SortedList<double, double> tickLows = new SortedList<double, double>();
                SortedList<double, double> indHighs = new SortedList<double, double>();
                SortedList<double, double> indLows = new SortedList<double, double>();
                for (int i = 2; i < MAArray.Length; i++)
                {
                    //high
                    if (MAArray[i] < MAArray[i - 1] && MAArray[i - 1] > MAArray[i - 2])
                    {
                        tickHighs.Add(i - 1, MAArray[i - 1]);
                    }
                    if (indArray[i] < indArray[i - 1] && indArray[i - 1] > indArray[i - 2])
                    {
                        indHighs.Add(i - 1, indArray[i - 1]);
                    }

                    //low
                    if (MAArray[i] > MAArray[i - 1] && MAArray[i - 1] < MAArray[i - 2])
                    {
                        tickLows.Add(i - 1, MAArray[i - 1]);
                    }
                    if (indArray[i] > indArray[i - 1] && indArray[i - 1] < indArray[i - 2])
                    {
                        indLows.Add(i - 1, indArray[i - 1]);
                    }

                }

                if (tickHighs.Count > 0 && indHighs.Count > 0
                    && tickLows.Count > 0 && indLows.Count > 0)
                {
                    LinearRegression lrTickHighs = new LinearRegression();
                    LinearRegression lrTickLows = new LinearRegression();
                    LinearRegression lrindkHighs = new LinearRegression();
                    LinearRegression lrindLows = new LinearRegression();

                    lrTickHighs.Model(tickHighs.Keys.ToArray(), tickHighs.Values.ToArray());
                    lrTickLows.Model(tickLows.Keys.ToArray(), tickLows.Values.ToArray());
                    lrindkHighs.Model(indHighs.Keys.ToArray(), indHighs.Values.ToArray());
                    lrindLows.Model(indLows.Keys.ToArray(), indLows.Values.ToArray());

                    if (lrTickHighs.X2 > 0 && lrindkHighs.X2 < 0) value = 1;
                    else if (lrTickLows.X2 < 0 && lrindLows.X2 > 0) value = -1;
                    else value = 0;

                    value = lrindkHighs.Fit(indArray[0]);
                }
            }

            indicatorData.Enqueue(value);
            return value;

        }