//------------------------------------------------------------------------ RiskyFloatingBond::RiskyFloatingBond( std::string name, Currency ccy, Real recoveryRate, Handle<DefaultProbabilityTermStructure> defaultTS, Schedule schedule, boost::shared_ptr<IborIndex> index, Integer fixingDays, Real spread, std::vector<Real> notionals, Handle<YieldTermStructure> yieldTS, Natural settlementDays) : RiskyBond(name, ccy, recoveryRate, defaultTS, yieldTS, settlementDays, schedule.calendar()), schedule_(schedule), index_(index), fixingDays_(fixingDays), spread_(spread), notionals_(notionals) { // FIXME: Take paymentConvention into account std::vector<Date> dates = schedule_.dates(); Real previousNotional = notionals_.front(); for (Size i = 1; i < dates.size(); i++) { Real currentNotional = (i < notionals_.size() ? notionals_[i] : notionals_.back()); boost::shared_ptr<CashFlow> interest (new IborCoupon(dates[i], previousNotional, dates[i-1], dates[i], fixingDays_, index_, 1.0, spread_)); boost::shared_ptr<CashFlow> amortization(new AmortizingPayment(previousNotional - currentNotional, dates[i])); previousNotional = currentNotional; leg_.push_back(interest); interestLeg_.push_back(interest); if (amortization->amount() != 0){ leg_.push_back(amortization); redemptionLeg_.push_back(amortization); } } boost::shared_ptr<CashFlow> redemption(new Redemption(previousNotional, schedule_.dates().back())); leg_.push_back(redemption); redemptionLeg_.push_back(redemption); boost::shared_ptr<IborCouponPricer> fictitiousPricer(new BlackIborCouponPricer(Handle<OptionletVolatilityStructure>())); setCouponPricer(leg_,fictitiousPricer); }
IborLeg::operator Leg() const { Leg leg = FloatingLeg<IborIndex, IborCoupon, CappedFlooredIborCoupon>( schedule_, notionals_, index_, paymentDayCounter_, paymentAdjustment_, fixingDays_, gearings_, spreads_, caps_, floors_, inArrears_, zeroPayments_); if (caps_.empty() && floors_.empty() && !inArrears_) { shared_ptr<IborCouponPricer> pricer(new BlackIborCouponPricer); setCouponPricer(leg, pricer); } return leg; }
MakeCms::operator boost::shared_ptr<Swap>() const { Date startDate; if (effectiveDate_ != Date()) startDate = effectiveDate_; else { Natural fixingDays = iborIndex_->fixingDays(); Date refDate = Settings::instance().evaluationDate(); // if the evaluation date is not a business day // then move to the next business day refDate = floatCalendar_.adjust(refDate); Date spotDate = floatCalendar_.advance(refDate, fixingDays*Days); startDate = spotDate+forwardStart_; } Date terminationDate = startDate+swapTenor_; Schedule cmsSchedule(startDate, terminationDate, cmsTenor_, cmsCalendar_, cmsConvention_, cmsTerminationDateConvention_, cmsRule_, cmsEndOfMonth_, cmsFirstDate_, cmsNextToLastDate_); Schedule floatSchedule(startDate, terminationDate, floatTenor_, floatCalendar_, floatConvention_, floatTerminationDateConvention_, floatRule_ , floatEndOfMonth_, floatFirstDate_, floatNextToLastDate_); Leg cmsLeg = CmsLeg(cmsSchedule, swapIndex_) .withNotionals(nominal_) .withPaymentDayCounter(cmsDayCount_) .withPaymentAdjustment(cmsConvention_) .withFixingDays(swapIndex_->fixingDays()) .withGearings(cmsGearing_) .withSpreads(cmsSpread_) .withCaps(cmsCap_) .withFloors(cmsFloor_); if (couponPricer_) setCouponPricer(cmsLeg, couponPricer_); Rate usedSpread = iborSpread_; if (useAtmSpread_) { QL_REQUIRE(!iborIndex_->forwardingTermStructure().empty(), "null term structure set to this instance of " << iborIndex_->name()); QL_REQUIRE(!swapIndex_->forwardingTermStructure().empty(), "null term structure set to this instance of " << swapIndex_->name()); QL_REQUIRE(couponPricer_, "no CmsCouponPricer set (yet)"); Leg floatLeg = IborLeg(floatSchedule, iborIndex_) .withNotionals(nominal_) .withPaymentDayCounter(floatDayCount_) .withPaymentAdjustment(floatConvention_) .withFixingDays(iborIndex_->fixingDays()); Swap temp(cmsLeg, floatLeg); temp.setPricingEngine(engine_); Real npv = temp.legNPV(0)+temp.legNPV(1); usedSpread = -npv/temp.legBPS(1)*1e-4; } else { QL_REQUIRE(usedSpread != Null<Spread>(), "null spread set"); } Leg floatLeg = IborLeg(floatSchedule, iborIndex_) .withNotionals(nominal_) .withPaymentDayCounter(floatDayCount_) .withPaymentAdjustment(floatConvention_) .withFixingDays(iborIndex_->fixingDays()) .withSpreads(usedSpread); boost::shared_ptr<Swap> swap; if (payCms_) swap = boost::shared_ptr<Swap>(new Swap(cmsLeg, floatLeg)); else swap = boost::shared_ptr<Swap>(new Swap(floatLeg, cmsLeg)); swap->setPricingEngine(engine_); return swap; }