Update of /cvsroot/quantlibaddin/QuantLibAddin/qlo
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv25928/qlo
Modified Files:
interpolation.cpp interpolation.hpp
Log Message:
Index: interpolation.hpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/interpolation.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** interpolation.hpp 19 May 2006 16:56:16 -0000 1.1
--- interpolation.hpp 8 Jun 2006 10:48:49 -0000 1.2
***************
*** 1,5 ****
/*
! Copyright (C) 2005 Aurelien Chanudet
This file is part of QuantLib, a free-software/open-source library
--- 1,5 ----
/*
! Copyright (C) 2006 Ferdinando Ametrano
This file is part of QuantLib, a free-software/open-source library
***************
*** 24,101 ****
namespace QuantLibAddin {
- typedef std::vector<std::vector<double> > double_matrix;
-
class Interpolation : public ObjHandler::Object {
public:
- Interpolation(const bool& allowExtrapolation) : allowExtrapolation_(allowExtrapolation) { }
-
- virtual boost::shared_ptr<QuantLib::Interpolation>
- interpolationFactory(std::vector<double>::const_iterator xBegin,
- std::vector<double>::const_iterator xEnd,
- std::vector<double>::const_iterator yBegin) const = 0;
-
- double_matrix interpolate(const double_matrix& xArray,
- const double_matrix& yArray,
- const double_matrix& xValues) const;
-
virtual boost::shared_ptr<void> getReference() const {
! return boost::shared_ptr<void>();
}
-
protected:
! bool allowExtrapolation_;
};
class BackwardFlatInterpolation : public Interpolation {
public:
! BackwardFlatInterpolation(const bool& allowExtrapolation) : Interpolation(allowExtrapolation) { }
!
! virtual boost::shared_ptr<QuantLib::Interpolation>
! interpolationFactory(std::vector<double>::const_iterator xBegin,
! std::vector<double>::const_iterator xEnd,
! std::vector<double>::const_iterator yBegin) const;
};
class ForwardFlatInterpolation : public Interpolation {
public:
! ForwardFlatInterpolation(const bool& allowExtrapolation) : Interpolation(allowExtrapolation) { }
!
! virtual boost::shared_ptr<QuantLib::Interpolation>
! interpolationFactory(std::vector<double>::const_iterator xBegin,
! std::vector<double>::const_iterator xEnd,
! std::vector<double>::const_iterator yBegin) const;
};
class LinearInterpolation : public Interpolation {
public:
! LinearInterpolation(const bool& allowExtrapolation) : Interpolation(allowExtrapolation) { }
!
! virtual boost::shared_ptr<QuantLib::Interpolation>
! interpolationFactory(std::vector<double>::const_iterator xBegin,
! std::vector<double>::const_iterator xEnd,
! std::vector<double>::const_iterator yBegin) const;
};
class CubicSplineInterpolation : public Interpolation {
public:
! CubicSplineInterpolation(
! const bool& allowExtrapolation,
! const std::string& leftConditionType,
! const double& leftConditionValue,
! const std::string& rightConditionType,
! const double& rightConditionValue,
! const bool& monotonicityConstraint);
!
! virtual boost::shared_ptr<QuantLib::Interpolation>
! interpolationFactory(std::vector<double>::const_iterator xBegin,
! std::vector<double>::const_iterator xEnd,
! std::vector<double>::const_iterator yBegin) const;
!
private:
! QuantLib::CubicSpline::BoundaryCondition leftConditionType_;
! QuantLib::Real leftConditionValue_;
! QuantLib::CubicSpline::BoundaryCondition rightConditionType_;
! QuantLib::Real rightConditionValue_;
! bool monotonicityConstraint_;
};
--- 24,78 ----
namespace QuantLibAddin {
class Interpolation : public ObjHandler::Object {
public:
virtual boost::shared_ptr<void> getReference() const {
! return boost::shared_ptr<void>(interp_);
! }
! const QuantLib::Interpolation& getObject() const {
! return *interp_;
}
protected:
! boost::shared_ptr<QuantLib::Interpolation> interp_;
};
class BackwardFlatInterpolation : public Interpolation {
public:
! BackwardFlatInterpolation(const std::vector<double>& x,
! const std::vector<double>& y,
! bool allowExtrapolation);
! private:
! std::vector<double> x_, y_;
};
class ForwardFlatInterpolation : public Interpolation {
public:
! ForwardFlatInterpolation(const std::vector<double>& x,
! const std::vector<double>& y,
! bool allowExtrapolation);
! private:
! std::vector<double> x_, y_;
};
class LinearInterpolation : public Interpolation {
public:
! LinearInterpolation(const std::vector<double>& x,
! const std::vector<double>& y,
! bool allowExtrapolation);
! private:
! std::vector<double> x_, y_;
};
class CubicSplineInterpolation : public Interpolation {
public:
! CubicSplineInterpolation(const std::vector<double>& x,
! const std::vector<double>& y,
! bool allowExtrapolation,
! QuantLib::CubicSpline::BoundaryCondition leftCondition,
! double leftConditionValue,
! QuantLib::CubicSpline::BoundaryCondition rightCondition,
! double rightConditionValue,
! bool monotonicityConstraint);
private:
! std::vector<double> x_, y_;
};
***************
*** 103,105 ****
#endif
-
--- 80,81 ----
Index: interpolation.cpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/interpolation.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** interpolation.cpp 19 May 2006 16:56:16 -0000 1.1
--- interpolation.cpp 8 Jun 2006 10:48:49 -0000 1.2
***************
*** 1,5 ****
/*
! Copyright (C) 2005 Aurelien Chanudet
This file is part of QuantLib, a free-software/open-source library
--- 1,5 ----
/*
! Copyright (C) 2006 Ferdinando Ametrano
This file is part of QuantLib, a free-software/open-source library
***************
*** 27,128 ****
namespace QuantLibAddin {
-
- double_matrix
- Interpolation::interpolate(const double_matrix& xArray,
- const double_matrix& yArray,
- const double_matrix& xValues) const {
-
- std::vector<QuantLib::Real> x;
- std::vector<QuantLib::Real> y;
-
- for (std::size_t ix=0 ; ix < xArray.size() ; ix++) {
- for (std::size_t jx=0 ; jx < xArray[ix].size() ; jx++) {
- x.push_back(xArray[ix][jx]);
- }
- }
! for (std::size_t iy=0 ; iy < yArray.size() ; iy++) {
! for (std::size_t jy=0 ; jy < yArray[iy].size() ; jy++) {
! y.push_back(yArray[iy][jy]);
! }
! }
!
! boost::shared_ptr<QuantLib::Interpolation> f =
! interpolationFactory(x.begin(), x.end(), y.begin());
!
! double_matrix result;
!
! for (std::size_t p=0 ; p < xValues.size() ; p++) {
! std::vector<QuantLib::Real> v;
! for (std::size_t q=0 ; q < xValues[p].size() ; q++) {
! v.push_back((*f)(xValues[p][q], allowExtrapolation_));
! }
! result.push_back(v);
! }
!
! return result;
}
! boost::shared_ptr<QuantLib::Interpolation>
! LinearInterpolation::interpolationFactory(
! std::vector<double>::const_iterator xBegin,
! std::vector<double>::const_iterator xEnd,
! std::vector<double>::const_iterator yBegin) const {
!
! return boost::shared_ptr<QuantLib::Interpolation>(
! new QuantLib::LinearInterpolation(xBegin, xEnd, yBegin));
}
! boost::shared_ptr<QuantLib::Interpolation>
! BackwardFlatInterpolation::interpolationFactory(
! std::vector<double>::const_iterator xBegin,
! std::vector<double>::const_iterator xEnd,
! std::vector<double>::const_iterator yBegin) const {
!
! return boost::shared_ptr<QuantLib::Interpolation>(
! new QuantLib::BackwardFlatInterpolation(xBegin, xEnd, yBegin));
! };
!
! boost::shared_ptr<QuantLib::Interpolation>
! ForwardFlatInterpolation::interpolationFactory(
! std::vector<double>::const_iterator xBegin,
! std::vector<double>::const_iterator xEnd,
! std::vector<double>::const_iterator yBegin) const {
!
! return boost::shared_ptr<QuantLib::Interpolation>(
! new QuantLib::ForwardFlatInterpolation(xBegin, xEnd, yBegin));
! };
!
! CubicSplineInterpolation::CubicSplineInterpolation(
! const bool& allowExtrapolation,
! const std::string& leftConditionTypeID,
! const double& leftConditionValue,
! const std::string& rightConditionTypeID,
! const double& rightConditionValue,
! const bool& monotonicityConstraint)
! : Interpolation(allowExtrapolation),
! leftConditionValue_(leftConditionValue), rightConditionValue_(rightConditionValue),
! monotonicityConstraint_(monotonicityConstraint) {
!
! leftConditionType_ =
! Create<QuantLib::CubicSpline::BoundaryCondition>()(leftConditionTypeID);
!
! rightConditionType_ =
! Create<QuantLib::CubicSpline::BoundaryCondition>()(rightConditionTypeID);
}
-
- boost::shared_ptr<QuantLib::Interpolation>
- CubicSplineInterpolation::interpolationFactory(
- std::vector<double>::const_iterator xBegin,
- std::vector<double>::const_iterator xEnd,
- std::vector<double>::const_iterator yBegin) const {
! return boost::shared_ptr<QuantLib::Interpolation>(
! new QuantLib::CubicSpline(xBegin, xEnd, yBegin,
! leftConditionType_, leftConditionValue_,
! rightConditionType_, rightConditionValue_,
! monotonicityConstraint_));
}
!
}
--- 27,89 ----
namespace QuantLibAddin {
! BackwardFlatInterpolation::BackwardFlatInterpolation(
! const std::vector<double>& x,
! const std::vector<double>& y,
! bool allowExtrapolation) : x_(x), y_(y) {
!
! QL_REQUIRE(x.size()==y.size(), "unmatched x/y");
! interp_ = boost::shared_ptr<QuantLib::Interpolation>(
! new QuantLib::BackwardFlatInterpolation(x_.begin(),
! x_.end(),
! y_.begin()));
}
! ForwardFlatInterpolation::ForwardFlatInterpolation(
! const std::vector<double>& x,
! const std::vector<double>& y,
! bool allowExtrapolation) : x_(x), y_(y) {
!
! QL_REQUIRE(x.size()==y.size(), "unmatched x/y");
! interp_ = boost::shared_ptr<QuantLib::Interpolation>(
! new QuantLib::ForwardFlatInterpolation(x_.begin(),
! x_.end(),
! y_.begin()));
}
! LinearInterpolation::LinearInterpolation(
! const std::vector<double>& x,
! const std::vector<double>& y,
! bool allowExtrapolation) : x_(x), y_(y) {
!
! QL_REQUIRE(x.size()==y.size(), "unmatched x/y");
!
! interp_ = boost::shared_ptr<QuantLib::Interpolation>(
! new QuantLib::LinearInterpolation(x_.begin(),
! x_.end(),
! y_.begin()));
}
! CubicSplineInterpolation::CubicSplineInterpolation(
! const std::vector<double>& x,
! const std::vector<double>& y,
! bool allowExtrapolation,
! QuantLib::CubicSpline::BoundaryCondition leftCondition,
! double leftConditionValue,
! QuantLib::CubicSpline::BoundaryCondition rightCondition,
! double rightConditionValue,
! bool monotonicityConstraint) : x_(x), y_(y) {
!
! QL_REQUIRE(x.size()==y.size(), "unmatched x/y");
!
! interp_ = boost::shared_ptr<QuantLib::Interpolation>(
! new QuantLib::CubicSpline(
! x_.begin(), x_.end(), y_.begin(),
! leftCondition, leftConditionValue,
! rightCondition, rightConditionValue,
! monotonicityConstraint));
!
}
!
}
|