31#ifndef quantlib_cash_flow_vectors_hpp
32#define quantlib_cash_flow_vectors_hpp
47 const std::vector<Rate>& caps,
48 const std::vector<Rate>& floors,
51 bool noOption(
const std::vector<Rate>& caps,
52 const std::vector<Rate>& floors,
58 template <
typename InterestRateIndexType,
59 typename FloatingCouponType,
60 typename CappedFlooredCouponType>
62 const std::vector<Real>& nominals,
63 const ext::shared_ptr<InterestRateIndexType>& index,
66 const std::vector<Natural>& fixingDays,
67 const std::vector<Real>& gearings,
68 const std::vector<Spread>& spreads,
69 const std::vector<Rate>& caps,
70 const std::vector<Rate>& floors,
78 bool exCouponEndOfMonth =
false) {
81 QL_REQUIRE(!nominals.empty(),
"no notional given");
83 "too many nominals (" << nominals.size() <<
84 "), only " <<
n <<
" required");
86 "too many gearings (" << gearings.size() <<
87 "), only " <<
n <<
" required");
89 "too many spreads (" << spreads.size() <<
90 "), only " <<
n <<
" required");
92 "too many caps (" << caps.size() <<
93 "), only " <<
n <<
" required");
95 "too many floors (" << floors.size() <<
96 "), only " <<
n <<
" required");
98 "in-arrears and zero features are not compatible");
100 Leg leg; leg.reserve(
n);
105 if (paymentCalendar.empty()) {
106 paymentCalendar = calendar;
108 Date refStart, start, refEnd, end;
112 for (
Size i=0; i<
n; ++i) {
113 refStart = start = schedule.
date(i);
114 refEnd = end = schedule.
date(i+1);
116 isZero ? lastPaymentDate : paymentCalendar.
advance(end, paymentLag,
Days, paymentAdj);
119 refStart = calendar.
adjust(end - schedule.
tenor(), bdc);
123 refEnd = calendar.
adjust(start + schedule.
tenor(), bdc);
125 if (exCouponPeriod !=
Period()) {
126 if (exCouponCalendar.empty()) {
127 exCouponCalendar = calendar;
129 exCouponDate = exCouponCalendar.
advance(paymentDate, -exCouponPeriod,
130 exCouponAdjustment, exCouponEndOfMonth);
133 leg.push_back(ext::shared_ptr<CashFlow>(
new
139 start, end, refStart, refEnd,
143 leg.push_back(ext::shared_ptr<CashFlow>(
new
153 paymentDayCounter, isInArrears, exCouponDate)));
155 leg.push_back(ext::shared_ptr<CashFlow>(
new
156 CappedFlooredCouponType(
168 isInArrears, exCouponDate)));
176 template <
typename InterestRateIndexType,
177 typename FloatingCouponType,
178 typename DigitalCouponType>
181 const std::vector<Real>& nominals,
182 const ext::shared_ptr<InterestRateIndexType>& index,
185 const std::vector<Natural>& fixingDays,
186 const std::vector<Real>& gearings,
187 const std::vector<Spread>& spreads,
189 const std::vector<Rate>& callStrikes,
191 bool isCallATMIncluded,
192 const std::vector<Rate>& callDigitalPayoffs,
193 const std::vector<Rate>& putStrikes,
195 bool isPutATMIncluded,
196 const std::vector<Rate>& putDigitalPayoffs,
197 const ext::shared_ptr<DigitalReplication>& replication,
198 bool nakedOption =
false) {
200 QL_REQUIRE(!nominals.empty(),
"no notional given");
202 "too many nominals (" << nominals.size() <<
203 "), only " <<
n <<
" required");
205 "too many gearings (" << gearings.size() <<
206 "), only " <<
n <<
" required");
208 "too many spreads (" << spreads.size() <<
209 "), only " <<
n <<
" required");
211 "too many call rates (" << callStrikes.size() <<
212 "), only " <<
n <<
" required");
214 "too many put rates (" << putStrikes.size() <<
215 "), only " <<
n <<
" required");
217 Leg leg; leg.reserve(
n);
222 Date refStart, start, refEnd, end;
225 for (
Size i=0; i<
n; ++i) {
226 refStart = start = schedule.
date(i);
227 refEnd = end = schedule.
date(i+1);
228 paymentDate = calendar.
adjust(end, paymentAdj);
231 refStart = calendar.
adjust(end - schedule.
tenor(), bdc);
235 refEnd = calendar.
adjust(start + schedule.
tenor(), bdc);
238 leg.push_back(ext::shared_ptr<CashFlow>(
new
243 start, end, refStart, refEnd)));
245 ext::shared_ptr<FloatingCouponType> underlying(
new
246 FloatingCouponType(paymentDate,
254 paymentDayCounter, isInArrears));
255 leg.push_back(ext::shared_ptr<CashFlow>(
new
266 replication, nakedOption)));
Date adjust(const Date &, BusinessDayConvention convention=Following) const
static Date advance(const Date &d, Integer units, TimeUnit)
Coupon paying a fixed interest rate
template class providing a null value for a given type.
const Calendar & calendar() const
bool isRegular(Size i) const
const Date & date(Size i) const
BusinessDayConvention businessDayConvention() const
bool hasIsRegular() const
const Period & tenor() const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Coupon paying a fixed annual rate.
BusinessDayConvention
Business Day conventions.
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
T get(const std::vector< T > &v, Size i, U defaultValue)
Rate effectiveFixedRate(const std::vector< Spread > &spreads, const std::vector< Rate > &caps, const std::vector< Rate > &floors, Size i)
bool noOption(const std::vector< Rate > &caps, const std::vector< Rate > &floors, Size i)
Leg FloatingLeg(const Schedule &schedule, const std::vector< Real > &nominals, const ext::shared_ptr< InterestRateIndexType > &index, const DayCounter &paymentDayCounter, BusinessDayConvention paymentAdj, const std::vector< Natural > &fixingDays, const std::vector< Real > &gearings, const std::vector< Spread > &spreads, const std::vector< Rate > &caps, const std::vector< Rate > &floors, bool isInArrears, bool isZero, Integer paymentLag=0, Calendar paymentCalendar=Calendar(), Period exCouponPeriod=Period(), Calendar exCouponCalendar=Calendar(), BusinessDayConvention exCouponAdjustment=Unadjusted, bool exCouponEndOfMonth=false)
Leg FloatingDigitalLeg(const Schedule &schedule, const std::vector< Real > &nominals, const ext::shared_ptr< InterestRateIndexType > &index, const DayCounter &paymentDayCounter, BusinessDayConvention paymentAdj, const std::vector< Natural > &fixingDays, const std::vector< Real > &gearings, const std::vector< Spread > &spreads, bool isInArrears, const std::vector< Rate > &callStrikes, Position::Type callPosition, bool isCallATMIncluded, const std::vector< Rate > &callDigitalPayoffs, const std::vector< Rate > &putStrikes, Position::Type putPosition, bool isPutATMIncluded, const std::vector< Rate > &putDigitalPayoffs, const ext::shared_ptr< DigitalReplication > &replication, bool nakedOption=false)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Sub, Central, or Super replication.
Utilities for vector manipulation.