Update of /cvsroot/quantlibaddin/QuantLibAddin/qlo
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv31901/qlo
Added Files:
interpolation2D.cpp interpolation2D.hpp
Log Message:
exported Interpolation2D
--- NEW FILE: interpolation2D.hpp ---
/*
Copyright (C) 2006 Ferdinando Ametrano
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 qua...@li...
The license is also available online at http://quantlib.org/html/license.html
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.
*/
#ifndef qla_interpolation2D_hpp
#define qla_interpolation2D_hpp
#include <oh/objhandler.hpp>
#include <qlo/interpolation.hpp>
#include <ql/Math/matrix.hpp>
namespace QuantLibAddin {
enum Interpolation2DType {
BiLinear,
BiCubic
};
class Interpolation2D : public Extrapolator
{
public:
Interpolation2D(const Interpolation2DType t,
const std::vector<double>& x,
const std::vector<double>& y,
const QuantLib::Matrix& dataMatrix);
private:
std::vector<double> x_, y_;
QuantLib::Matrix dataMatrix_;
};
}
#endif
--- NEW FILE: interpolation2D.cpp ---
/*
Copyright (C) 2006 Ferdinando Ametrano
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 qua...@li...
The license is also available online at http://quantlib.org/html/license.html
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.
*/
#if defined(HAVE_CONFIG_H)
#include <qlo/config.hpp>
#endif
#include <qlo/interpolation2D.hpp>
#include <ql/Math/bilinearinterpolation.hpp>
#include <ql/Math/bicubicsplineinterpolation.hpp>
namespace QuantLibAddin {
Interpolation2D::Interpolation2D(
const Interpolation2DType t,
const std::vector<double>& x,
const std::vector<double>& y,
const QuantLib::Matrix& dataMatrix)
: x_(x), y_(y), dataMatrix_(dataMatrix)
{
QL_REQUIRE(y.size()==dataMatrix_.rows(),
"y size (" << y.size() <<
") does not match number of rows in the data matrix ("
<< dataMatrix_.rows() << ")");
QL_REQUIRE(x.size()==dataMatrix_.columns(),
"x size (" << x.size() <<
") does not match number of columns in the data matrix ("
<< dataMatrix_.columns() << ")");
switch (t) {
case BiLinear:
libraryObject_ = boost::shared_ptr<QuantLib::Extrapolator>(
new QuantLib::BilinearInterpolation(x_.begin(), x_.end(),
y_.begin(), y_.end(),
dataMatrix_));
break;
case BiCubic:
libraryObject_ = boost::shared_ptr<QuantLib::Extrapolator>(
new QuantLib::BicubicSpline(x_.begin(), x_.end(),
y_.begin(), y_.end(),
dataMatrix_));
break;
default:
QL_FAIL("Unknown Interpolation2DType");
}
}
}
|