Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
dategrid.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file ored/utilities/dategrid.hpp
20 \brief The date grid class
21 \ingroup simulation
22*/
23
24#pragma once
25#include <map>
26#include <ql/time/calendars/target.hpp>
27#include <ql/time/daycounters/actualactual.hpp>
28#include <ql/timegrid.hpp>
29
30namespace ore {
31namespace data {
32
33//! Simulation Date Grid
34/*!
35 Utility for building a simulation date grid.
36 \ingroup simulation
37 */
38class DateGrid {
39public:
40 //! Build a date grid with a single date equal to Settings::instance().evaluationDate()
41 DateGrid();
42
43 /*! Build a date grid from a string which can be of the form 40,1M or 1D,2D,1W,2W,3Y,5Y or a fixed name (ALPHA,
44 BETA) indicating a hard coded grid structure
45 */
46 DateGrid(const std::string& grid, const QuantLib::Calendar& gridCalendar = QuantLib::TARGET(),
47 const QuantLib::DayCounter& dayCounter = QuantLib::ActualActual(QuantLib::ActualActual::ISDA));
48
49 //! Build a date grid from the given vector of tenors.
50 DateGrid(const std::vector<QuantLib::Period>& tenors, const QuantLib::Calendar& gridCalendar = QuantLib::TARGET(),
51 const QuantLib::DayCounter& dayCounter = QuantLib::ActualActual(QuantLib::ActualActual::ISDA));
52
53 //! Build a date grid from an explicit set of dates, sorted in ascending order.
54 DateGrid(const std::vector<QuantLib::Date>& dates, const QuantLib::Calendar& gridCalendar = QuantLib::TARGET(),
55 const QuantLib::DayCounter& dayCounter = QuantLib::ActualActual(QuantLib::ActualActual::ISDA));
56
57 //! The size of the date grid
58 QuantLib::Size size() const { return dates_.size(); }
59
60 //! Truncate the grid up to the given date.
61 /*! If overrun is true, we make sure the last date in the grid is greater than
62 the portfolio maturity, even though every scenario portfolio NPV will be 0
63 at this point we may need the market data.
64 If overrun is false, the last date in the grid is the last date where the
65 portfolio is live.
66 */
67 void truncate(const QuantLib::Date& d, bool overrun = true);
68
69 //! Truncate the grid to the given length
70 void truncate(QuantLib::Size length);
71
72 /*! Add close out dates. If 0D is given, the valuation dates itself are treated
73 as close out dates. The first date is a valuation date only and the last
74 date is a close out date only then, all other dates are both valuation and
75 close out dates. */
76 void addCloseOutDates(const QuantLib::Period& p = QuantLib::Period(2, QuantLib::Weeks));
77
78 //! \name Inspectors
79 //@{
80 const std::vector<QuantLib::Period>& tenors() const { return tenors_; }
81 const std::vector<QuantLib::Date>& dates() const { return dates_; }
82 const std::vector<bool>& isValuationDate() const { return isValuationDate_; }
83 const std::vector<bool>& isCloseOutDate() const { return isCloseOutDate_; }
84 std::vector<QuantLib::Date> valuationDates() const;
85 std::vector<QuantLib::Date> closeOutDates() const;
86 const QuantLib::Calendar& calendar() const { return calendar_; }
87 const QuantLib::DayCounter& dayCounter() const { return dayCounter_; }
88
89 //! Returns the times from Settings::instance().evaluationDate to each Date using the day counter
90 const std::vector<QuantLib::Time>& times() const { return times_; }
91
92 //! Returns the time grid associated with the vector of times (plus t=0)
93 const QuantLib::TimeGrid& timeGrid() const { return timeGrid_; }
94 //@}
95
96 //! Returns the time grid associated with the vector of valuation times (plus t=0)
97 QuantLib::TimeGrid valuationTimeGrid() const;
98 //@}
99
100 //! Returns the time grid associated with the vector of close-out times (plus t=0)
101 QuantLib::TimeGrid closeOutTimeGrid() const;
102 //@}
103
104 QuantLib::Date closeOutDateFromValuationDate(const QuantLib::Date& d) const;
105
106 //! Accessor methods
107 const QuantLib::Date& operator[](QuantLib::Size i) const { return dates_[i]; };
108
109private:
110 void buildDates(const QuantLib::Calendar& cal, const QuantLib::DayCounter& dc);
111 // Log the constructed DateGrid
112 void log();
113
115 QuantLib::DayCounter dayCounter_;
116 std::vector<QuantLib::Date> dates_;
117 std::map<QuantLib::Date, QuantLib::Date> valuationCloseOutMap_;
118 std::vector<QuantLib::Period> tenors_;
119 std::vector<QuantLib::Time> times_;
120 QuantLib::TimeGrid timeGrid_;
122};
123
124QuantLib::ext::shared_ptr<DateGrid> generateShiftedDateGrid(const QuantLib::ext::shared_ptr<DateGrid>& dg,
125 const QuantLib::Period& shift = QuantLib::Period(2,
126 QuantLib::Weeks));
127
128QuantLib::ext::shared_ptr<DateGrid> combineDateGrids(const QuantLib::ext::shared_ptr<DateGrid>& dg1,
129 const QuantLib::ext::shared_ptr<DateGrid>& dg2);
130
131} // namespace data
132} // namespace ore
Simulation Date Grid.
Definition: dategrid.hpp:38
void truncate(const QuantLib::Date &d, bool overrun=true)
Truncate the grid up to the given date.
const QuantLib::TimeGrid & timeGrid() const
Returns the time grid associated with the vector of times (plus t=0)
Definition: dategrid.hpp:93
void truncate(QuantLib::Size length)
Truncate the grid to the given length.
std::map< QuantLib::Date, QuantLib::Date > valuationCloseOutMap_
Definition: dategrid.hpp:117
DateGrid()
Build a date grid with a single date equal to Settings::instance().evaluationDate()
Definition: dategrid.cpp:32
const std::vector< bool > & isValuationDate() const
Definition: dategrid.hpp:82
QuantLib::TimeGrid closeOutTimeGrid() const
Returns the time grid associated with the vector of close-out times (plus t=0)
Definition: dategrid.cpp:294
QuantLib::Size size() const
The size of the date grid.
Definition: dategrid.hpp:58
std::vector< QuantLib::Date > closeOutDates() const
Definition: dategrid.cpp:275
std::vector< QuantLib::Date > dates_
Definition: dategrid.hpp:116
std::vector< QuantLib::Date > valuationDates() const
Definition: dategrid.cpp:266
const std::vector< QuantLib::Time > & times() const
Returns the times from Settings::instance().evaluationDate to each Date using the day counter.
Definition: dategrid.hpp:90
std::vector< bool > isValuationDate_
Definition: dategrid.hpp:121
const QuantLib::Calendar & calendar() const
Definition: dategrid.hpp:86
std::vector< QuantLib::Period > tenors_
Definition: dategrid.hpp:118
const QuantLib::DayCounter & dayCounter() const
Definition: dategrid.hpp:87
DateGrid(const std::vector< QuantLib::Date > &dates, const QuantLib::Calendar &gridCalendar=QuantLib::TARGET(), const QuantLib::DayCounter &dayCounter=QuantLib::ActualActual(QuantLib::ActualActual::ISDA))
Build a date grid from an explicit set of dates, sorted in ascending order.
QuantLib::Date closeOutDateFromValuationDate(const QuantLib::Date &d) const
Definition: dategrid.cpp:304
QuantLib::Calendar calendar_
Definition: dategrid.hpp:114
DateGrid(const std::vector< QuantLib::Period > &tenors, const QuantLib::Calendar &gridCalendar=QuantLib::TARGET(), const QuantLib::DayCounter &dayCounter=QuantLib::ActualActual(QuantLib::ActualActual::ISDA))
Build a date grid from the given vector of tenors.
const std::vector< QuantLib::Period > & tenors() const
Definition: dategrid.hpp:80
QuantLib::TimeGrid valuationTimeGrid() const
Returns the time grid associated with the vector of valuation times (plus t=0)
Definition: dategrid.cpp:284
const QuantLib::Date & operator[](QuantLib::Size i) const
Accessor methods.
Definition: dategrid.hpp:107
std::vector< QuantLib::Time > times_
Definition: dategrid.hpp:119
const std::vector< bool > & isCloseOutDate() const
Definition: dategrid.hpp:83
void addCloseOutDates(const QuantLib::Period &p=QuantLib::Period(2, QuantLib::Weeks))
Definition: dategrid.cpp:207
const std::vector< QuantLib::Date > & dates() const
Definition: dategrid.hpp:81
QuantLib::DayCounter dayCounter_
Definition: dategrid.hpp:115
std::vector< bool > isCloseOutDate_
Definition: dategrid.hpp:121
QuantLib::TimeGrid timeGrid_
Definition: dategrid.hpp:120
void buildDates(const QuantLib::Calendar &cal, const QuantLib::DayCounter &dc)
Definition: dategrid.cpp:139
@ data
Definition: log.hpp:77
QuantLib::ext::shared_ptr< DateGrid > combineDateGrids(const QuantLib::ext::shared_ptr< DateGrid > &dg1, const QuantLib::ext::shared_ptr< DateGrid > &dg2)
Definition: dategrid.cpp:325
QuantLib::ext::shared_ptr< DateGrid > generateShiftedDateGrid(const QuantLib::ext::shared_ptr< DateGrid > &dg, const QuantLib::Period &shift)
Definition: dategrid.cpp:312
Serializable Credit Default Swap.
Definition: namespaces.docs:23