Beispiel #1
0
    void Gsr::initialize(Real T) {

        volsteptimesArray_ = Array(volstepdates_.size());

        updateTimes();

        QL_REQUIRE(volatilities_.size() == volsteptimes_.size() + 1,
                   "there must be n+1 volatilities ("
                       << volatilities_.size()
                       << ") for n volatility step times ("
                       << volsteptimes_.size() << ")");
        // sigma_ =
        // PiecewiseConstantParameter(volsteptimes_,PositiveConstraint());
        sigma_ = PiecewiseConstantParameter(volsteptimes_, NoConstraint());

        QL_REQUIRE(reversions_.size() == 1 ||
                       reversions_.size() == volsteptimes_.size() + 1,
                   "there must be 1 or n+1 reversions ("
                       << reversions_.size()
                       << ") for n volatility step times ("
                       << volsteptimes_.size() << ")");
        if (reversions_.size() == 1) {
            reversion_ = ConstantParameter(reversions_[0]->value(), NoConstraint());
        } else {
            reversion_ =
                PiecewiseConstantParameter(volsteptimes_, NoConstraint());
        }

        for (Size i = 0; i < sigma_.size(); i++) {
            sigma_.setParam(i, volatilities_[i]->value());
        }
        for (Size i = 0; i < reversion_.size(); i++) {
            reversion_.setParam(i, reversions_[i]->value());
        }

        stateProcess_ = boost::shared_ptr<GsrProcess>(new GsrProcess(
            volsteptimesArray_, sigma_.params(), reversion_.params(), T));

        registerWith(termStructure());

        registerWith(stateProcess_);
        for(Size i=0;i<reversions_.size();++i)
            registerWith(reversions_[i]);

        for(Size i=0;i<volatilities_.size();++i)
            registerWith(volatilities_[i]);

    }
	Generalized_HullWhite::Generalized_HullWhite(const Handle<YieldTermStructure>& termStructure,
		std::vector<Date> dates,
		std::vector<Real> sigma,
		Real a,
		Real fxVol,
		Real fxCorr)
		: Vasicek(termStructure->forwardRate(0.0, 0.0, Continuous, NoFrequency), a, 0.0, sigma[0], 0.0), a0_(a),
		TermStructureConsistentModel(termStructure), fxVol_(fxVol), fxCorr_(fxCorr)
	{
		a_ = NullParameter();
		b_ = NullParameter();
		lambda_ = NullParameter();

		DayCounter dc = termStructure->dayCounter();

		//volperiods_.push_back(0.0);
		for (Size i=0; i<dates.size()-1; i++)
			volperiods_.push_back(dc.yearFraction(Settings::instance().evaluationDate(), dates[i]));
		sigma_ = PiecewiseConstantParameter(volperiods_, PositiveConstraint());

		for (Size i=0; i< sigma_.size(); i++)
			sigma_.setParam(i, sigma[i]);


		generateArguments();
		registerWith(termStructure);
	}
	GeneralizedHullWhite::GeneralizedHullWhite(
        const Handle<YieldTermStructure>& yieldtermStructure,
		const std::vector<Date>& speedstructure,
		const std::vector<Date>& volstructure,
		const std::vector<Real>& speed,
		const std::vector<Real>& vol)
  : OneFactorModel(2), TermStructureConsistentModel(yieldtermStructure),
    speedstructure_(speedstructure),
    volstructure_(volstructure),
    a_(arguments_[0]), sigma_(arguments_[1]) {

        DayCounter dc = yieldtermStructure->dayCounter();

        speedperiods_.push_back(0.0);
        for (Size i=0;i<speedstructure.size()-1;i++)
            speedperiods_.push_back(dc.yearFraction(speedstructure[0],
                                                    speedstructure[i+1]));

        a_ = PiecewiseConstantParameter(speedperiods_, PositiveConstraint());

        volperiods_.push_back(0.0);
        for (Size i=0;i<volstructure.size()-1;i++)
            volperiods_.push_back(dc.yearFraction(volstructure[0],
                                                  volstructure[i+1]));

        sigma_ = PiecewiseConstantParameter(volperiods_, PositiveConstraint());

        a_.setParam(0,speed[0]);
        sigma_.setParam(0,vol[0]);

        for (Size i=1; i< sigma_.size();i++) {
            sigma_.setParam(i,vol[i-1]);
        }
        for (Size i=1; i< a_.size();i++) {
            a_.setParam(i,speed[i-1]);
        }

        registerWith(yieldtermStructure);
	}