minimize() public abstract method

public abstract minimize ( Problem P, QLNet.EndCriteria endCriteria ) : EndCriteria.Type
P Problem
endCriteria QLNet.EndCriteria
return EndCriteria.Type
示例#1
0
文件: model.cs 项目: qed-/qlnet
        //! Calibrate to a set of market instruments (caps/swaptions)

        /*! An additional constraint can be passed which must be
         *  satisfied in addition to the constraints of the model.
         */
        //public void calibrate(List<CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
        //           Constraint constraint = new Constraint(), List<double> weights = new List<double>()) {
        public void calibrate(List <CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
                              Constraint additionalConstraint, List <double> weights)
        {
            if (!(weights.Count == 0 || weights.Count == instruments.Count))
            {
                throw new ApplicationException("mismatch between number of instruments and weights");
            }

            Constraint c;

            if (additionalConstraint.empty())
            {
                c = constraint_;
            }
            else
            {
                c = new CompositeConstraint(constraint_, additionalConstraint);
            }
            List <double>       w = weights.Count == 0 ? new InitializedList <double>(instruments.Count, 1.0): weights;
            CalibrationFunction f = new CalibrationFunction(this, instruments, w);

            Problem prob = new Problem(f, c, parameters());

            shortRateEndCriteria_ = method.minimize(prob, endCriteria);
            Vector result = new Vector(prob.currentValue());

            setParams(result);
            // recheck
            Vector shortRateProblemValues_ = prob.values(result);

            notifyObservers();
        }
示例#2
0
文件: model.cs 项目: cub-/qlnet
        //! Calibrate to a set of market instruments (caps/swaptions)

        /*! An additional constraint can be passed which must be
         *  satisfied in addition to the constraints of the model.
         */
        //public void calibrate(List<CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
        //           Constraint constraint = new Constraint(), List<double> weights = new List<double>()) {
        public void calibrate(List <CalibrationHelper> instruments,
                              OptimizationMethod method,
                              EndCriteria endCriteria,
                              Constraint additionalConstraint = null,
                              List <double> weights           = null,
                              List <bool> fixParameters       = null)
        {
            if (weights == null)
            {
                weights = new List <double>();
            }
            if (additionalConstraint == null)
            {
                additionalConstraint = new Constraint();
            }
            Utils.QL_REQUIRE(weights.empty() || weights.Count == instruments.Count, () =>
                             "mismatch between number of instruments (" +
                             instruments.Count + ") and weights(" +
                             weights.Count + ")");

            Constraint c;

            if (additionalConstraint.empty())
            {
                c = constraint_;
            }
            else
            {
                c = new CompositeConstraint(constraint_, additionalConstraint);
            }
            List <double> w = weights.Count == 0 ? new InitializedList <double>(instruments.Count, 1.0): weights;

            Vector              prms = parameters();
            List <bool>         all  = new InitializedList <bool>(prms.size(), false);
            Projection          proj = new Projection(prms, fixParameters ?? all);
            CalibrationFunction f    = new CalibrationFunction(this, instruments, w, proj);
            ProjectedConstraint pc   = new ProjectedConstraint(c, proj);
            Problem             prob = new Problem(f, pc, proj.project(prms));

            shortRateEndCriteria_ = method.minimize(prob, endCriteria);
            Vector result = new Vector(prob.currentValue());

            setParams(proj.include(result));
            Vector shortRateProblemValues_ = prob.values(result);

            notifyObservers();

            //CalibrationFunction f = new CalibrationFunction(this, instruments, w);

            //Problem prob = new Problem(f, c, parameters());
            //shortRateEndCriteria_ = method.minimize(prob, endCriteria);
            //Vector result = new Vector(prob.currentValue());
            //setParams(result);
            //// recheck
            //Vector shortRateProblemValues_ = prob.values(result);

            //notifyObservers();
        }
示例#3
0
        //! Solve least square problem using numerix solver
        public Vector perform(ref LeastSquareProblem lsProblem)
        {
            double eps = accuracy_;

            // wrap the least square problem in an optimization function
            LeastSquareFunction lsf = new LeastSquareFunction(lsProblem);

            // define optimization problem
            Problem P = new Problem(lsf, c_, initialValue_);

            // minimize
            EndCriteria ec = new EndCriteria(maxIterations_, Math.Min(maxIterations_ / 2, 100), eps, eps, eps);

            exitFlag_ = (int)om_.minimize(P, ec);

            results_      = P.currentValue();
            resnorm_      = P.functionValue();
            bestAccuracy_ = P.functionValue();

            return(results_);
        }
示例#4
0
文件: model.cs 项目: ammachado/QLNet
        //! Calibrate to a set of market instruments (caps/swaptions)
        /*! An additional constraint can be passed which must be
            satisfied in addition to the constraints of the model.
        */
        //public void calibrate(List<CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
        //           Constraint constraint = new Constraint(), List<double> weights = new List<double>()) {
        public void calibrate(List<CalibrationHelper> instruments, OptimizationMethod method, EndCriteria endCriteria,
            Constraint additionalConstraint, List<double> weights)
        {
            if (!(weights.Count == 0 || weights.Count == instruments.Count))
                throw new ApplicationException("mismatch between number of instruments and weights");

            Constraint c;
            if (additionalConstraint.empty())
                c = constraint_;
            else
                c = new CompositeConstraint(constraint_,additionalConstraint);
            List<double> w = weights.Count == 0 ? new InitializedList<double>(instruments.Count, 1.0): weights;
            CalibrationFunction f = new CalibrationFunction(this, instruments, w);

            Problem prob = new Problem(f, c, parameters());
            shortRateEndCriteria_ = method.minimize(prob, endCriteria);
            Vector result = new Vector(prob.currentValue());
            setParams(result);
            // recheck
            Vector shortRateProblemValues_ = prob.values(result);

            notifyObservers();
        }