コード例 #1
0
        internal static Matrix CovarianceMatrixSerialCorrelationCorrected(double[] array1, double[] array2, double decayFactor, int length)
        {
            double[] array1Len = Tools.MostRecentValues(array1, length);
            double[] array2Len = Tools.MostRecentValues(array2, length);
            double[] array1Lag = Tools.LagArray(array1, length, 1);
            double[] array2Lag = Tools.LagArray(array2, length, 1);

            double[,] lagArray = new double[length, 2];
            for (int i = 0; i < length; i++)
            {
                lagArray[i, 0] = array1Lag[i];
                lagArray[i, 1] = array2Lag[i];
            }
            WeightedLeastSquares wls1 = new WeightedLeastSquares(array1Len, lagArray, true, decayFactor);
            WeightedLeastSquares wls2 = new WeightedLeastSquares(array2Len, lagArray, true, decayFactor);
            Matrix D = new Matrix(2, 2);

            D[0, 0] = wls1.Betas[1].Value;
            D[0, 1] = wls1.Betas[2].Value;
            D[1, 0] = wls2.Betas[1].Value;
            D[1, 1] = wls2.Betas[2].Value;

            Matrix C = new Matrix(2, 2);

            C[0, 0] = Variance(array1Len, decayFactor);
            C[0, 1] = Covariance(array1Len, array2Len, decayFactor);
            C[1, 0] = C[0, 1];
            C[1, 1] = Variance(array2Len, decayFactor);

            Matrix M     = SerialCorrelationCorrection.SerialCorrelationVarianceCorrection(D, C);
            Matrix CStar = M.Multiply(C);

            return(CStar);
        }
コード例 #2
0
        internal static Matrix CovarianceMatrixSerialCorrelationCorrected(double[] array1, double[] array2, double decayFactor, int length)
        {
            double[] array1Len = Tools.MostRecentValues(array1, length);
            double[] array2Len = Tools.MostRecentValues(array2, length);
            double[] array1Lag = Tools.LagArray(array1, length, 1);
            double[] array2Lag = Tools.LagArray(array2, length, 1);

            double[,] lagArray = new double[length, 2];
            for (int i = 0; i < length; i++)
            {
                lagArray[i, 0] = array1Lag[i];
                lagArray[i, 1] = array2Lag[i];
            }
            WeightedLeastSquares wls1 = new WeightedLeastSquares(array1Len, lagArray, true, decayFactor);
            WeightedLeastSquares wls2 = new WeightedLeastSquares(array2Len, lagArray, true, decayFactor);
            Matrix D = new Matrix(2, 2);
            D[0, 0] = wls1.Betas[1].Value;
            D[0, 1] = wls1.Betas[2].Value;
            D[1, 0] = wls2.Betas[1].Value;
            D[1, 1] = wls2.Betas[2].Value;

            Matrix C = new Matrix(2, 2);
            C[0, 0] = Variance(array1Len, decayFactor);
            C[0, 1] = Covariance(array1Len, array2Len, decayFactor);
            C[1, 0] = C[0, 1];
            C[1, 1] = Variance(array2Len, decayFactor);

            Matrix M = SerialCorrelationCorrection.SerialCorrelationVarianceCorrection(D, C);
            Matrix CStar = M.Multiply(C);
            return CStar;
        }