36 ext::shared_ptr<Bond> bond,
40 const ext::shared_ptr<IborIndex>& iborIndex,
45 :
Swap(2), bond_(
std::move(bond)), bondCleanPrice_(bondCleanPrice),
46 nonParRepayment_(nonParRepayment), spread_(spread), parSwap_(parSwap) {
48 bond_->maturityDate(),
50 iborIndex->fixingCalendar(),
51 iborIndex->businessDayConvention(),
52 iborIndex->businessDayConvention(),
55 if (dealMaturity==
Date())
56 dealMaturity =
bond_->maturityDate();
58 "deal maturity " << dealMaturity <<
59 " cannot be later than (adjusted) bond maturity " <<
60 tempSch.
dates().back());
62 "deal maturity " << dealMaturity <<
63 " must be later than swap start date " <<
70 dealMaturity, paymentAdjustment);
84 notional *= dirtyPrice/100.0;
100 Leg::const_iterator i;
101 for (i=
legs_[1].begin(); i<
legs_[1].end(); ++i)
106 for (i =
bondLeg.begin(); i<
bondLeg.end()-1 && (*i)->date()<=dealMaturity; ++i) {
109 bool upfrontDateBondFlows =
false;
110 if (!(*i)->hasOccurred(
upfrontDate_, upfrontDateBondFlows))
111 legs_[0].push_back(*i);
116 ext::shared_ptr<Coupon> c = ext::dynamic_pointer_cast<Coupon>(*i);
118 ext::shared_ptr<CashFlow> accruedCoupon(
new
120 legs_[0].push_back(accruedCoupon);
124 ext::shared_ptr<CashFlow> nonParRepaymentFlow(
new
126 legs_[0].push_back(nonParRepaymentFlow);
129 "empty bond leg to start with");
134 Real upfront = (dirtyPrice-100.0)/100.0*notional;
135 ext::shared_ptr<CashFlow> upfrontCashFlow(
new
137 legs_[1].insert(
legs_[1].begin(), upfrontCashFlow);
140 Real backPayment = notional;
141 ext::shared_ptr<CashFlow> backPaymentCashFlow(
new
143 legs_[1].push_back(backPaymentCashFlow);
146 ext::shared_ptr<CashFlow> finalCashFlow (
new
148 legs_[1].push_back(finalCashFlow);
152 for (i=
legs_[0].begin(); i<
legs_[0].end(); ++i)
165 ext::shared_ptr<Bond> bond,
167 const ext::shared_ptr<IborIndex>& iborIndex,
172 :
Swap(2), bond_(
std::move(bond)), bondCleanPrice_(bondCleanPrice), nonParRepayment_(100),
173 spread_(spread), parSwap_(parSwap) {
176 bond_->maturityDate(),
178 iborIndex->fixingCalendar(),
179 iborIndex->businessDayConvention(),
180 iborIndex->businessDayConvention(),
183 : std::move(floatSchedule);
189 schedule.
endDate(), paymentAdjustment);
191 bond_->maturityDate(), paymentAdjustment);
194 "adjusted schedule end date (" <<
196 ") must be equal to adjusted bond maturity date (" <<
197 adjBondMaturityDate <<
")");
210 notional *= dirtyPrice/100.0;
224 for (Leg::const_iterator i=
legs_[1].begin(); i<
legs_[1].end(); ++i)
231 bool upfrontDateBondFlows =
false;
232 if (!(*i)->hasOccurred(
upfrontDate_, upfrontDateBondFlows))
233 legs_[0].push_back(*i);
237 "empty bond leg to start with");
242 Real upfront = (dirtyPrice-100.0)/100.0*notional;
243 ext::shared_ptr<CashFlow> upfrontCashFlow(
new
245 legs_[1].insert(
legs_[1].begin(), upfrontCashFlow);
248 Real backPayment = notional;
249 ext::shared_ptr<CashFlow> backPaymentCashFlow(
new
251 legs_[1].push_back(backPaymentCashFlow);
254 ext::shared_ptr<CashFlow> finalCashFlow(
new
256 legs_[1].push_back(finalCashFlow);
260 for (Leg::const_iterator i=
legs_[0].begin(); i<
legs_[0].end(); ++i)
284 vector<Date>(fixedCoupons.size());
287 for (
Size i=0; i<fixedCoupons.size(); ++i) {
288 ext::shared_ptr<FixedRateCoupon> coupon =
289 ext::dynamic_pointer_cast<FixedRateCoupon>(fixedCoupons[i]);
300 vector<Date>(floatingCoupons.size());
302 vector<Time>(floatingCoupons.size());
304 vector<Spread>(floatingCoupons.size());
306 for (
Size i=0; i<floatingCoupons.size(); ++i) {
307 ext::shared_ptr<FloatingRateCoupon> coupon =
308 ext::dynamic_pointer_cast<FloatingRateCoupon>(floatingCoupons[i]);
319 static const Spread basisPoint = 1.0e-4;
327 QL_FAIL(
"fair spread not available");
334 "floating-leg BPS not available");
341 "floating-leg NPV not available");
351 "fair clean price not available for seasoned deal");
373 "fair non par repayment not available for expired leg");
404 "number of fixed start dates different from "
405 "number of fixed payment dates");
407 "number of fixed payment dates different from "
408 "number of fixed coupon amounts");
410 "number of floating start dates different from "
411 "number of floating payment dates");
413 "number of floating fixing dates different from "
414 "number of floating payment dates");
416 "number of floating accrual times different from "
417 "number of floating payment dates");
419 "number of floating spreads different from "
420 "number of floating payment dates");
Bullet bond vs Libor swap.
Cash flow vector builders.
Arguments for asset swap calculation
std::vector< Date > floatingResetDates
std::vector< Spread > floatingSpreads
std::vector< Date > floatingFixingDates
std::vector< Date > fixedPayDates
std::vector< Date > fixedResetDates
void validate() const override
std::vector< Time > floatingAccrualTimes
std::vector< Real > fixedCoupons
std::vector< Date > floatingPayDates
Results from simple swap calculation
Real fairNonParRepayment_
AssetSwap(bool payBondCoupon, ext::shared_ptr< Bond > bond, Real bondCleanPrice, const ext::shared_ptr< IborIndex > &iborIndex, Spread spread, Schedule floatSchedule=Schedule(), const DayCounter &floatingDayCount=DayCounter(), bool parAssetSwap=true)
Real fairCleanPrice() const
const Leg & floatingLeg() const
Spread fairSpread() const
Real floatingLegBPS() const
Real fairNonParRepayment() const
void setupArguments(PricingEngine::arguments *args) const override
const Leg & bondLeg() const
ext::shared_ptr< Bond > bond_
void setupExpired() const override
Real floatingLegNPV() const
void fetchResults(const PricingEngine::results *) const override
bool payBondCoupon() const
Date adjust(const Date &, BusinessDayConvention convention=Following) const
helper class building a sequence of capped/floored ibor-rate coupons
IborLeg & withSpreads(Spread spread)
IborLeg & withPaymentAdjustment(BusinessDayConvention)
IborLeg & withPaymentDayCounter(const DayCounter &)
IborLeg & withNotionals(Real notional)
IborLeg & withGearings(Real gearing)
void calculate() const override
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
const Date & endDate() const
const Calendar & calendar() const
const std::vector< Date > & dates() const
const Date & startDate() const
Schedule until(const Date &truncationDate) const
DiscountFactor npvDateDiscount_
void setupArguments(PricingEngine::arguments *) const override
std::vector< Real > legNPV_
std::vector< Real > legBPS_
std::vector< DiscountFactor > startDiscounts_
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
std::vector< DiscountFactor > endDiscounts_
std::vector< Real > payer_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Coupon paying a fixed annual rate.
BusinessDayConvention
Business Day conventions.
Real Spread
spreads on interest rates
std::size_t Size
size of a container
Coupon paying a Libor-type index.
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
ext::shared_ptr< YieldTermStructure > r