QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
coupon.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) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2007 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
24
25namespace QuantLib {
26
27 Coupon::Coupon(const Date& paymentDate,
28 Real nominal,
29 const Date& accrualStartDate,
30 const Date& accrualEndDate,
31 const Date& refPeriodStart,
32 const Date& refPeriodEnd,
33 const Date& exCouponDate)
34 : paymentDate_(paymentDate), nominal_(nominal),
35 accrualStartDate_(accrualStartDate), accrualEndDate_(accrualEndDate),
36 refPeriodStart_(refPeriodStart), refPeriodEnd_(refPeriodEnd),
37 exCouponDate_(exCouponDate), accrualPeriod_(Null<Real>()) {
38 if (refPeriodStart_ == Date())
40 if (refPeriodEnd_ == Date())
42 }
43
49 return accrualPeriod_;
50 }
51
55 }
56
58 if (d <= accrualStartDate_ || d > paymentDate_) {
59 return 0.0;
60 } else if (tradingExCoupon(d)) {
61 return -dayCounter().yearFraction(d, std::max(d, accrualEndDate_),
63 } else {
65 std::min(d, accrualEndDate_),
68 }
69 }
70
72 if (d <= accrualStartDate_ || d > paymentDate_) {
73 return 0;
74 } else {
76 std::min(d, accrualEndDate_));
77 }
78 }
79
81 auto* v1 = dynamic_cast<Visitor<Coupon>*>(&v);
82 if (v1 != nullptr)
83 v1->visit(*this);
84 else
85 CashFlow::accept(v);
86 }
87
88}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
bool tradingExCoupon(const Date &refDate=Date()) const
returns true if the cashflow is trading ex-coupon on the refDate
Definition: cashflow.cpp:51
Date::serial_type accrualDays() const
accrual period in days
Definition: coupon.cpp:52
Date paymentDate_
Definition: coupon.hpp:90
Date refPeriodEnd_
Definition: coupon.hpp:92
void accept(AcyclicVisitor &) override
Definition: coupon.cpp:80
Date accrualStartDate_
Definition: coupon.hpp:92
Date refPeriodStart_
Definition: coupon.hpp:92
virtual DayCounter dayCounter() const =0
day counter for accrual calculation
Date accrualEndDate_
Definition: coupon.hpp:92
Real accrualPeriod_
Definition: coupon.hpp:94
Time accruedPeriod(const Date &) const
accrued period as fraction of year at the given date
Definition: coupon.cpp:57
Date::serial_type accruedDays(const Date &) const
accrued days at the given date
Definition: coupon.cpp:71
Time accrualPeriod() const
accrual period as fraction of year
Definition: coupon.cpp:44
Coupon(const Date &paymentDate, Real nominal, const Date &accrualStartDate, const Date &accrualEndDate, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date(), const Date &exCouponDate=Date())
Definition: coupon.cpp:27
Concrete date class.
Definition: date.hpp:125
std::int_fast32_t serial_type
serial number type
Definition: date.hpp:128
Date::serial_type dayCount(const Date &, const Date &) const
Returns the number of days between two dates.
Definition: daycounter.hpp:122
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
template class providing a null value for a given type.
Definition: null.hpp:76
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Coupon accruing over a fixed period.
day counter class
Date d
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
ext::shared_ptr< BlackVolTermStructure > v
degenerate base class for the Acyclic Visitor pattern