QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
lfmcovarparam.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
22
23namespace QuantLib {
24
25 class LfmCovarianceParameterization::Var_Helper {
26 public:
27 Var_Helper(const LfmCovarianceParameterization* param, Size i, Size j);
28
29 Real operator()(Real t) const;
30 private:
31 const Size i_, j_;
32 const LfmCovarianceParameterization* param_;
33 };
34
35 LfmCovarianceParameterization::Var_Helper::Var_Helper(
36 const LfmCovarianceParameterization* param,
37 Size i, Size j)
38 : i_(i), j_(j), param_(param) {}
39
40 Real LfmCovarianceParameterization::Var_Helper::operator()(Real t) const {
41 const Matrix m = param_->diffusion(t);
42
43 return std::inner_product(m.row_begin(i_), m.row_end(i_),
44 m.row_begin(j_), Real(0.0));
45 }
46
47 Matrix LfmCovarianceParameterization::covariance(Time t, const Array& x) const {
48 Matrix sigma = this->diffusion(t, x);
49 Matrix result = sigma*transpose(sigma);
50 return result;
51 }
52
53 Matrix LfmCovarianceParameterization::integratedCovariance(Time t, const Array& x) const {
54 // this implementation is not intended for production.
55 // because it is too slow and too inefficient.
56 // This method is useful for testing and R&D.
57 // Please overload the method within derived classes.
58 QL_REQUIRE(x.empty(), "can not handle given x here");
59
60 Matrix tmp(size_, size_,0.0);
61
62 for (Size i=0; i<size_; ++i) {
63 for (Size j=0; j<=i;++j) {
64 Var_Helper helper(this, i, j);
65 GaussKronrodAdaptive integrator(1e-10, 10000);
66 for (Size k=0; k < 64; ++k) {
67 tmp[i][j]+=integrator(helper, k*t/64.,(k+1)*t/64.);
68 }
69 tmp[j][i]=tmp[i][j];
70 }
71 }
72
73 return tmp;
74 }
75
76}
77
1-D array used in linear algebra.
Definition: array.hpp:52
bool empty() const
whether the array is empty
Definition: array.hpp:499
Integral of a 1-dimensional function using the Gauss-Kronrod methods.
Matrix used in linear algebra.
Definition: matrix.hpp:41
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
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Real sigma
Integral of a 1-dimensional function using the Gauss-Kronrod method.
volatility & correlation function for libor forward model process
Definition: any.hpp:35
Matrix transpose(const Matrix &m)
Definition: matrix.hpp:700
Size size_
Definition: pseudosqrt.cpp:76