/// <summary>
        /// Attempts to solve the Variance Gamma Optimization problem using
        /// <see cref="Heston.VarianceGammaOptimizationProblem"/>.
        /// </summary>
        /// <param name="data">
        /// The data to be used in order to perform the optimization.
        /// </param>
        /// <param name="settings">The parameter is not used.</param>
        /// <returns>The results of the optimization.</returns>
        public EstimationResult Estimate(List <object> data, IEstimationSettings settings = null, IController controller = null, Dictionary <string, object> properties = null)
        {
            EquitySpotMarketData       espmd = data[0] as EquitySpotMarketData;
            CallPriceMarketData        cpmd  = data[1] as CallPriceMarketData;
            DiscountingCurveMarketData dcmd  = data[2] as DiscountingCurveMarketData;
            EquityCalibrationData      ecd   = new EquityCalibrationData(cpmd, dcmd);

            this.s0 = espmd.Price;
            this.r  = espmd.RiskFreeRate;
            this.q  = espmd.DividendYield;

            this.k  = ecd.Hdata.Strike;
            this.m  = ecd.Hdata.Maturity;
            this.cp = ecd.Hdata.CallPrice;

            Vector x0 = (Vector) new double[] { -0.1, 0.2, 0.1 };
            IOptimizationAlgorithm algorithm            = new QADE();
            OptimizationSettings   optimizationSettings = new DESettings();

            // Maximum number of iteration allowed.

            // Positive integer values print debug info.
            optimizationSettings.Verbosity = 1;

            // Tolerance.
            optimizationSettings.epsilon = 10e-5;
            var solution = algorithm.Minimize(new VarianceGammaOptimizationProblem(this.q, this.s0, this.k,
                                                                                   this.r, this.cp, this.m),
                                              optimizationSettings, x0);

            if (solution.errors)
            {
                return(new EstimationResult(solution.message));
            }

            var er = new EstimationResult();

            er.Names  = new string[] { "S0", "theta", "sigma", "nu", "rate", "dividend" };
            er.Values = new double[] { this.s0, solution.x[0], solution.x[1], solution.x[2], this.r, this.q };
            return(er);
        }
        private static Vector Test(int nm, int nk, double q, double s0, double r, double t, double theta, double sigma, double nu)
        {
            // Simulate synthetic data.
            Vector m    = new Vector(nm);
            Vector k    = new Vector(nk);
            Matrix cp   = new Matrix(nm, nk);
            Random rand = new Random();

            for (int i = 0; i < nm; i++)
            {
                m[i] = 0.01 + rand.NextDouble() * 0.99;
            }

            for (int i = 0; i < nk; i++)
            {
                k[i] = 60 + rand.NextDouble() * 90;
            }

            for (int i = 0; i < nm; i++)
            {
                for (int j = 0; j < nk; j++)
                {
                    cp[i, j] = VarianceGammaOptionsCalibration.VGCall(theta, sigma, nu, m[i], k[j], q, s0, r);
                }
            }

            Console.WriteLine("Benchmark value");
            Console.WriteLine(new Vector()
            {
                theta, sigma, nu
            });

            Console.WriteLine("Call prices");
            Console.WriteLine(cp);

            // VGDiff at optimum.
            double fopt = VarianceGammaOptimizationProblem.VGDiff(new Vector()
            {
                theta, sigma, nu
            }, q, s0, k, r, cp, m);

            Console.WriteLine("fopt");
            Console.WriteLine(fopt);

            VarianceGammaOptionsCalibration c = new VarianceGammaOptionsCalibration();
            List <object> marketData          = new List <object>();

            var espmd = new EquitySpotMarketData();

            espmd.Price         = s0;
            espmd.RiskFreeRate  = r;
            espmd.DividendYield = q;

            var cpmd = new CallPriceMarketData();

            cpmd.Strike    = k;
            cpmd.Maturity  = m;
            cpmd.CallPrice = cp;

            var dc = new DiscountingCurveMarketData();

            dc.Durations = new Vector()
            {
                0
            };
            dc.Values = new Vector()
            {
                r
            };

            marketData.Add(espmd);
            marketData.Add(cpmd);
            marketData.Add(dc);

            EstimationResult res = c.Estimate(marketData, null);

            return((Vector)res.Values);
        }
        private static Vector Test(int nm, int nk, double q, double s0, double r, double t, double theta, double sigma, double nu)
        {
            // Simulate synthetic data.
            Vector m = new Vector(nm);
            Vector k = new Vector(nk);
            Matrix cp = new Matrix(nm, nk);
            Random rand = new Random();
            for (int i = 0; i < nm; i++)
            {
                m[i] = 0.01 + rand.NextDouble() * 0.99;
            }

            for (int i = 0; i < nk; i++)
            {
                k[i] = 60 + rand.NextDouble() * 90;
            }

            for (int i = 0; i < nm; i++)
            {
                for (int j = 0; j < nk; j++)
                {
                    cp[i, j] = VarianceGammaOptionsCalibration.VGCall(theta, sigma, nu, m[i], k[j], q, s0, r);
                }
            }

            Console.WriteLine("Benchmark value");
            Console.WriteLine(new Vector() { theta, sigma, nu });

            Console.WriteLine("Call prices");
            Console.WriteLine(cp);

            // VGDiff at optimum.
            double fopt = VarianceGammaOptimizationProblem.VGDiff(new Vector() { theta, sigma, nu }, q, s0, k, r, cp, m);
            Console.WriteLine("fopt");
            Console.WriteLine(fopt);

            VarianceGammaOptionsCalibration c = new VarianceGammaOptionsCalibration();
            List<object> marketData = new List<object>();

            EquitySpotMarketData espmd = new EquitySpotMarketData();
            CallPriceMarketData cpmd = new CallPriceMarketData();
            espmd.Price = s0;
            espmd.RiskFreeRate = r;
            espmd.DividendYield = q;
            cpmd.Strike = k;
            cpmd.Maturity = m;
            cpmd.CallPrice = cp;

            marketData.Add(espmd);
            marketData.Add(cpmd);

            EstimationResult res = c.Estimate(marketData, null);
            return (Vector)res.Values;
        }