QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Attributes | Related Functions | List of all members
Calendar Class Reference

calendar class More...

#include <ql/time/calendar.hpp>

+ Inheritance diagram for Calendar:
+ Collaboration diagram for Calendar:

Classes

class  Impl
 abstract base class for calendar implementations More...
 
class  OrthodoxImpl
 partial calendar implementation More...
 
class  WesternImpl
 partial calendar implementation More...
 

Public Member Functions

 Calendar ()=default
 
Calendar interface
bool empty () const
 Returns whether or not the calendar is initialized. More...
 
std::string name () const
 Returns the name of the calendar. More...
 
const std::set< Date > & addedHolidays () const
 
const std::set< Date > & removedHolidays () const
 
void resetAddedAndRemovedHolidays ()
 
bool isBusinessDay (const Date &d) const
 
bool isHoliday (const Date &d) const
 
bool isWeekend (Weekday w) const
 
bool isEndOfMonth (const Date &d) const
 
Date endOfMonth (const Date &d) const
 last business day of the month to which the given date belongs More...
 
void addHoliday (const Date &)
 
void removeHoliday (const Date &)
 
std::vector< DateholidayList (const Date &from, const Date &to, bool includeWeekEnds=false) const
 
std::vector< DatebusinessDayList (const Date &from, const Date &to) const
 
Date adjust (const Date &, BusinessDayConvention convention=Following) const
 
Date advance (const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
 
Date advance (const Date &date, const Period &period, BusinessDayConvention convention=Following, bool endOfMonth=false) const
 
Date::serial_type businessDaysBetween (const Date &from, const Date &to, bool includeFirst=true, bool includeLast=false) const
 

Protected Attributes

ext::shared_ptr< Implimpl_
 

Related Functions

(Note that these are not member functions.)

bool operator== (const Calendar &, const Calendar &)
 
bool operator!= (const Calendar &, const Calendar &)
 
std::ostream & operator<< (std::ostream &, const Calendar &)
 

Detailed Description

calendar class

This class provides methods for determining whether a date is a business day or a holiday for a given market, and for incrementing/decrementing a date of a given number of business days.

The Bridge pattern is used to provide the base behavior of the calendar, namely, to determine whether a date is a business day.

A calendar should be defined for specific exchange holiday schedule or for general country holiday schedule. Legacy city holiday schedule calendars will be moved to the exchange/country convention.

Tests:
the methods for adding and removing holidays are tested by inspecting the calendar before and after their invocation.
Examples
BasketLosses.cpp, BermudanSwaption.cpp, Bonds.cpp, CDS.cpp, CVAIRS.cpp, CallableBonds.cpp, ConvertibleBonds.cpp, DiscreteHedging.cpp, EquityOption.cpp, FRA.cpp, FittedBondCurve.cpp, LatentModel.cpp, MulticurveBootstrapping.cpp, and Repo.cpp.

Definition at line 61 of file calendar.hpp.

Constructor & Destructor Documentation

◆ Calendar()

Calendar ( )
default

The default constructor returns a calendar with a null implementation, which is therefore unusable except as a placeholder.

Member Function Documentation

◆ empty()

bool empty ( ) const

Returns whether or not the calendar is initialized.

Definition at line 202 of file calendar.hpp.

+ Here is the caller graph for this function:

◆ name()

std::string name ( ) const

Returns the name of the calendar.

Warning:
This method is used for output and comparison between calendars. It is not meant to be used for writing switch-on-type code.

Definition at line 206 of file calendar.hpp.

+ Here is the caller graph for this function:

◆ addedHolidays()

const std::set< Date > & addedHolidays ( ) const

Returns true iff the date is a business day for the given market.

Returns the set of added holidays for the given calendar

Definition at line 211 of file calendar.hpp.

◆ removedHolidays()

const std::set< Date > & removedHolidays ( ) const

Returns the set of removed holidays for the given calendar

Definition at line 217 of file calendar.hpp.

◆ resetAddedAndRemovedHolidays()

void resetAddedAndRemovedHolidays ( )

Clear the set of added and removed holidays

Definition at line 79 of file calendar.cpp.

◆ isBusinessDay()

bool isBusinessDay ( const Date d) const

Definition at line 223 of file calendar.hpp.

+ Here is the caller graph for this function:

◆ isHoliday()

bool isHoliday ( const Date d) const

Returns true iff the date is a holiday for the given market.

Definition at line 251 of file calendar.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isWeekend()

bool isWeekend ( Weekday  w) const

Returns true iff the weekday is part of the weekend for the given market.

Definition at line 255 of file calendar.hpp.

+ Here is the caller graph for this function:

◆ isEndOfMonth()

bool isEndOfMonth ( const Date d) const

Returns true iff in the given market, the date is on or after the last business day for that month.

Definition at line 243 of file calendar.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endOfMonth()

Date endOfMonth ( const Date d) const

last business day of the month to which the given date belongs

Definition at line 247 of file calendar.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addHoliday()

void addHoliday ( const Date d)

Adds a date to the set of holidays for the given calendar.

Definition at line 45 of file calendar.cpp.

◆ removeHoliday()

void removeHoliday ( const Date d)

Removes a date from the set of holidays for the given calendar.

Definition at line 62 of file calendar.cpp.

◆ holidayList()

std::vector< Date > holidayList ( const Date from,
const Date to,
bool  includeWeekEnds = false 
) const

Returns the holidays between two dates.

Definition at line 271 of file calendar.cpp.

+ Here is the call graph for this function:

◆ businessDayList()

std::vector< Date > businessDayList ( const Date from,
const Date to 
) const

Returns the business days between two dates.

Definition at line 285 of file calendar.cpp.

+ Here is the call graph for this function:

◆ adjust()

Date adjust ( const Date d,
BusinessDayConvention  convention = Following 
) const

Adjusts a non-business day to the appropriate near business day with respect to the given convention.

Examples
BasketLosses.cpp, Bonds.cpp, CDS.cpp, CVAIRS.cpp, ConvertibleBonds.cpp, FittedBondCurve.cpp, LatentModel.cpp, and MulticurveBootstrapping.cpp.

Definition at line 84 of file calendar.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ advance() [1/2]

Date advance ( const Date d,
Integer  n,
TimeUnit  unit,
BusinessDayConvention  convention = Following,
bool  endOfMonth = false 
) const

Advances the given date of the given number of business days and returns the result.

Note
The input date is not modified.
Examples
BermudanSwaption.cpp, Bonds.cpp, CDS.cpp, CVAIRS.cpp, CallableBonds.cpp, ConvertibleBonds.cpp, FRA.cpp, FittedBondCurve.cpp, Gaussian1dModels.cpp, LatentModel.cpp, and MulticurveBootstrapping.cpp.

Definition at line 130 of file calendar.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ advance() [2/2]

Date advance ( const Date date,
const Period period,
BusinessDayConvention  convention = Following,
bool  endOfMonth = false 
) const

Advances the given date as specified by the given period and returns the result.

Note
The input date is not modified.

Definition at line 169 of file calendar.cpp.

+ Here is the call graph for this function:

◆ businessDaysBetween()

Date::serial_type businessDaysBetween ( const Date from,
const Date to,
bool  includeFirst = true,
bool  includeLast = false 
) const

Calculates the number of business days between two given dates and returns the result.

Definition at line 176 of file calendar.cpp.

+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator==()

bool operator== ( const Calendar ,
const Calendar  
)
related

Returns true iff the two calendars belong to the same derived class.

Definition at line 260 of file calendar.hpp.

+ Here is the call graph for this function:

◆ operator!=()

bool operator!= ( const Calendar ,
const Calendar  
)
related

Definition at line 265 of file calendar.hpp.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  ,
const Calendar  
)
related

Definition at line 269 of file calendar.hpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ impl_

ext::shared_ptr<Impl> impl_
protected

Definition at line 72 of file calendar.hpp.