Exemplo n.º 1
0
        public ConstantParameter(double value, Constraint constraint)
            : base(1, new ConstantParameter.Impl(), constraint)
        {
            params_[0] = value;

            if (!(testParams(params_)))
                throw new ApplicationException(": invalid value");
        }
Exemplo n.º 2
0
        public abstract double value(Problem P, ref EndCriteria.Type ecType, EndCriteria NamelessParameter3, double t_ini); // initial value of line-search step
        public double update(ref Vector data, Vector direction, double beta, Constraint constraint) {

            double diff = beta;
            Vector newParams = data + diff * direction;
            bool valid = constraint.test(newParams);
            int icount = 0;
            while (!valid) {
                if (icount > 200)
                    throw new ApplicationException("can't update linesearch");
                diff *= 0.5;
                icount++;
                newParams = data + diff * direction;
                valid = constraint.test(newParams);
            }
            data += diff * direction;
            return diff;
        }
Exemplo n.º 3
0
        //! 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();
        }
Exemplo n.º 4
0
 public CalibratedModel(int nArguments)
 {
     arguments_ = new InitializedList<Parameter>(nArguments);
     constraint_ = new PrivateConstraint(arguments_);
     shortRateEndCriteria_ = EndCriteria.Type.None;
 }
Exemplo n.º 5
0
 public ConstantParameter(Constraint constraint)
     : base(1, new ConstantParameter.Impl(), constraint)
 {
 }
Exemplo n.º 6
0
 protected Parameter(int size, Impl impl, Constraint constraint)
 {
     impl_ = impl;
     params_ = new Vector(size);
     constraint_ = constraint;
 }
Exemplo n.º 7
0
 public Parameter()
 {
     constraint_ = new NoConstraint();
 }
Exemplo n.º 8
0
 public CompositeConstraint(Constraint c1, Constraint c2)
     : base(new Impl(c1,c2))
 {
 }
Exemplo n.º 9
0
 public Impl(Constraint c1, Constraint c2)
 {
     c1_ = c1;
     c2_ = c2;
 }
 //! Default constructor
 public NonLinearLeastSquare(Constraint c, double accuracy, int maxiter, OptimizationMethod om)
 {
     exitFlag_ = -1;
     accuracy_ = accuracy;
     maxIterations_ = maxiter;
     om_ = om;
     c_ = c;
 }
 public NonLinearLeastSquare(Constraint c, double accuracy, int maxiter)
 {
     exitFlag_ = -1;
     accuracy_ = accuracy;
     maxIterations_ = maxiter;
     om_ = new ConjugateGradient();
     c_ = c;
 }
 public NonLinearLeastSquare(Constraint c)
     : this(c, 1e-4, 100)
 {
 }
 //! Default constructor
 public NonLinearLeastSquare(Constraint c, double accuracy)
     : this(c, accuracy, 100)
 {
 }
Exemplo n.º 14
0
 //! default constructor
 //public Problem(CostFunction costFunction, Constraint constraint, Vector initialValue = Array())
 public Problem(CostFunction costFunction, Constraint constraint, Vector initialValue) {
     costFunction_ = costFunction;
     constraint_ = constraint;
     currentValue_ = (Vector)initialValue.Clone();
 }