QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
piecewiseconstantabcdvariance.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4Copyright (C) 2007 Ferdinando Ametrano
5Copyright (C) 2007 Mark Joshi
6
7This file is part of QuantLib, a free-software/open-source library
8for financial quantitative analysts and developers - http://quantlib.org/
9
10QuantLib is free software: you can redistribute it and/or modify it
11under the terms of the QuantLib license. You should have received a
12copy of the license along with this program; if not, please email
13<quantlib-dev@lists.sf.net>. The license is also available online at
14<http://quantlib.org/license.shtml>.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
24
25namespace QuantLib {
26
28 Real a, Real b, Real c, Real d,
29 Size resetIndex,
30 const std::vector<Time>& rateTimes)
31 : variances_(rateTimes.size()-1, 0.0),
32 volatilities_(rateTimes.size()-1, 0.0),
33 rateTimes_(rateTimes) ,
34 a_(a),
35 b_(b),
36 c_(c),
37 d_(d)
38 {
39
41 QL_REQUIRE(rateTimes.size()>1,
42 "Rate times must contain at least two values");
43 QL_REQUIRE(resetIndex<rateTimes_.size()-1,
44 "resetIndex (" << resetIndex <<
45 ") must be less than rateTimes.size()-1 (" <<
46 rateTimes_.size()-1 << ")");
47 AbcdFunction abcd(a,b,c,d);
48 for (Size i=0; i<=resetIndex; ++i) {
49 Time startTime = (i==0 ? 0.0 : rateTimes_[i-1]);
50 variances_[i] = abcd.variance(startTime,
51 rateTimes_[i],
52 rateTimes_[resetIndex]);
53 Time totTime = rateTimes_[i]-startTime;
54 volatilities_[i] = std::sqrt(variances_[i]/totTime);
55 }
56 }
57
58
60 {
61 a=a_;
62 b=b_;
63 c=c_;
64 d=d_;
65 }
66
67 const std::vector<Real>& PiecewiseConstantAbcdVariance::rateTimes() const {
68 return rateTimes_;
69 }
70
71 const std::vector<Real>& PiecewiseConstantAbcdVariance::variances() const {
72 return variances_;
73 }
74
75 const std::vector<Real>&
77 return volatilities_;
78 }
79
80}
Abcd functional form for instantaneous volatility
Definition: abcd.hpp:34
Real variance(Time tMin, Time tMax, Time T) const
Definition: abcd.cpp:39
const std::vector< Real > & variances() const override
const std::vector< Time > & rateTimes() const override
PiecewiseConstantAbcdVariance(Real a, Real b, Real c, Real d, Size resetIndex, const std::vector< Time > &rateTimes)
const std::vector< Real > & volatilities() const override
void getABCD(Real &a, Real &b, Real &c, Real &d) const
Real a_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
ext::function< Real(Real)> b
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
const VF_R b_
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