/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2005, 2006 Klaus Spanderen This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email . The license is also available online at . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ #include #include namespace QuantLib { LfmHullWhiteParameterization::LfmHullWhiteParameterization( const boost::shared_ptr & process, const boost::shared_ptr & capletVol, const Matrix& correlation, Size factors) : LfmCovarianceParameterization(process->size(), factors), diffusion_ (size_-1, factors_), fixingTimes_(process->fixingTimes()) { Matrix sqrtCorr(size_-1, factors_, 1.0); if (correlation.empty()) { QL_REQUIRE(factors_ == 1, "correlation matrix must be given for " "multi factor models"); } else { QL_REQUIRE( correlation.rows() == size_-1 && correlation.rows() == correlation.columns(), "wrong dimesion of the correlation matrix"); QL_REQUIRE(factors_ <= size_-1, "too many factors for given LFM process"); Matrix tmpSqrtCorr = pseudoSqrt(correlation, SalvagingAlgorithm::Spectral); // reduce to n factor model // "Reconstructing a valid correlation matrix from invalid data" // () for (Size i=0; i < size_-1; ++i) { std::transform( tmpSqrtCorr[i], tmpSqrtCorr[i]+factors_, sqrtCorr[i], std::bind2nd(std::divides(), std::sqrt(std::inner_product( tmpSqrtCorr[i],tmpSqrtCorr[i]+factors_, tmpSqrtCorr[i], 0.0)))); } } std::vector lambda; const DayCounter dayCounter = process->index()->dayCounter(); const std::vector