QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
floatingratecoupon.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) 2007 Giorgio Facchinetti
5 Copyright (C) 2006, 2007 Cristina Duminuco
6 Copyright (C) 2006 Ferdinando Ametrano
7 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
8 Copyright (C) 2003, 2004 StatPro Italia srl
9 Copyright (C) 2003 Nicolas Di Césaré
10
11 This file is part of QuantLib, a free-software/open-source library
12 for financial quantitative analysts and developers - http://quantlib.org/
13
14 QuantLib is free software: you can redistribute it and/or modify it
15 under the terms of the QuantLib license. You should have received a
16 copy of the license along with this program; if not, please email
17 <quantlib-dev@lists.sf.net>. The license is also available online at
18 <http://quantlib.org/license.shtml>.
19
20 This program is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. See the license for more details.
23*/
24
29#include <utility>
30
31namespace QuantLib {
32
34 Real nominal,
35 const Date& startDate,
36 const Date& endDate,
37 Natural fixingDays,
38 const ext::shared_ptr<InterestRateIndex>& index,
39 Real gearing,
40 Spread spread,
41 const Date& refPeriodStart,
42 const Date& refPeriodEnd,
43 DayCounter dayCounter,
44 bool isInArrears,
45 const Date& exCouponDate)
46 : Coupon(paymentDate, nominal, startDate, endDate, refPeriodStart, refPeriodEnd, exCouponDate),
47 index_(index), dayCounter_(std::move(dayCounter)),
48 fixingDays_(fixingDays == Null<Natural>() ? (index ? index->fixingDays() : 0) : fixingDays),
49 gearing_(gearing), spread_(spread), isInArrears_(isInArrears) {
50 QL_REQUIRE(index_, "no index provided");
51 QL_REQUIRE(gearing_!=0, "Null gearing not allowed");
52
53 if (dayCounter_.empty())
54 dayCounter_ = index_->dayCounter();
55
57 registerWith(Settings::instance().evaluationDate());
58 }
59
61 const ext::shared_ptr<FloatingRateCouponPricer>& pricer) {
62 if (pricer_ != nullptr)
65 if (pricer_ != nullptr)
67 update();
68 }
69
71 if (d <= accrualStartDate_ || d > paymentDate_) {
72 // out of coupon range
73 return 0.0;
74 } else {
75 return nominal() * rate() * accruedPeriod(d);
76 }
77 }
78
80 // if isInArrears_ fix at the end of period
82 return index_->fixingCalendar().advance(refDate,
83 -static_cast<Integer>(fixingDays_), Days, Preceding);
84 }
85
87 calculate();
88 return rate_;
89 }
90
92 QL_REQUIRE(pricer_, "pricer not set");
93 pricer_->initialize(*this);
94 rate_ = pricer_->swapletRate();
95 }
96
98 return amount() * discountingCurve->discount(date());
99 }
100
102 return index_->fixing(fixingDate());
103 }
104
105}
coupon accruing over a fixed period
Definition: coupon.hpp:39
Date paymentDate_
Definition: coupon.hpp:90
Date accrualStartDate_
Definition: coupon.hpp:92
virtual Real nominal() const
Definition: coupon.hpp:100
Date accrualEndDate_
Definition: coupon.hpp:92
Date date() const override
Definition: coupon.hpp:53
Time accruedPeriod(const Date &) const
accrued period as fraction of year at the given date
Definition: coupon.cpp:57
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
bool empty() const
Returns whether or not the day counter is initialized.
Definition: daycounter.hpp:113
virtual Date fixingDate() const
fixing date
void performCalculations() const override
FloatingRateCoupon(const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, Natural fixingDays, const ext::shared_ptr< InterestRateIndex > &index, Real gearing=1.0, Spread spread=0.0, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date(), DayCounter dayCounter=DayCounter(), bool isInArrears=false, const Date &exCouponDate=Date())
ext::shared_ptr< InterestRateIndex > index_
virtual void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &)
Rate rate() const override
accrued rate
Real amount() const override
returns the amount of the cash flow
ext::shared_ptr< FloatingRateCouponPricer > pricer_
Real accruedAmount(const Date &) const override
accrued amount at the given date
virtual Rate indexFixing() const
fixing of the underlying index
ext::shared_ptr< FloatingRateCouponPricer > pricer() const
Real price(const Handle< YieldTermStructure > &discountingCurve) const
Shared handle to an observable.
Definition: handle.hpp:41
virtual void calculate() const
Definition: lazyobject.hpp:253
void update() override
Definition: lazyobject.hpp:188
template class providing a null value for a given type.
Definition: null.hpp:76
Size unregisterWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:245
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
Coupon pricers.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
Coupon paying a variable index-based rate.
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
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
base class for interest rate indexes
Definition: any.hpp:35
STL namespace.
Interest-rate term structure.