public void usingTimeFrame5UsingClosePriceAndVolume()
        {
            CorrelationCoefficientIndicator coef = new CorrelationCoefficientIndicator(close, volume, 5);

            // Assert.IsTrue(coef.getValue(0).IsNaN());

            Assert.AreEqual(coef.GetValue(1), 1M);
            Assert.AreEqual(coef.GetValue(2), 0.87733848342525925124506998M);
            Assert.AreEqual(coef.GetValue(3), 0.9073137143013725161493810737M);
            Assert.AreEqual(coef.GetValue(4), 0.9219445959464780324897279404M);
            Assert.AreEqual(coef.GetValue(5), 0.9204686084830691879429314265M);
            Assert.AreEqual(coef.GetValue(6), 0.4565079193666946530704545434M);
            Assert.AreEqual(coef.GetValue(7), -0.4622368993375032370867375609M);
            Assert.AreEqual(coef.GetValue(8), 0.0574674682540454585943187237M);
            Assert.AreEqual(coef.GetValue(9), 0.1442072366721843231551720267M);
            Assert.AreEqual(coef.GetValue(10), -0.1262800365682874150793719821M);
            Assert.AreEqual(coef.GetValue(11), -0.5345125968416236818993319855M);
            Assert.AreEqual(coef.GetValue(12), -0.7275265284764913369741980078M);
            Assert.AreEqual(coef.GetValue(13), 0.1676203622600160056069374939M);
            Assert.AreEqual(coef.GetValue(14), 0.2506093635823103767503572818M);
            Assert.AreEqual(coef.GetValue(15), -0.2937644826001439430561912446M);
            Assert.AreEqual(coef.GetValue(16), -0.3585679550668379351786236965M);
            Assert.AreEqual(coef.GetValue(17), 0.1713296125780531390600177618M);
            Assert.AreEqual(coef.GetValue(18), 0.9841040262836171107084622525M);
            Assert.AreEqual(coef.GetValue(19), 0.9799146648100918552300686205M);
        }
예제 #2
0
        public void UsingTimeFrame5UsingClosePriceAndVolume()
        {
            var coef = new CorrelationCoefficientIndicator(_close, _volume, 5);

            Assert.IsTrue(coef.GetValue(0).NaN);

            TaTestsUtils.AssertDecimalEquals(coef.GetValue(1), 1);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(2), 0.8773);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(3), 0.9073);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(4), 0.9219);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(5), 0.9205);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(6), 0.4565);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(7), -0.4622);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(8), 0.05747);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(9), 0.1442);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(10), -0.1263);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(11), -0.5345);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(12), -0.7275);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(13), 0.1676);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(14), 0.2506);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(15), -0.2938);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(16), -0.3586);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(17), 0.1713);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(18), 0.9841);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(19), 0.9799);
        }
        /**
         * @param index the actual index
         * @return true, if negative convergent
         */
        private bool CalculateNegativeConvergence(int index)
        {
            CorrelationCoefficientIndicator cc = new CorrelationCoefficientIndicator(_indicator, _other, _timeFrame);
            bool isConvergent = cc.GetValue(index).IsGreaterThanOrEqual(_minStrenght);

            decimal slope      = CalculateSlopeRel(index);
            bool    isNegative = slope.IsLessThanOrEqual(_minSlope.Abs().MultipliedBy(-1));

            return(isConvergent && isNegative);
        }
        /**
         * @param index the actual index
         * @return true, if negative divergent
         */
        private bool CalculateNegativeDivergence(int index)
        {
            CorrelationCoefficientIndicator cc = new CorrelationCoefficientIndicator(_indicator, _other, _timeFrame);
            bool isDivergent = cc.GetValue(index).IsLessThanOrEqual(_minStrenght.MultipliedBy(-1));

            if (isDivergent)
            {
                // If "isDivergent" and "ref" is positive, then "other" must be negative.
                decimal slope = CalculateSlopeRel(index);
                return(slope.IsLessThanOrEqual(_minSlope.Abs().MultipliedBy(-1)));
            }

            return(false);
        }