QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
lmfixedvolmodel.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) 2005, 2006 Klaus Spanderen
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
21#include <utility>
22
23namespace QuantLib {
24
26 const std::vector<Time>& startTimes)
27 : LmVolatilityModel(startTimes.size(), 0), volatilities_(std::move(volatilities)),
28 startTimes_(startTimes) {
29 QL_REQUIRE(startTimes_.size()>1, "too few dates");
31 "volatility array and fixing time array have to have "
32 "the same size");
33 for (Size i = 1; i < startTimes_.size(); i++) {
35 "invalid time (" << startTimes_[i] << ", vs "
36 << startTimes_[i-1] << ")");
37 }
38 }
39
41 QL_REQUIRE(t >= startTimes_.front() && t <= startTimes_.back(),
42 "invalid time given for volatility model");
43
44 const Size ti = std::upper_bound(startTimes_.begin(),
45 startTimes_.end()-1, t)
46 - startTimes_.begin()-1;
47
48 Array tmp(size_, 0.0);
49
50 for (Size i=ti; i<size_; ++i) {
51 tmp[i] = volatilities_[i-ti];
52 }
53
54 return tmp;
55 }
56
58 Size i, Time t, const Array&) const {
59 QL_REQUIRE(t >= startTimes_.front() && t <= startTimes_.back(),
60 "invalid time given for volatility model");
61
62 const Size ti = std::upper_bound(startTimes_.begin(),
63 startTimes_.end()-1, t)
64 - startTimes_.begin()-1;
65
66 return volatilities_[i-ti];
67 }
68
70}
71
1-D array used in linear algebra.
Definition: array.hpp:52
Size size() const
dimension of the array
Definition: array.hpp:495
Array volatility(Time t, const Array &x=Null< Array >()) const override
LmFixedVolatilityModel(Array volatilities, const std::vector< Time > &startTimes)
const std::vector< Time > startTimes_
caplet volatility model
Definition: lmvolmodel.hpp:33
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
Real Volatility
volatility
Definition: types.hpp:78
std::size_t Size
size of a container
Definition: types.hpp:58
model of constant volatilities for libor market models
Definition: any.hpp:35
STL namespace.