QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
timebasket.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003 Decillion Pty(Ltd)
5 Copyright (C) 2003 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
25#ifndef quantlib_time_basket_hpp
26#define quantlib_time_basket_hpp
27
28#include <ql/time/date.hpp>
29#include <ql/utilities/null.hpp>
30#include <vector>
31#include <map>
32
33namespace QuantLib {
34
36 class TimeBasket : private std::map<Date,Real> {
37 // this is needed for Visual C++ 6
38 typedef std::map<Date,Real> super;
39 public:
40 TimeBasket() = default;
41 TimeBasket(const std::vector<Date>& dates,
42 const std::vector<Real>& values);
44
45
46 using super::size;
48 using super::operator[];
49 // iterators
50 typedef super::iterator iterator;
51 typedef super::const_iterator const_iterator;
52 typedef super::reverse_iterator reverse_iterator;
53 typedef super::const_reverse_iterator const_reverse_iterator;
54 using super::begin;
55 using super::end;
56 using super::rbegin;
57 using super::rend;
59 bool hasDate(const Date&) const;
61
63 TimeBasket& operator+=(const TimeBasket& other);
64 TimeBasket& operator-=(const TimeBasket& other);
66
68
69 TimeBasket rebin(const std::vector<Date>& buckets) const;
71 };
72
73
74 // inline definitions
75
76 inline bool TimeBasket::hasDate(const Date& d) const {
77 auto i = find(d);
78 return i != end();
79 }
80
82 super& self = *this;
83 for (auto j : other)
84 self[j.first] += j.second;
85 return *this;
86 }
87
89 super& self = *this;
90 for (auto j : other)
91 self[j.first] -= j.second;
92 return *this;
93 }
94
95}
96
97
98#endif
Concrete date class.
Definition: date.hpp:125
Distribution over a number of dates.
Definition: timebasket.hpp:36
bool hasDate(const Date &) const
membership
Definition: timebasket.hpp:76
TimeBasket rebin(const std::vector< Date > &buckets) const
redistribute the entries over the given dates
Definition: timebasket.cpp:36
std::map< Date, Real > super
Definition: timebasket.hpp:38
TimeBasket & operator-=(const TimeBasket &other)
Definition: timebasket.hpp:88
super::iterator iterator
Definition: timebasket.hpp:50
TimeBasket & operator+=(const TimeBasket &other)
Definition: timebasket.hpp:81
super::const_reverse_iterator const_reverse_iterator
Definition: timebasket.hpp:53
super::const_iterator const_iterator
Definition: timebasket.hpp:51
super::reverse_iterator reverse_iterator
Definition: timebasket.hpp:52
Definition: any.hpp:35