QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmlinearoplayout.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Andreas Gaida
5 Copyright (C) 2008 Ralph Schreyer
6 Copyright (C) 2008 Klaus Spanderen
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
22#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
23
24namespace QuantLib {
25
27 Size i, Integer offset) const {
28 Size myIndex = iterator.index()
29 - iterator.coordinates()[i]*spacing_[i];
30
31 Integer coorOffset = Integer(iterator.coordinates()[i])+offset;
32 if (coorOffset < 0) {
33 coorOffset=-coorOffset;
34 }
35 else if (Size(coorOffset) >= dim_[i]) {
36 coorOffset = 2*(dim_[i]-1) - coorOffset;
37 }
38 return myIndex + coorOffset*spacing_[i];
39 }
40
42 Size i1, Integer offset1,
43 Size i2, Integer offset2) const {
44
45 Size myIndex = iterator.index()
46 - iterator.coordinates()[i1]*spacing_[i1]
47 - iterator.coordinates()[i2]*spacing_[i2];
48
49 Integer coorOffset1 = Integer(iterator.coordinates()[i1])+offset1;
50 if (coorOffset1 < 0) {
51 coorOffset1=-coorOffset1;
52 }
53 else if (Size(coorOffset1) >= dim_[i1]) {
54 coorOffset1 = 2*(dim_[i1]-1) - coorOffset1;
55 }
56
57 Integer coorOffset2 = Integer(iterator.coordinates()[i2])+offset2;
58 if (coorOffset2 < 0) {
59 coorOffset2=-coorOffset2;
60 }
61 else if (Size(coorOffset2) >= dim_[i2]) {
62 coorOffset2 = 2*(dim_[i2]-1) - coorOffset2;
63 }
64
65 return myIndex + coorOffset1*spacing_[i1]+coorOffset2*spacing_[i2];
66 }
67
68 // smart but sometimes too slow
70 const FdmLinearOpIterator& iterator, Size i, Integer offset) const {
71
72 std::vector<Size> coordinates = iterator.coordinates();
73
74 Integer coorOffset = Integer(coordinates[i])+offset;
75 if (coorOffset < 0) {
76 coorOffset=-coorOffset;
77 }
78 else if (Size(coorOffset) >= dim_[i]) {
79 coorOffset = 2*(dim_[i]-1) - coorOffset;
80 }
81 coordinates[i] = Size(coorOffset);
82
83 return FdmLinearOpIterator(dim_, coordinates,
84 index(coordinates));
85 }
86
87}
const std::vector< Size > & coordinates() const
FdmLinearOpIterator iter_neighbourhood(const FdmLinearOpIterator &iterator, Size i, Integer offset) const
Size neighbourhood(const FdmLinearOpIterator &iterator, Size i, Integer offset) const
Size index(const std::vector< Size > &coordinates) const
QL_INTEGER Integer
integer number
Definition: types.hpp:35
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35