Exemplo n.º 1
0
        public void testOutputsNoIntercept()
        {
            x         = new RootSpud <double>(values.manager);
            indicator = new QRegression(values, x, 10, true);
            addPoint(-5, -1);
            hasNaN();
            addPoint(5, 3);
            addPoint(1, 0.5);
            addPoint(3, 1);
            addPoint(2, 1.1);
            addPoint(8, 1.3);
            addPoint(-2, -1);
            addPoint(-8, -5);
            addPoint(1, 0.5);
            addPoint(0, 1);

            checkOutputs(0, 1.89855);
            var residuals = indicator[0].getResiduals();

            AlmostEqual(residuals[0], -3.10144, 1e-5);
            AlmostEqual(residuals[1], -0.69565, 1e-5);
            AlmostEqual(residuals[7], 1.49275, 1e-5);
            AlmostEqual(residuals[8], 0.05072, 1e-5);
            AlmostEqual(residuals[9], -1.89855, 1e-5);
            AlmostEqual(indicator[0].getLastResidual(), -1.89855, 1e-5);
            AlmostEqual(indicator[0].getSigma(), 2.30395, 1e-5);
            AlmostEqual(indicator[0].getLastZScore(), -0.92569, 1e-5);
            AlmostEqual(indicator[0].getNumFactors(), 1, 1e-5);
            AlmostEqual(indicator[0].predict(5), 9.49275, 1e-5);
            AlmostEqual(indicator[0].rSquare(), 0.75749, 1e-5);
            AlmostEqual(indicator[0].rSquareAdj(), 0.73054, 1e-5);
        }
Exemplo n.º 2
0
        public void testOutputsWithIntercept()
        {
            x         = new RootSpud <double>(values.manager);
            indicator = new QRegression(values, x, 10, false);
            addPoint(-5, -1);
            hasNaN();
            addPoint(5, 3);
            addPoint(1, 0.5);
            addPoint(3, 1);
            addPoint(2, 1.1);
            addPoint(8, 1.3);
            addPoint(-2, -1);
            addPoint(-8, -5);
            addPoint(1, 0.5);
            addPoint(0, 0);

            var residuals = indicator[0].getResiduals();

            AlmostEqual(residuals[0], -3.48098, 1e-5);
            AlmostEqual(residuals[1], -1.24643, 1e-5);
            AlmostEqual(residuals[7], 1.28446, 1e-5);
            AlmostEqual(residuals[8], -0.39302, 1e-5);
            AlmostEqual(residuals[9], -0.42234, 1e-5);
            AlmostEqual(indicator[0].getLastResidual(), -0.42234, 1e-5);
            AlmostEqual(indicator[0].getSigma(), 2.29937, 1e-5);
            AlmostEqual(indicator[0].getLastZScore(), -0.18367, 1e-5);
            AlmostEqual(indicator[0].getNumFactors(), 2, 1e-5);
            AlmostEqual(indicator[0].predict(5), 10.12916, 1e-5);
            AlmostEqual(indicator[0].rSquare(), 0.78253, 1e-5);
            AlmostEqual(indicator[0].rSquareAdj(), 0.75535, 1e-5);
        }
Exemplo n.º 3
0
        public void testWeightedRegression()
        {
            x         = new RootSpud <double>(values.manager);
            indicator = new QRegression(values, x, 10, false, new [] { 0.5, 0.5358867, 0.5743492, 0.6155722, 0.6597540, 0.7071068, 0.7578583, 0.8122524, 0.8705506, 0.9330330 });

            addPoint(-5, -1);
            hasNaN();
            addPoint(5, 3);
            addPoint(1, 0.5);
            addPoint(3, 1);
            addPoint(2, 1.1);
            addPoint(8, 1.3);
            addPoint(-2, -1);
            addPoint(-8, -5);
            addPoint(1, 0.5);
            addPoint(0, 0);
            checkOutputs(0.5499542078002, 1.91841053644205);
            AlmostEqual(indicator[0].getLastResidual(), -0.54995, 1e-5);
            AlmostEqual(indicator[0].getLastResidual(true), -0.53122, 1e-5);
            AlmostEqual(indicator[0].getSigma(), 2.30431, 1e-5);
            AlmostEqual(indicator[0].getSigma(true), 1.84317, 1e-5);
            AlmostEqual(indicator[0].getLastZScore(), -0.18368, 1e-5);
            AlmostEqual(indicator[0].getLastZScore(true), -0.26229, 1e-5);
            AlmostEqual(indicator[0].rSquare(), 0.77860, 1e-5);
            AlmostEqual(indicator[0].rSquare(true), 0.79859, 1e-5);
            AlmostEqual(indicator[0].rSquareAdj(true), 0.77341, 1e-5);
        }
Exemplo n.º 4
0
 public void testXIsConstant()
 {
     x         = new RootSpud <double>(values.manager);
     indicator = new QRegression(values, x, 3, false);
     addPoint(5, 2);
     hasNaN();
     addPoint(6, 2);
     hasNaN();
     addPoint(9, 2);
     checkOutputs(6.66666, 0);
 }
Exemplo n.º 5
0
 public void testYIsConstant()
 {
     x         = new RootSpud <double>(values.manager);
     indicator = new QRegression(values, x, 3, false);
     addPoint(8, 5);
     hasNaN();
     addPoint(8, 6);
     hasNaN();
     addPoint(8, 9);
     checkOutputs(8, 0);
 }
Exemplo n.º 6
0
 public void testYAndYAreZero()
 {
     x         = new RootSpud <double>(values.manager);
     indicator = new QRegression(values, x, 3, false);
     addPoint(0, 0);
     hasNaN();
     addPoint(0, 0);
     hasNaN();
     addPoint(0, 0);
     checkOutputs(0, 0);
 }
Exemplo n.º 7
0
 public void testXHasInfinity()
 {
     x         = new RootSpud <double>(values.manager);
     indicator = new QRegression(values, x, 3, false);
     addPoint(5, 2);
     hasNaN();
     addPoint(double.NegativeInfinity, 2);
     hasNaN();
     addPoint(9, 2);
     hasNaN();
 }
Exemplo n.º 8
0
 public void testBasicUseCase()
 {
     x         = new RootSpud <double>(values.manager);
     indicator = new QRegression(values, x, 3, false);
     addPoint(7, 9);
     hasNaN();
     addPoint(6, 8);
     hasNaN();
     addPoint(5, 0);
     checkOutputs(4.952055, 0.18493);
     addPoint(6, 8);
     checkOutputs(5, 0.125);
     addPoint(9, 7);
     checkOutputs(5.21929, 0.28947);
 }
Exemplo n.º 9
0
 public void testLongSeries()
 {
     x         = new RootSpud <double>(values.manager);
     indicator = new QRegression(values, x, 10, false);
     addPoint(-5, -1);
     hasNaN();
     addPoint(5, 3);
     addPoint(1, 0.5);
     addPoint(3, 1);
     addPoint(2, 1.1);
     addPoint(8, 1.3);
     addPoint(-2, -1);
     addPoint(-8, -5);
     addPoint(1, 0.5);
     addPoint(0, 0);
     checkOutputs(0.42234, 1.94136);
 }