Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ZeroFixedCoupon Class Reference

#include <qle/cashflows/zerofixedcoupon.hpp>

+ Inheritance diagram for ZeroFixedCoupon:
+ Collaboration diagram for ZeroFixedCoupon:

Public Member Functions

 ZeroFixedCoupon (const Date &paymentDate, double notional, double rate, const DayCounter &dc, const std::vector< Date > &dates, const Compounding &comp, bool subtractNotional)
 
Coupon interface
Real amount () const override
 
Real nominal () const override
 
Real rate () const override
 
DayCounter dayCounter () const override
 
Real accruedAmount (const Date &accrualEnd) const override
 

Visitability

double notional_
 
double rate_
 
DayCounter dc_
 
std::vector< Date > dates_
 
Compounding comp_
 
bool subtractNotional_
 
double amount_
 
void accept (AcyclicVisitor &) override
 

Detailed Description

Definition at line 40 of file zerofixedcoupon.hpp.

Constructor & Destructor Documentation

◆ ZeroFixedCoupon()

ZeroFixedCoupon ( const Date &  paymentDate,
double  notional,
double  rate,
const DayCounter &  dc,
const std::vector< Date > &  dates,
const Compounding &  comp,
bool  subtractNotional 
)

Definition at line 23 of file zerofixedcoupon.cpp.

29 :
30 Coupon(paymentDate, notional, dates.front(), dates.back()),
31 notional_(notional), rate_(rate), dc_(dc), dates_(dates),
32 comp_(comp), subtractNotional_(subtractNotional)
33 {
34
35 QL_REQUIRE(comp_ == QuantLib::Compounded || comp_ == QuantLib::Simple,
36 "Compounding method " << comp_ << " not supported");
37
38 QL_REQUIRE(dates_.size() >= 2, "Number of schedule dates expected at least 2, got " << dates_.size());
39
41
42 }//ctor
std::vector< Date > dates_
Real accruedAmount(const Date &accrualEnd) const override
Real rate() const override
+ Here is the call graph for this function:

Member Function Documentation

◆ amount()

Real amount ( ) const
override

Definition at line 44 of file zerofixedcoupon.cpp.

44{ return amount_; }

◆ nominal()

Real nominal ( ) const
override

Definition at line 46 of file zerofixedcoupon.cpp.

46{ return notional_; }

◆ rate()

Real rate ( ) const
override

Definition at line 48 of file zerofixedcoupon.cpp.

48{ return rate_; }

◆ dayCounter()

DayCounter dayCounter ( ) const
override

Definition at line 50 of file zerofixedcoupon.cpp.

50{ return dc_; }

◆ accruedAmount()

Real accruedAmount ( const Date &  accrualEnd) const
override

Definition at line 52 of file zerofixedcoupon.cpp.

52 {
53
54 //outside this period, return zero
55 if(dates_.front() > accrualEnd || dates_.back() < accrualEnd)
56 return 0.0;
57
58 double totalDCF = 0.0;
59 double compoundFactor = 1.0;
60
61 // we loop over the dates in the schedule, computing the compound factor.
62 // For the Compounded rule:
63 // (1+r)^dcf_0 * (1+r)^dcf_1 * ... = (1+r)^(dcf_0 + dcf_1 + ...)
64 // So we compute the sum of all DayCountFractions in the loop.
65 // For the Simple rule:
66 // (1 + r * dcf_0) * (1 + r * dcf_1)...
67
68 for (Size i = 0; i < dates_.size() - 1; i++) {
69
70 Date startDate = dates_[i];
71 Date endDate = dates_[i+1];
72
73 if(startDate > accrualEnd)
74 break;
75
76 if(endDate > accrualEnd)
77 endDate = accrualEnd;
78
79 double dcf = dc_.yearFraction(startDate, endDate);
80
81 if (comp_ == QuantLib::Simple)
82 compoundFactor *= (1 + rate_ * dcf);
83
84 totalDCF += dcf;
85 }
86
87 if (comp_ == QuantLib::Compounded)
88 compoundFactor = pow(1.0 + rate_, totalDCF);
89
90 return notional_ * (subtractNotional_ ? compoundFactor - 1.0 : compoundFactor);
91
92
93
94}
CompiledFormula pow(CompiledFormula x, const CompiledFormula &y)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ accept()

void accept ( AcyclicVisitor &  v)
override

Definition at line 98 of file zerofixedcoupon.cpp.

98 {
99 Visitor<ZeroFixedCoupon>* v1 = dynamic_cast<Visitor<ZeroFixedCoupon>*>(&v);
100 if (v1 != 0)
101 v1->visit(*this);
102 else
103 Coupon::accept(v);
104}

Member Data Documentation

◆ notional_

double notional_
private

Definition at line 66 of file zerofixedcoupon.hpp.

◆ rate_

double rate_
private

Definition at line 67 of file zerofixedcoupon.hpp.

◆ dc_

DayCounter dc_
private

Definition at line 68 of file zerofixedcoupon.hpp.

◆ dates_

std::vector<Date> dates_
private

Definition at line 69 of file zerofixedcoupon.hpp.

◆ comp_

Compounding comp_
private

Definition at line 70 of file zerofixedcoupon.hpp.

◆ subtractNotional_

bool subtractNotional_
private

Definition at line 71 of file zerofixedcoupon.hpp.

◆ amount_

double amount_
private

Definition at line 73 of file zerofixedcoupon.hpp.