QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fixedratebond.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004 Jeff Yu
5 Copyright (C) 2004 M-Dimension Consulting Inc.
6 Copyright (C) 2005, 2006, 2007 StatPro Italia srl
7 Copyright (C) 2007, 2008, 2010 Ferdinando Ametrano
8 Copyright (C) 2009 Piter Dias
9
10 This file is part of QuantLib, a free-software/open-source library
11 for financial quantitative analysts and developers - http://quantlib.org/
12
13 QuantLib is free software: you can redistribute it and/or modify it
14 under the terms of the QuantLib license. You should have received a
15 copy of the license along with this program; if not, please email
16 <quantlib-dev@lists.sf.net>. The license is also available online at
17 <http://quantlib.org/license.shtml>.
18
19 This program is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 FOR A PARTICULAR PURPOSE. See the license for more details.
22*/
23
27#include <ql/time/schedule.hpp>
28
29namespace QuantLib {
30
32 Real faceAmount,
33 Schedule schedule,
34 const std::vector<Rate>& coupons,
35 const DayCounter& accrualDayCounter,
36 BusinessDayConvention paymentConvention,
37 Real redemption,
38 const Date& issueDate,
39 const Calendar& paymentCalendar,
40 const Period& exCouponPeriod,
41 const Calendar& exCouponCalendar,
42 const BusinessDayConvention exCouponConvention,
43 bool exCouponEndOfMonth,
44 const DayCounter& firstPeriodDayCounter)
45 : Bond(settlementDays,
46 paymentCalendar==Calendar() ? schedule.calendar() : paymentCalendar,
47 issueDate),
48 frequency_(schedule.hasTenor() ? schedule.tenor().frequency() : NoFrequency),
49 dayCounter_(accrualDayCounter),
50 firstPeriodDayCounter_(firstPeriodDayCounter) {
51
52 maturityDate_ = schedule.endDate();
53
54 cashflows_ = FixedRateLeg(std::move(schedule))
55 .withNotionals(faceAmount)
56 .withCouponRates(coupons, accrualDayCounter)
59 .withPaymentAdjustment(paymentConvention)
60 .withExCouponPeriod(exCouponPeriod,
61 exCouponCalendar,
62 exCouponConvention,
63 exCouponEndOfMonth);
64
65 addRedemptionsToCashflows(std::vector<Real>(1, redemption));
66
67 QL_ENSURE(!cashflows().empty(), "bond with no cashflows!");
68 QL_ENSURE(redemptions_.size() == 1, "multiple redemptions created");
69 }
70
71}
Cash flow vector builders.
Base bond class.
Definition: bond.hpp:59
Calendar calendar_
Definition: bond.hpp:299
Leg redemptions_
Definition: bond.hpp:303
void addRedemptionsToCashflows(const std::vector< Real > &redemptions=std::vector< Real >())
Definition: bond.cpp:315
const Leg & cashflows() const
Definition: bond.hpp:344
Leg cashflows_
Definition: bond.hpp:302
const ext::shared_ptr< CashFlow > & redemption() const
Definition: bond.cpp:140
Date maturityDate_
Definition: bond.hpp:305
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
FixedRateBond(Natural settlementDays, Real faceAmount, Schedule schedule, const std::vector< Rate > &coupons, const DayCounter &accrualDayCounter, BusinessDayConvention paymentConvention=Following, Real redemption=100.0, const Date &issueDate=Date(), const Calendar &paymentCalendar=Calendar(), const Period &exCouponPeriod=Period(), const Calendar &exCouponCalendar=Calendar(), BusinessDayConvention exCouponConvention=Unadjusted, bool exCouponEndOfMonth=false, const DayCounter &firstPeriodDayCounter=DayCounter())
simple annual compounding coupon rates
const DayCounter & firstPeriodDayCounter() const
helper class building a sequence of fixed rate coupons
FixedRateLeg & withNotionals(Real)
FixedRateLeg & withPaymentCalendar(const Calendar &)
FixedRateLeg & withPaymentAdjustment(BusinessDayConvention)
FixedRateLeg & withCouponRates(Rate, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
FixedRateLeg & withFirstPeriodDayCounter(const DayCounter &)
FixedRateLeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
Payment schedule.
Definition: schedule.hpp:40
const Date & endDate() const
Definition: schedule.hpp:184
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
Definition: errors.hpp:130
fixed-rate bond
BusinessDayConvention
Business Day conventions.
@ NoFrequency
null frequency
Definition: frequency.hpp:37
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Definition: any.hpp:35
date schedule
Predetermined cash flow.