QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
path.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
6 Copyright (C) 2003 Ferdinando Ametrano
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef quantlib_montecarlo_path_hpp
27#define quantlib_montecarlo_path_hpp
28
29#include <ql/math/array.hpp>
30#include <ql/timegrid.hpp>
31#include <utility>
32
33namespace QuantLib {
34
36
40 class Path {
41 public:
42 Path(TimeGrid timeGrid, Array values = Array());
44
45 bool empty() const;
46 Size length() const;
48 Real operator[](Size i) const;
49 Real at(Size i) const;
51 Real& at(Size i);
52 Real value(Size i) const;
53 Real& value(Size i);
55 Time time(Size i) const;
57 Real front() const;
58 Real& front();
60 Real back() const;
61 Real& back();
63 const TimeGrid& timeGrid() const;
65
69 iterator begin() const;
70 iterator end() const;
72 reverse_iterator rend() const;
74 private:
77 };
78
79
80 // inline definitions
81
82 inline Path::Path(TimeGrid timeGrid, Array values)
83 : timeGrid_(std::move(timeGrid)), values_(std::move(values)) {
84 if (values_.empty())
86 QL_REQUIRE(values_.size() == timeGrid_.size(),
87 "different number of times and asset values");
88 }
89
90 inline bool Path::empty() const {
91 return timeGrid_.empty();
92 }
93
94 inline Size Path::length() const {
95 return timeGrid_.size();
96 }
97
98 inline Real Path::operator[](Size i) const {
99 return values_[i];
100 }
101
102 inline Real Path::at(Size i) const {
103 return values_.at(i);
104 }
105
107 return values_[i];
108 }
109
110 inline Real& Path::at(Size i) {
111 return values_.at(i);
112 }
113
114 inline Real Path::value(Size i) const {
115 return values_[i];
116 }
117
118 inline Real& Path::value(Size i) {
119 return values_[i];
120 }
121
122 inline Real Path::front() const {
123 return values_[0];
124 }
125
126 inline Real& Path::front() {
127 return values_[0];
128 }
129
130 inline Real Path::back() const {
131 return values_[values_.size()-1];
132 }
133
134 inline Real& Path::back() {
135 return values_[values_.size()-1];
136 }
137
138 inline Time Path::time(Size i) const {
139 return timeGrid_[i];
140 }
141
142 inline const TimeGrid& Path::timeGrid() const {
143 return timeGrid_;
144 }
145
147 return values_.begin();
148 }
149
150 inline Path::iterator Path::end() const {
151 return values_.end();
152 }
153
155 return values_.rbegin();
156 }
157
159 return values_.rend();
160 }
161
162}
163
164
165#endif
1-D array used in linear algebra.
Definition: array.hpp:52
const Real * const_iterator
Definition: array.hpp:124
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: array.hpp:126
bool empty() const
whether the array is empty
Definition: array.hpp:499
const_reverse_iterator rend() const
Definition: array.hpp:527
const_reverse_iterator rbegin() const
Definition: array.hpp:519
const_iterator end() const
Definition: array.hpp:511
Real at(Size) const
Definition: array.hpp:444
Size size() const
dimension of the array
Definition: array.hpp:495
const_iterator begin() const
Definition: array.hpp:503
single-factor random walk
Definition: path.hpp:40
Size length() const
Definition: path.hpp:94
Array::const_reverse_iterator reverse_iterator
Definition: path.hpp:68
bool empty() const
Definition: path.hpp:90
Array::const_iterator iterator
Definition: path.hpp:67
iterator end() const
Definition: path.hpp:150
Array values_
Definition: path.hpp:76
iterator begin() const
Definition: path.hpp:146
Real back() const
final asset value
Definition: path.hpp:130
Real at(Size i) const
Definition: path.hpp:102
reverse_iterator rbegin() const
Definition: path.hpp:154
Path(TimeGrid timeGrid, Array values=Array())
Definition: path.hpp:82
const TimeGrid & timeGrid() const
time grid
Definition: path.hpp:142
Time time(Size i) const
time at the -th point
Definition: path.hpp:138
Real operator[](Size i) const
asset value at the -th point
Definition: path.hpp:98
reverse_iterator rend() const
Definition: path.hpp:158
TimeGrid timeGrid_
Definition: path.hpp:75
Real value(Size i) const
Definition: path.hpp:114
Real front() const
initial asset value
Definition: path.hpp:122
time grid class
Definition: timegrid.hpp:43
bool empty() const
Definition: timegrid.hpp:165
Size size() const
Definition: timegrid.hpp:164
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.