QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swapforwardbasissystem.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) 2009 Mark Joshi
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
24namespace QuantLib
25{
26
27 SwapForwardBasisSystem::SwapForwardBasisSystem(const std::vector<Time>& rateTimes,
28 const std::vector<Time>& exerciseTimes)
29 :
30 rateTimes_(rateTimes), exerciseTimes_(exerciseTimes),
31 rateIndex_(exerciseTimes.size()),
32 evolution_(rateTimes, exerciseTimes)
33 {
34 Size j = 0;
35 for (Size i=0; i<exerciseTimes.size(); ++i)
36 {
37 while (j < rateTimes.size() && rateTimes[j] < exerciseTimes[i])
38 ++j;
39 rateIndex_[i] = j;
40 }
41 }
42
44 {
45 return exerciseTimes_.size();
46 }
47
49 {
50 std::vector<Size> sizes(exerciseTimes_.size(), 10);
51
52 if (rateIndex_[exerciseTimes_.size()-1] == rateTimes_.size()-3)
53 sizes.back() = 6;
54
55 if (rateIndex_[exerciseTimes_.size()-1] == rateTimes_.size()-2)
56 sizes.back() = 3;
57
58 return sizes;
59 }
60
62 {
63 return evolution_;
64 }
65
67 {
69 }
70
72 {
73 currentIndex_ = 0;
74 }
75
76 std::valarray<bool> SwapForwardBasisSystem::isExerciseTime() const
77 {
78 return std::valarray<bool>(true, exerciseTimes_.size());
79 }
80
82 std::vector<Real>& results) const
83 {
84 Size rateIndex = rateIndex_[currentIndex_-1];
85
86 if (rateIndex < rateTimes_.size() -3)
87 {
88 results.resize(10);
89
90 Real x= currentState.forwardRate(rateIndex);
91 Real y = currentState.coterminalSwapRate(rateIndex+1);
92 Real z = currentState.discountRatio(rateIndex,rateTimes_.size()-1);
93
94 results[0] = 1.0;
95 results[1] = x;
96 results[2] = y;
97 results[3] = z;
98 results[4] = x*y;
99 results[5] = y*z;
100 results[6] = z*x;
101 results[7] = x*x;
102 results[8] = y*y;
103 results[9] = z*z;
104 }
105 else
106 if ( rateIndex == rateTimes_.size() -3)
107 {
108 Real x= currentState.forwardRate(rateIndex);
109 Real y = currentState.forwardRate(rateIndex+1);
110 results.resize(6);
111 results[0] = 1.0;
112 results[1] = x;
113 results[2] = y;
114 results[3] = x*x;
115 results[4] = x*y;
116 results[5] = y*y;
117
118 }
119 else
120 {
121 Real x= currentState.forwardRate(rateIndex);
122 results.resize(3);
123 results[0] =1.0;
124 results[1] = x;
125 results[2] = x*x;
126
127 }
128 }
129
130 std::unique_ptr<MarketModelBasisSystem>
132 return std::unique_ptr<MarketModelBasisSystem>(new SwapForwardBasisSystem(*this));
133 }
134
135}
136
Curve state for market-model simulations
Definition: curvestate.hpp:41
virtual Rate forwardRate(Size i) const =0
virtual Rate coterminalSwapRate(Size i) const =0
virtual Real discountRatio(Size i, Size j) const =0
Market-model evolution description.
void values(const CurveState &, std::vector< Real > &results) const override
void nextStep(const CurveState &) override
std::vector< Size > numberOfFunctions() const override
std::valarray< bool > isExerciseTime() const override
const EvolutionDescription & evolution() const override
SwapForwardBasisSystem(const std::vector< Time > &rateTimes, const std::vector< Time > &exerciseTimes)
std::unique_ptr< MarketModelBasisSystem > clone() const override
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