QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
catbond.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) 2012, 2013 Grzegorz Andruszkiewicz
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
21#include <ql/settings.hpp>
28
29using namespace std;
30
31namespace QuantLib {
32
35 QL_REQUIRE(notionalRisk, "null notionalRisk");
36 }
37
39
40 auto* arguments = dynamic_cast<CatBond::arguments*>(args);
41 QL_REQUIRE(arguments != nullptr, "wrong arguments type");
42
44
47 }
48
51
52 const auto* results = dynamic_cast<const CatBond::results*>(r);
53 QL_ENSURE(results != nullptr, "wrong result type");
54
58 }
59
61 Real faceAmount,
62 Schedule schedule,
63 const ext::shared_ptr<IborIndex>& iborIndex,
64 const DayCounter& paymentDayCounter,
65 const ext::shared_ptr<NotionalRisk>& notionalRisk,
66 BusinessDayConvention paymentConvention,
67 Natural fixingDays,
68 const std::vector<Real>& gearings,
69 const std::vector<Spread>& spreads,
70 const std::vector<Rate>& caps,
71 const std::vector<Rate>& floors,
72 bool inArrears,
74 const Date& issueDate)
75 : CatBond(settlementDays, schedule.calendar(), issueDate, notionalRisk) {
76
77 maturityDate_ = schedule.endDate();
78
79 cashflows_ = IborLeg(std::move(schedule), iborIndex)
80 .withNotionals(faceAmount)
81 .withPaymentDayCounter(paymentDayCounter)
82 .withPaymentAdjustment(paymentConvention)
83 .withFixingDays(fixingDays)
84 .withGearings(gearings)
85 .withSpreads(spreads)
86 .withCaps(caps)
87 .withFloors(floors)
88 .inArrears(inArrears);
89
90 addRedemptionsToCashflows(std::vector<Real>(1, redemption));
91
92 QL_ENSURE(!cashflows().empty(), "bond with no cashflows!");
93 QL_ENSURE(redemptions_.size() == 1, "multiple redemptions created");
94
95 registerWith(iborIndex);
96 }
97
99 Real faceAmount,
100 const Date& startDate,
101 const Date& maturityDate,
102 Frequency couponFrequency,
103 const Calendar& calendar,
104 const ext::shared_ptr<IborIndex>& iborIndex,
105 const DayCounter& accrualDayCounter,
106 const ext::shared_ptr<NotionalRisk>& notionalRisk,
107 BusinessDayConvention accrualConvention,
108 BusinessDayConvention paymentConvention,
109 Natural fixingDays,
110 const std::vector<Real>& gearings,
111 const std::vector<Spread>& spreads,
112 const std::vector<Rate>& caps,
113 const std::vector<Rate>& floors,
114 bool inArrears,
115 Real redemption,
116 const Date& issueDate,
117 const Date& stubDate,
119 bool endOfMonth)
120 : CatBond(settlementDays, calendar, issueDate, notionalRisk) {
121
123
124 Date firstDate, nextToLastDate;
125 switch (rule) {
127 firstDate = Date();
128 nextToLastDate = stubDate;
129 break;
131 firstDate = stubDate;
132 nextToLastDate = Date();
133 break;
138 QL_FAIL("stub date (" << stubDate << ") not allowed with " <<
139 rule << " DateGeneration::Rule");
140 default:
141 QL_FAIL("unknown DateGeneration::Rule (" << Integer(rule) << ")");
142 }
143
144 Schedule schedule(startDate, maturityDate_, Period(couponFrequency),
145 calendar_, accrualConvention, accrualConvention,
146 rule, endOfMonth,
147 firstDate, nextToLastDate);
148
149 cashflows_ = IborLeg(schedule, iborIndex)
150 .withNotionals(faceAmount)
151 .withPaymentDayCounter(accrualDayCounter)
152 .withPaymentAdjustment(paymentConvention)
153 .withFixingDays(fixingDays)
154 .withGearings(gearings)
155 .withSpreads(spreads)
156 .withCaps(caps)
157 .withFloors(floors)
158 .inArrears(inArrears);
159
160 addRedemptionsToCashflows(std::vector<Real>(1, redemption));
161
162 QL_ENSURE(!cashflows().empty(), "bond with no cashflows!");
163 QL_ENSURE(redemptions_.size() == 1, "multiple redemptions created");
164
165 registerWith(iborIndex);
166 }
167
168}
act/act day counters
Cash flow vector builders.
cat bond class
void validate() const override
Definition: bond.cpp:410
Calendar calendar_
Definition: bond.hpp:299
Leg redemptions_
Definition: bond.hpp:303
void setupArguments(PricingEngine::arguments *) const override
Definition: bond.cpp:296
Natural settlementDays() const
Definition: bond.hpp:332
void addRedemptionsToCashflows(const std::vector< Real > &redemptions=std::vector< Real >())
Definition: bond.cpp:315
const Calendar & calendar() const
Definition: bond.hpp:336
Date startDate() const
Definition: bond.cpp:146
const Leg & cashflows() const
Definition: bond.hpp:344
Date issueDate() const
Definition: bond.hpp:352
Leg cashflows_
Definition: bond.hpp:302
const ext::shared_ptr< CashFlow > & redemption() const
Definition: bond.cpp:140
Date maturityDate() const
Definition: bond.cpp:150
void fetchResults(const PricingEngine::results *) const override
Definition: bond.cpp:305
Date maturityDate_
Definition: bond.hpp:305
calendar class
Definition: calendar.hpp:61
ext::shared_ptr< NotionalRisk > notionalRisk
Definition: catbond.hpp:69
void validate() const override
Definition: catbond.cpp:33
results for a cat bond calculation
Definition: catbond.hpp:74
void setupArguments(PricingEngine::arguments *) const override
Definition: catbond.cpp:38
ext::shared_ptr< NotionalRisk > notionalRisk_
Definition: catbond.hpp:59
Real exhaustionProbability_
Definition: catbond.hpp:62
Real lossProbability_
Definition: catbond.hpp:61
void fetchResults(const PricingEngine::results *) const override
Definition: catbond.cpp:49
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
FloatingCatBond(Natural settlementDays, Real faceAmount, Schedule schedule, const ext::shared_ptr< IborIndex > &iborIndex, const DayCounter &accrualDayCounter, const ext::shared_ptr< NotionalRisk > &notionalRisk, BusinessDayConvention paymentConvention=Following, Natural fixingDays=Null< Natural >(), const std::vector< Real > &gearings=std::vector< Real >(1, 1.0), const std::vector< Spread > &spreads=std::vector< Spread >(1, 0.0), const std::vector< Rate > &caps=std::vector< Rate >(), const std::vector< Rate > &floors=std::vector< Rate >(), bool inArrears=false, Real redemption=100.0, const Date &issueDate=Date())
Definition: catbond.cpp:60
helper class building a sequence of capped/floored ibor-rate coupons
Definition: iborcoupon.hpp:134
IborLeg & withSpreads(Spread spread)
Definition: iborcoupon.cpp:212
IborLeg & withPaymentAdjustment(BusinessDayConvention)
Definition: iborcoupon.cpp:177
IborLeg & withPaymentDayCounter(const DayCounter &)
Definition: iborcoupon.cpp:172
IborLeg & inArrears(bool flag=true)
Definition: iborcoupon.cpp:242
IborLeg & withFloors(Rate floor)
Definition: iborcoupon.cpp:232
IborLeg & withNotionals(Real notional)
Definition: iborcoupon.cpp:162
IborLeg & withGearings(Real gearing)
Definition: iborcoupon.cpp:202
IborLeg & withCaps(Rate cap)
Definition: iborcoupon.cpp:222
IborLeg & withFixingDays(Natural fixingDays)
Definition: iborcoupon.cpp:192
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Payment schedule.
Definition: schedule.hpp:40
const Date & endDate() const
Definition: schedule.hpp:184
Coupon pricers.
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
Definition: errors.hpp:130
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Frequency
Frequency of events.
Definition: frequency.hpp:37
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Coupon paying a Libor-type index.
Pair of loss time and amount, sortable by loss time.
Definition: any.hpp:35
STL namespace.
ext::shared_ptr< YieldTermStructure > r
global repository for run-time library settings
Predetermined cash flow.