예제 #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");
        }
예제 #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;
        }
예제 #3
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();
        }
예제 #4
0
파일: model.cs 프로젝트: ammachado/QLNet
 public CalibratedModel(int nArguments)
 {
     arguments_ = new InitializedList<Parameter>(nArguments);
     constraint_ = new PrivateConstraint(arguments_);
     shortRateEndCriteria_ = EndCriteria.Type.None;
 }
예제 #5
0
 public ConstantParameter(Constraint constraint)
     : base(1, new ConstantParameter.Impl(), constraint)
 {
 }
예제 #6
0
 protected Parameter(int size, Impl impl, Constraint constraint)
 {
     impl_ = impl;
     params_ = new Vector(size);
     constraint_ = constraint;
 }
예제 #7
0
 public Parameter()
 {
     constraint_ = new NoConstraint();
 }
예제 #8
0
파일: Constraint.cs 프로젝트: vdt/QLNet
 public CompositeConstraint(Constraint c1, Constraint c2)
     : base(new Impl(c1,c2))
 {
 }
예제 #9
0
파일: Constraint.cs 프로젝트: vdt/QLNet
 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)
 {
 }
예제 #14
0
파일: problem.cs 프로젝트: akasolace/qlnet
 //! 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();
 }