Example #1
0
        public bool AuxiliaryFunction(int index, out object output)
        {
            var approx = new ARMAModel(0, maxLag); // we should be able to get close with an MA
            var hlds   = new HaltonSequence(maxLag);

            double bestError        = double.MaxValue;
            var    bestMAPolynomial = Vector <double> .Build.Dense(maxLag);//new Polynomial(maxLag);

            for (int i = 0; i < 200000; ++i)
            {
                var cube    = hlds.GetNext();                            // this is the MA part to try in the ARMA
                var curCube = approx.ParameterToCube(approx.Parameters); // el. 0=mu, el. 1=d, el. 2=sigma
                for (int j = 0; j < maxLag; ++j)
                {
                    curCube[j + 3] = cube[j];
                }
                approx.SetParameters(approx.CubeToParameter(curCube));

                // now compare autocorrelation function (don't care about mean or sigma)
                var    acf   = approx.ComputeACF(maxLag, true);
                double error = 0;
                for (int j = 0; j < maxLag; ++j)
                {
                    error += Math.Abs(acf[j + 1] - Rho(j));
                }
                if (error < bestError)
                {
                    bestError        = error;
                    bestMAPolynomial = approx.GetMAPolynomial();
                }
            }

            approx.SetMAPolynomial(bestMAPolynomial);
            approx.Mu = Mu;
            output    = approx;
            return(true);
        }