QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
triggeredswapexercise.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 StatPro Italia srl
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
27 TriggeredSwapExercise::TriggeredSwapExercise(const std::vector<Time>& rateTimes,
28 const std::vector<Time>& exerciseTimes,
29 std::vector<Rate> strikes)
30 : rateTimes_(rateTimes), exerciseTimes_(exerciseTimes), strikes_(std::move(strikes)),
31 rateIndex_(exerciseTimes.size()), evolution_(rateTimes, exerciseTimes) {
32 Size j = 0;
33 for (Size i=0; i<exerciseTimes.size(); ++i) {
34 while (j < rateTimes.size() && rateTimes[j] < exerciseTimes[i])
35 ++j;
36 rateIndex_[i] = j;
37 }
38 }
39
41 return exerciseTimes_.size();
42 }
43
45 return evolution_;
46 }
47
50 }
51
53 currentStep_ = 0;
54 }
55
56 std::valarray<bool> TriggeredSwapExercise::isExerciseTime() const {
57 return std::valarray<bool>(true,numberOfExercises());
58 }
59
61 std::vector<Real>& results) const {
62 Size swapIndex = rateIndex_[currentStep_-1];
63 results.resize(1);
64 results[0] = state.coterminalSwapRate(swapIndex);
65 }
66
67 std::vector<Size> TriggeredSwapExercise::numberOfVariables() const {
68 return std::vector<Size>(numberOfExercises(), 1);
69 }
70
72 return std::vector<Size>(numberOfExercises(), 1);
73 }
74
76 Size,
77 const std::vector<Real>& parameters,
78 const std::vector<Real>& variables) const {
79 return variables[0] >= parameters[0];
80 }
81
83 std::vector<Real>& parameters) const {
84 parameters.resize(1);
85 parameters[0] = strikes_.at(exerciseIndex);
86 }
87
88 std::unique_ptr<MarketModelParametricExercise>
90 return std::unique_ptr<MarketModelParametricExercise>(new TriggeredSwapExercise(*this));
91 }
92
93}
94
Curve state for market-model simulations
Definition: curvestate.hpp:41
virtual Rate coterminalSwapRate(Size i) const =0
Market-model evolution description.
void values(const CurveState &, std::vector< Real > &results) const override
std::vector< Size > numberOfVariables() const override
TriggeredSwapExercise(const std::vector< Time > &rateTimes, const std::vector< Time > &exerciseTimes, std::vector< Rate > strikes)
std::vector< Size > numberOfParameters() const override
void nextStep(const CurveState &) override
std::unique_ptr< MarketModelParametricExercise > clone() const override
void guess(Size exerciseNumber, std::vector< Real > &parameters) const override
std::valarray< bool > isExerciseTime() const override
const EvolutionDescription & evolution() const override
bool exercise(Size exerciseNumber, const std::vector< Real > &parameters, const std::vector< Real > &variables) const override
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.