QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
nothingexercisevalue.cpp
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
20#include <ql/errors.hpp>
21#include <ql/models/marketmodels/callability/nothingexercisevalue.hpp>
22#include <ql/models/marketmodels/utilities.hpp>
23#include <utility>
24
25namespace QuantLib {
26
27 NothingExerciseValue::NothingExerciseValue(const std::vector<Time>& rateTimes,
28 std::valarray<bool> isExerciseTime)
29 : rateTimes_(rateTimes), isExerciseTime_(std::move(isExerciseTime)) {
30
31 checkIncreasingTimes(rateTimes);
32 QL_REQUIRE(rateTimes.size() >= 2,
33 "Rate times must contain at least two values");
34 cf_.amount = 0.0;
35 std::vector<Time> evolutionTimes(rateTimes_);
36 evolutionTimes.pop_back();
38 if(isExerciseTime_.size()==0) {
39 isExerciseTime_ = std::valarray<bool>(true,rateTimes.empty() ? 0 : rateTimes.size()-1);
40 }
41 else {
42 QL_REQUIRE(isExerciseTime_.size() ==
43 (rateTimes.empty() ? 0 : rateTimes.size() - 1),
44 "isExerciseTime ("
45 << isExerciseTime_.size() << ") must "
46 << "have same size as rateTimes minus 1 ("
47 << (rateTimes.empty() ? 0 : rateTimes.size() - 1)
48 << ")");
49 }
51 for(Size i=0;i<isExerciseTime_.size();i++)
52 if(isExerciseTime_[i])
54 }
55
57 return numberOfExercises_;
58 }
59
61 return evolution_;
62 }
63
65 return rateTimes_;
66 }
67
70 }
71
75 }
76
77
78 std::valarray<bool> NothingExerciseValue::isExerciseTime() const {
79 return isExerciseTime_;
80 }
81
84 return cf_;
85 }
86
87 std::unique_ptr<MarketModelExerciseValue>
89 return std::unique_ptr<MarketModelExerciseValue>(new NothingExerciseValue(*this));
90 }
91
92}
Curve state for market-model simulations
Definition: curvestate.hpp:41
Market-model evolution description.
MarketModelMultiProduct::CashFlow value(const CurveState &) const override
MarketModelMultiProduct::CashFlow cf_
Size numberOfExercises() const override
void nextStep(const CurveState &) override
std::valarray< bool > isExerciseTime() const override
std::unique_ptr< MarketModelExerciseValue > clone() const override
std::vector< Time > possibleCashFlowTimes() const override
const EvolutionDescription & evolution() const override
NothingExerciseValue(const std::vector< Time > &rateTimes, std::valarray< bool > isExerciseTime=std::valarray< bool >())
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.