24#include <ql/time/period.hpp>
25#include <ql/errors.hpp>
63 QL_FAIL(
"unknown frequency");
65 QL_FAIL(
"unknown frequency (" <<
Integer(f) <<
")");
154 "impossible addition between " << *
this <<
158 QL_FAIL(
"unknown time unit (" <<
Integer(p.
units()) <<
")");
170 "impossible addition between " << *
this <<
174 QL_FAIL(
"unknown time unit (" <<
Integer(p.
units()) <<
")");
187 "impossible addition between " << *
this <<
191 QL_FAIL(
"unknown time unit (" <<
Integer(p.
units()) <<
")");
203 "impossible addition between " << *
this <<
207 QL_FAIL(
"unknown time unit (" <<
Integer(p.
units()) <<
")");
229 QL_REQUIRE(n != 0,
"cannot be divided by zero");
251 QL_REQUIRE(
length % n == 0,
252 *
this <<
" cannot be divided by " << n);
262 std::pair<Integer,Integer> daysMinMax(
const Period& p) {
273 QL_FAIL(
"unknown time unit (" <<
Integer(p.
units()) <<
")");
280 if (p.
length()==0)
return 0.0;
284 QL_FAIL(
"cannot convert Days into Years");
286 QL_FAIL(
"cannot convert Weeks into Years");
292 QL_FAIL(
"unknown time unit (" <<
Integer(p.
units()) <<
")");
297 if (p.
length()==0)
return 0.0;
301 QL_FAIL(
"cannot convert Days into Months");
303 QL_FAIL(
"cannot convert Weeks into Months");
309 QL_FAIL(
"unknown time unit (" <<
Integer(p.
units()) <<
")");
314 if (p.
length()==0)
return 0.0;
322 QL_FAIL(
"cannot convert Months into Weeks");
324 QL_FAIL(
"cannot convert Years into Weeks");
326 QL_FAIL(
"unknown time unit (" <<
Integer(p.
units()) <<
")");
331 if (p.
length()==0)
return 0.0;
339 QL_FAIL(
"cannot convert Months into Days");
341 QL_FAIL(
"cannot convert Years into Days");
343 QL_FAIL(
"unknown time unit (" <<
Integer(p.
units()) <<
")");
368 std::pair<Integer, Integer> p1lim = daysMinMax(p1);
369 std::pair<Integer, Integer> p2lim = daysMinMax(p2);
371 if (p1lim.second < p2lim.first)
373 else if (p1lim.first > p2lim.second)
376 QL_FAIL(
"undecidable comparison between " << p1 <<
" and " << p2);
407 switch (holder.
p.
units()) {
409 return out << n << (n == 1 ?
" day" :
" days");
411 return out << n << (n == 1 ?
" week" :
" weeks");
413 return out << n << (n == 1 ?
" month" :
" months");
415 return out << n << (n == 1 ?
" year" :
" years");
417 QL_FAIL(
"unknown time unit (" <<
Integer(holder.
p.
units()) <<
")");
424 switch (holder.
p.
units()) {
426 return out << n <<
"D";
428 return out << n <<
"W";
430 return out << n <<
"M";
432 return out << n <<
"Y";
434 QL_FAIL(
"unknown time unit (" <<
Integer(holder.
p.
units()) <<
")");
Period & operator+=(const Period &)
Period & operator/=(Integer)
Period & operator*=(Integer)
Period & operator-=(const Period &)
Frequency frequency() const
Frequency
Frequency of events.
TimeUnit
Units used to describe time periods.
@ Biweekly
every second week
@ EveryFourthWeek
every fourth week
@ OtherFrequency
some other unknown frequency
@ Bimonthly
every second month
@ Once
only once, e.g., a zero-coupon
@ Quarterly
every third month
@ EveryFourthMonth
every fourth month
@ NoFrequency
null frequency
detail::short_period_holder short_period(const Period &p)
output periods in short format (e.g. "2w")
detail::long_period_holder long_period(const Period &p)
output periods in long format (e.g. "2 weeks")
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
std::ostream & operator<<(std::ostream &out, const short_date_holder &holder)
Quantity operator-(const Quantity &m1, const Quantity &m2)
Real weeks(const Period &p)
bool operator<(const Quantity &m1, const Quantity &m2)
Real months(const Period &p)
Real years(const Period &p)
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
Quantity operator+(const Quantity &m1, const Quantity &m2)
Real days(const Period &p)
Real operator/(const Quantity &m1, const Quantity &m2)