shared_ptr<CapFloor> CapFloor::optionlet(const Size i) const {
        QL_REQUIRE(i < floatingLeg().size(),
                   io::ordinal(i+1) << " optionlet does not exist, only " <<
                   floatingLeg().size());
        Leg cf(1, floatingLeg()[i]);

        std::vector<Rate> cap, floor;
        if (type() == Cap || type() == Collar)
            cap.push_back(capRates()[i]);
        if (type() == Floor || type() == Collar)
            floor.push_back(floorRates()[i]);

        return shared_ptr<CapFloor>(new CapFloor(type(), cf, cap, floor));
    }
	void crosscurrencyswap::setupArguments(PricingEngine::arguments* args) const {

		Swap::setupArguments(args);

		crosscurrencyswap::arguments* arguments =
			dynamic_cast<crosscurrencyswap::arguments*>(args);

		if (!arguments)  // it's a swap engine...
			return;

		arguments->type = type_;
		arguments->fixedCurrency=fixedCurrency_;
		arguments->floatCurrency=floatCurrency_;
		arguments->fixedLegnominal=Fixedlegnominal_;
		arguments->floatLegnominal=Floatlegnominal_;

		const Leg& fixedCoupons = fixedLeg();

		arguments->fixedResetDates = arguments->fixedPayDates =
			std::vector<Date>(fixedCoupons.size());
		arguments->fixedCoupons = std::vector<Real>(fixedCoupons.size());

		for (Size i=0; i<fixedCoupons.size(); ++i) {
			boost::shared_ptr<FixedRateCoupon> coupon =
				boost::dynamic_pointer_cast<FixedRateCoupon>(fixedCoupons[i]);

			arguments->fixedPayDates[i] = coupon->date();
			arguments->fixedResetDates[i] = coupon->accrualStartDate();
			arguments->fixedCoupons[i] = coupon->amount();
		}

		const Leg& floatingCoupons = floatingLeg();

		arguments->floatingResetDates = arguments->floatingPayDates =
			arguments->floatingFixingDates =
			std::vector<Date>(floatingCoupons.size());
		arguments->floatingAccrualTimes =
			std::vector<Time>(floatingCoupons.size());
		arguments->floatingSpreads =
			std::vector<Spread>(floatingCoupons.size());
		arguments->floatingCoupons = std::vector<Real>(floatingCoupons.size());
		for (Size i=0; i<floatingCoupons.size(); ++i) {
			boost::shared_ptr<IborCoupon> coupon =
				boost::dynamic_pointer_cast<IborCoupon>(floatingCoupons[i]);

			arguments->floatingResetDates[i] = coupon->accrualStartDate();
			arguments->floatingPayDates[i] = coupon->date();

			arguments->floatingFixingDates[i] = coupon->fixingDate();
			arguments->floatingAccrualTimes[i] = coupon->accrualPeriod();
			arguments->floatingSpreads[i] = coupon->spread();
			try {
				arguments->floatingCoupons[i] = coupon->amount();
			} catch (Error&) {
				arguments->floatingCoupons[i] = Null<Real>();
			}
		}
	}
Beispiel #3
0
    void AssetSwap::setupArguments(PricingEngine::arguments* args) const {

        Swap::setupArguments(args);

        AssetSwap::arguments* arguments =
            dynamic_cast<AssetSwap::arguments*>(args);

        if (!arguments)  // it's a swap engine...
            return;

        const Leg& fixedCoupons = bondLeg();

        arguments->fixedResetDates = arguments->fixedPayDates =
            vector<Date>(fixedCoupons.size());
        arguments->fixedCoupons = vector<Real>(fixedCoupons.size());

        for (Size i=0; i<fixedCoupons.size(); ++i) {
            shared_ptr<FixedRateCoupon> coupon =
                dynamic_pointer_cast<FixedRateCoupon>(fixedCoupons[i]);

            arguments->fixedPayDates[i] = coupon->date();
            arguments->fixedResetDates[i] = coupon->accrualStartDate();
            arguments->fixedCoupons[i] = coupon->amount();
        }

        const Leg& floatingCoupons = floatingLeg();

        arguments->floatingResetDates = arguments->floatingPayDates =
            arguments->floatingFixingDates =
            vector<Date>(floatingCoupons.size());
        arguments->floatingAccrualTimes =
            vector<Time>(floatingCoupons.size());
        arguments->floatingSpreads =
            vector<Spread>(floatingCoupons.size());

        for (Size i=0; i<floatingCoupons.size(); ++i) {
            shared_ptr<FloatingRateCoupon> coupon =
                dynamic_pointer_cast<FloatingRateCoupon>(floatingCoupons[i]);

            arguments->floatingResetDates[i] = coupon->accrualStartDate();
            arguments->floatingPayDates[i] = coupon->date();
            arguments->floatingFixingDates[i] = coupon->fixingDate();
            arguments->floatingAccrualTimes[i] = coupon->accrualPeriod();
            arguments->floatingSpreads[i] = coupon->spread();
        }
    }
Beispiel #4
0
    void NonstandardSwap::setupArguments(PricingEngine::arguments *args) const {

        Swap::setupArguments(args);

        NonstandardSwap::arguments *arguments =
            dynamic_cast<NonstandardSwap::arguments *>(args);

        if (!arguments)
            return; // swap engine ... // QL_FAIL("argument types do not
                    // match");

        arguments->type = type_;
        arguments->fixedNominal = fixedNominal_;
        arguments->floatingNominal = floatingNominal_;
        arguments->fixedRate = fixedRate_;

        const Leg &fixedCoupons = fixedLeg();

        arguments->fixedResetDates = arguments->fixedPayDates =
            std::vector<Date>(fixedCoupons.size());
        arguments->fixedCoupons = std::vector<Real>(fixedCoupons.size());
        arguments->fixedIsRedemptionFlow =
            std::vector<bool>(fixedCoupons.size(), false);

        for (Size i = 0; i < fixedCoupons.size(); ++i) {
            boost::shared_ptr<FixedRateCoupon> coupon =
                boost::dynamic_pointer_cast<FixedRateCoupon>(fixedCoupons[i]);
            if (coupon) {
                arguments->fixedPayDates[i] = coupon->date();
                arguments->fixedResetDates[i] = coupon->accrualStartDate();
                arguments->fixedCoupons[i] = coupon->amount();
            } else {
                boost::shared_ptr<CashFlow> cashflow =
                    boost::dynamic_pointer_cast<CashFlow>(fixedCoupons[i]);
                std::vector<Date>::const_iterator j =
                    std::find(arguments->fixedPayDates.begin(),
                              arguments->fixedPayDates.end(), cashflow->date());
                QL_REQUIRE(j != arguments->fixedPayDates.end(),
                           "nominal redemption on "
                               << cashflow->date()
                               << "has no corresponding coupon");
                Size jIdx = j - arguments->fixedPayDates.begin();
                arguments->fixedIsRedemptionFlow[i] = true;
                arguments->fixedCoupons[i] = cashflow->amount();
                arguments->fixedResetDates[i] =
                    arguments->fixedResetDates[jIdx];
                arguments->fixedPayDates[i] = cashflow->date();
            }
        }

        const Leg &floatingCoupons = floatingLeg();

        arguments->floatingResetDates = arguments->floatingPayDates =
            arguments->floatingFixingDates =
                std::vector<Date>(floatingCoupons.size());
        arguments->floatingAccrualTimes =
            std::vector<Time>(floatingCoupons.size());
        arguments->floatingSpreads =
            std::vector<Spread>(floatingCoupons.size());
        arguments->floatingGearings = std::vector<Real>(floatingCoupons.size());
        arguments->floatingCoupons = std::vector<Real>(floatingCoupons.size());
        arguments->floatingIsRedemptionFlow =
            std::vector<bool>(floatingCoupons.size(), false);

        for (Size i = 0; i < floatingCoupons.size(); ++i) {
            boost::shared_ptr<IborCoupon> coupon =
                boost::dynamic_pointer_cast<IborCoupon>(floatingCoupons[i]);
            if (coupon) {
                arguments->floatingResetDates[i] = coupon->accrualStartDate();
                arguments->floatingPayDates[i] = coupon->date();
                arguments->floatingFixingDates[i] = coupon->fixingDate();
                arguments->floatingAccrualTimes[i] = coupon->accrualPeriod();
                arguments->floatingSpreads[i] = coupon->spread();
                arguments->floatingGearings[i] = coupon->gearing();
                try {
                    arguments->floatingCoupons[i] = coupon->amount();
                }
                catch (Error &) {
                    arguments->floatingCoupons[i] = Null<Real>();
                }
            } else {
                boost::shared_ptr<CashFlow> cashflow =
                    boost::dynamic_pointer_cast<CashFlow>(floatingCoupons[i]);
                std::vector<Date>::const_iterator j = std::find(
                    arguments->floatingPayDates.begin(),
                    arguments->floatingPayDates.end(), cashflow->date());
                QL_REQUIRE(j != arguments->floatingPayDates.end(),
                           "nominal redemption on "
                               << cashflow->date()
                               << "has no corresponding coupon");
                Size jIdx = j - arguments->floatingPayDates.begin();
                arguments->floatingIsRedemptionFlow[i] = true;
                arguments->floatingCoupons[i] = cashflow->amount();
                arguments->floatingResetDates[i] =
                    arguments->floatingResetDates[jIdx];
                arguments->floatingFixingDates[i] =
                    arguments->floatingFixingDates[jIdx];
                arguments->floatingAccrualTimes[i] = 0.0;
                arguments->floatingSpreads[i] = 0.0;
                arguments->floatingGearings[i] = 1.0;
                arguments->floatingPayDates[i] = cashflow->date();
            }
        }

        arguments->iborIndex = iborIndex();
    }