Login  Register

Re: G2 revisited

Posted by Luigi Ballabio-2 on Jun 09, 2004; 4:35am
URL: http://quantlib.414.s1.nabble.com/G2-revisited-tp2986p2990.html

On 2004.06.07 14:38, [hidden email] wrote:
> BTW, does anyone know how to set things so that additional  
> constraints apply to the G2 parameters when fitting (outside of  
> changing code for G2 constructor)?
> For example, if I wanted to set boundary conditions for a to be in  
> range (0.0-0.05). I can"t work out how to do it otherwise.

> Would you need to add a public interface in the particular model? I  
> see that calibrate in model.cpp has an additional optimization  
> parameter, but I don't know how to relate that back to the model's  
> parameters. Any ideas ?

Mike,
        it's a bit of work, but it can be done. You'll have to define  
your own specific constraint first, as in:

class AConstraint : public Constraint {
  private:
    class Impl : public Constraint::Impl {
      public:
        Impl(Real low, Real high)
        : low_(low), high_(high) {}
        bool test(const Array& params) const {
            // a is parameter # 0 in G2
            return ((params[0] > low_) && (params[0] < high_))
        }
      private:
        Real low_, high_;
    };
  public:
    AConstraint(Real low, Real high)
    : Constraint(boost::shared_ptr<Constraint::Impl>(
                              new AConstraint::Impl(low, high))) {}
};

There's a bit of machinery involved---mainly because Constraint is  
implemented via the Strategy pattern, which might or might not be the  
right choice in this case---but the point is that test() should return  
true if the parameters satisfy the desired constraints and false  
otherwise. You can easily extend the above so that it checks more  
parameters.

Afterwards, you should be able to do

G2 model(...);
model.calibrate(helpers, method, AConstraint(0.0,0.05));

and the calibration should take into account your constraint besides  
the ones intrinsic to the model.

Hope this helps,
                Luigi