QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
lmfixedvolmodel.cpp
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
20#include <ql/legacy/libormarketmodels/lmfixedvolmodel.hpp>
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");
30 QL_REQUIRE(volatilities_.size() == startTimes_.size(),
31 "volatility array and fixing time array have to have "
32 "the same size");
33 for (Size i = 1; i < startTimes_.size(); i++) {
34 QL_REQUIRE(startTimes_[i] > startTimes_[i-1],
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
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
Definition: any.hpp:35
STL namespace.