QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swapratetrigger.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
22#include <utility>
23
24namespace QuantLib {
25
26 SwapRateTrigger::SwapRateTrigger(const std::vector<Time>& rateTimes,
27 std::vector<Rate> swapTriggers,
28 const std::vector<Time>& exerciseTimes)
29 : rateTimes_(rateTimes), swapTriggers_(std::move(swapTriggers)), exerciseTimes_(exerciseTimes),
30 rateIndex_(exerciseTimes.size()) {
31
32 checkIncreasingTimes(rateTimes);
33 QL_REQUIRE(rateTimes.size()>1,
34 "Rate times must contain at least two values");
35
37
39 "swapTriggers/exerciseTimes mismatch");
40 Size j = 0;
41 for (Size i=0; i<exerciseTimes.size(); ++i) {
42 while (j < rateTimes.size() && rateTimes[j] < exerciseTimes[i])
43 ++j;
44 rateIndex_[i] = j;
45 }
46 }
47
48 std::vector<Time> SwapRateTrigger::exerciseTimes() const {
49 return exerciseTimes_;
50 }
51
52 std::vector<Time> SwapRateTrigger::relevantTimes() const {
53 return exerciseTimes_;
54 }
55
58 }
59
60 bool SwapRateTrigger::exercise(const CurveState& currentState) const {
61 Size rateIndex = rateIndex_[currentIndex_-1];
62 Rate currentSwapRate =
63 currentState.coterminalSwapRate(rateIndex);
64 return swapTriggers_[currentIndex_-1]<currentSwapRate;
65 }
66
69 }
70
71 std::unique_ptr<ExerciseStrategy<CurveState>>
73 return std::unique_ptr<ExerciseStrategy<CurveState>>(new SwapRateTrigger(*this));
74 }
75
76}
Curve state for market-model simulations
Definition: curvestate.hpp:41
virtual Rate coterminalSwapRate(Size i) const =0
std::vector< Size > rateIndex_
std::vector< Rate > swapTriggers_
std::vector< Time > relevantTimes() const override
bool exercise(const CurveState &currentState) const override
std::vector< Time > exerciseTimes_
std::unique_ptr< ExerciseStrategy< CurveState > > clone() const override
SwapRateTrigger(const std::vector< Time > &rateTimes, std::vector< Rate > swapTriggers, const std::vector< Time > &exerciseTimes)
void nextStep(const CurveState &currentState) override
std::vector< Time > exerciseTimes() const override
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
void checkIncreasingTimes(const std::vector< Time > &times)
check for strictly increasing times, first time greater than zero
Definition: utilities.cpp:92
STL namespace.