QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmbermudanstepcondition.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2010 Klaus Spanderen
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
23#include <utility>
24
25namespace QuantLib {
26
28 const std::vector<Date>& exerciseDates,
29 const Date& referenceDate,
30 const DayCounter& dayCounter,
31 ext::shared_ptr<FdmMesher> mesher,
32 ext::shared_ptr<FdmInnerValueCalculator> calculator)
33 : mesher_(std::move(mesher)), calculator_(std::move(calculator)) {
34
35 exerciseTimes_.reserve(exerciseDates.size());
36 for (auto exerciseDate : exerciseDates) {
37 exerciseTimes_.push_back(dayCounter.yearFraction(referenceDate, exerciseDate));
38 }
39 }
40
41 const std::vector<Time>& FdmBermudanStepCondition::exerciseTimes() const {
42 return exerciseTimes_;
43 }
44
46 if (std::find(exerciseTimes_.begin(), exerciseTimes_.end(), t)
47 != exerciseTimes_.end()) {
48
49 QL_REQUIRE(mesher_->layout()->size() == a.size(),
50 "inconsistent array dimensions");
51
52 const Size dims = mesher_->layout()->dim().size();
53 Array locations(dims);
54
55 for (const auto& iter : *mesher_->layout()) {
56 for (Size i=0; i < dims; ++i)
57 locations[i] = mesher_->location(iter, i);
58
59 const Real innerValue = calculator_->innerValue(iter, t);
60 if (innerValue > a[iter.index()]) {
61 a[iter.index()] = innerValue;
62 }
63 }
64 }
65 }
66}
1-D array used in linear algebra.
Definition: array.hpp:52
Size size() const
dimension of the array
Definition: array.hpp:495
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
FdmBermudanStepCondition(const std::vector< Date > &exerciseDates, const Date &referenceDate, const DayCounter &dayCounter, ext::shared_ptr< FdmMesher > mesher, ext::shared_ptr< FdmInnerValueCalculator > calculator)
const ext::shared_ptr< FdmMesher > mesher_
const ext::shared_ptr< FdmInnerValueCalculator > calculator_
void applyTo(Array &a, Time t) const override
const std::vector< Time > & exerciseTimes() const
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
const ext::shared_ptr< CEVCalculator > calculator_
bermudan step condition for multi dimensional problems
layer of abstraction to calculate the inner value
memory layout of a fdm linear operator
const ext::shared_ptr< FdmMesher > mesher_
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.