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

Handles non-contiguous time period. More...

#include <ored/utilities/timeperiod.hpp>

+ Collaboration diagram for TimePeriod:

Public Member Functions

 TimePeriod (const std::vector< Date > &dates, Size mporDays=QuantLib::Null< Size >(), const QuantLib::Calendar &calendar=QuantLib::Calendar())
 
Size numberOfContiguousParts () const
 
const std::vector< Date > & startDates () const
 
const std::vector< Date > & endDates () const
 
bool contains (const Date &d) const
 

Private Attributes

std::vector< Date > startDates_
 
std::vector< Date > endDates_
 

Detailed Description

Handles non-contiguous time period.

Definition at line 41 of file timeperiod.hpp.

Constructor & Destructor Documentation

◆ TimePeriod()

TimePeriod ( const std::vector< Date > &  dates,
Size  mporDays = QuantLib::Null<Size>(),
const QuantLib::Calendar &  calendar = QuantLib::Calendar() 
)

Definition at line 28 of file timeperiod.cpp.

28 {
29 QL_REQUIRE(dates.size() % 2 == 0, "TimePeriod: dates size must be an even number, got " << dates.size());
30 for (Size i = 0; i < dates.size(); ++i) {
31 if (i % 2 == 0) {
32 Date sDate = dates[i];
33 if (!calendar.empty() && mporDays != QuantLib::Null<Size>())
34 sDate = calendar.advance(sDate, -mporDays * QuantLib::Days);
35 startDates_.push_back(sDate);
36 }
37 else
38 endDates_.push_back(dates[i]);
39 }
40}
std::vector< Date > startDates_
Definition: timeperiod.hpp:57
std::vector< Date > endDates_
Definition: timeperiod.hpp:57
Calendar calendar
Definition: utilities.cpp:441

Member Function Documentation

◆ numberOfContiguousParts()

Size numberOfContiguousParts ( ) const

Definition at line 51 of file timeperiod.hpp.

51{ return startDates_.size(); }
+ Here is the caller graph for this function:

◆ startDates()

const std::vector< Date > & startDates ( ) const

Definition at line 52 of file timeperiod.hpp.

52{ return startDates_; }
+ Here is the caller graph for this function:

◆ endDates()

const std::vector< Date > & endDates ( ) const

Definition at line 53 of file timeperiod.hpp.

53{ return endDates_; }
+ Here is the caller graph for this function:

◆ contains()

bool contains ( const Date &  d) const

Definition at line 42 of file timeperiod.cpp.

42 {
43 for (Size i = 0; i < startDates_.size(); ++i) {
44 if (d >= startDates_[i] && d <= endDates_[i])
45 return true;
46 }
47 return false;
48}

Member Data Documentation

◆ startDates_

std::vector<Date> startDates_
private

Definition at line 57 of file timeperiod.hpp.

◆ endDates_

std::vector<Date> endDates_
private

Definition at line 57 of file timeperiod.hpp.