QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swapbasissystem.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) 2006 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 SwapBasisSystem::SwapBasisSystem(const std::vector<Time>& rateTimes,
27 const std::vector<Time>& exerciseTimes)
28 : rateTimes_(rateTimes), exerciseTimes_(exerciseTimes),
29 rateIndex_(exerciseTimes.size()),
30 evolution_(rateTimes, exerciseTimes) {
31 Size j = 0;
32 for (Size i=0; i<exerciseTimes.size(); ++i) {
33 while (j < rateTimes.size() && rateTimes[j] < exerciseTimes[i])
34 ++j;
35 rateIndex_[i] = j;
36 }
37 }
38
40 return exerciseTimes_.size();
41 }
42
43 std::vector<Size> SwapBasisSystem::numberOfFunctions() const {
44 std::vector<Size> sizes(exerciseTimes_.size(), 3);
45 if (rateIndex_[exerciseTimes_.size()-1] == rateTimes_.size()-2)
46 sizes.back() = 2;
47 return sizes;
48 }
49
51 return evolution_;
52 }
53
56 }
57
59 currentIndex_ = 0;
60 }
61
62 std::valarray<bool> SwapBasisSystem::isExerciseTime() const {
63 return std::valarray<bool>(true, exerciseTimes_.size());
64 }
65
66 void SwapBasisSystem::values(const CurveState& currentState,
67 std::vector<Real>& results) const {
68 Size rateIndex = rateIndex_[currentIndex_-1];
69
70 results.reserve(3);
71 results.resize(2);
72 results[0] = 1.0;
73 results[1] = currentState.forwardRate(rateIndex);
74 if (rateIndex < rateTimes_.size()-2)
75 results.push_back(currentState.coterminalSwapRate(rateIndex+1));
76 }
77
78 std::unique_ptr<MarketModelBasisSystem>
80 return std::unique_ptr<MarketModelBasisSystem>(new SwapBasisSystem(*this));
81 }
82
83}
84
Curve state for market-model simulations
Definition: curvestate.hpp:41
virtual Rate forwardRate(Size i) const =0
virtual Rate coterminalSwapRate(Size i) const =0
Market-model evolution description.
void values(const CurveState &, std::vector< Real > &results) const override
std::vector< Size > rateIndex_
Size numberOfExercises() const override
void nextStep(const CurveState &) override
std::vector< Size > numberOfFunctions() const override
std::valarray< bool > isExerciseTime() const override
std::vector< Time > rateTimes_
const EvolutionDescription & evolution() const override
std::vector< Time > exerciseTimes_
EvolutionDescription evolution_
std::unique_ptr< MarketModelBasisSystem > clone() const override
SwapBasisSystem(const std::vector< Time > &rateTimes, const std::vector< Time > &exerciseTimes)
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35