QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
catbond.cpp
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
20#include <ql/experimental/catbonds/catbond.hpp>
21#include <ql/settings.hpp>
22#include <ql/experimental/credit/loss.hpp>
23#include <ql/time/daycounters/actualactual.hpp>
24#include <ql/cashflows/cashflowvectors.hpp>
25#include <ql/cashflows/iborcoupon.hpp>
26#include <ql/cashflows/couponpricer.hpp>
27#include <ql/cashflows/simplecashflow.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 const 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(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}
void validate() const override
Definition: bond.cpp:399
Calendar calendar_
Definition: bond.hpp:285
Leg redemptions_
Definition: bond.hpp:289
void setupArguments(PricingEngine::arguments *) const override
Definition: bond.cpp:285
Natural settlementDays() const
Definition: bond.hpp:318
void addRedemptionsToCashflows(const std::vector< Real > &redemptions=std::vector< Real >())
Definition: bond.cpp:304
const Calendar & calendar() const
Definition: bond.hpp:322
Date startDate() const
Definition: bond.cpp:146
const Leg & cashflows() const
Definition: bond.hpp:330
Date issueDate() const
Definition: bond.hpp:338
Leg cashflows_
Definition: bond.hpp:288
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:294
Date maturityDate_
Definition: bond.hpp:291
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, const 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:133
IborLeg & withSpreads(Spread spread)
Definition: iborcoupon.cpp:208
IborLeg & withPaymentAdjustment(BusinessDayConvention)
Definition: iborcoupon.cpp:173
IborLeg & withPaymentDayCounter(const DayCounter &)
Definition: iborcoupon.cpp:168
IborLeg & inArrears(bool flag=true)
Definition: iborcoupon.cpp:238
IborLeg & withFloors(Rate floor)
Definition: iborcoupon.cpp:228
IborLeg & withNotionals(Real notional)
Definition: iborcoupon.cpp:158
IborLeg & withGearings(Real gearing)
Definition: iborcoupon.cpp:198
IborLeg & withCaps(Rate cap)
Definition: iborcoupon.cpp:218
IborLeg & withFixingDays(Natural fixingDays)
Definition: iborcoupon.cpp:188
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
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
Definition: any.hpp:35
STL namespace.