1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2015 Johannes Göttker-Schnetmann
Copyright (C) 2015 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
<quantlib-dev@lists.sf.net>. The license is also available online at
<https://www.quantlib.org/license.shtml>.
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.
*/
/*! \file fixedlocalvolsurface.hpp
\brief Local volatility surface based on fixed values plus interpolation
*/
#ifndef quantlib_fixed_local_vol_surface_hpp
#define quantlib_fixed_local_vol_surface_hpp
#include <ql/math/matrix.hpp>
#include <ql/math/interpolation.hpp>
#include <ql/math/interpolations/linearinterpolation.hpp>
#include <ql/termstructures/volatility/equityfx/localvoltermstructure.hpp>
namespace QuantLib {
class FixedLocalVolSurface : public LocalVolTermStructure {
public:
enum Extrapolation { ConstantExtrapolation,
InterpolatorDefaultExtrapolation };
FixedLocalVolSurface(const Date& referenceDate,
const std::vector<Date>& dates,
const std::vector<Real>& strikes,
ext::shared_ptr<Matrix> localVolMatrix,
const DayCounter& dayCounter,
Extrapolation lowerExtrapolation = ConstantExtrapolation,
Extrapolation upperExtrapolation = ConstantExtrapolation);
FixedLocalVolSurface(const Date& referenceDate,
const std::vector<Time>& times,
const std::vector<Real>& strikes,
ext::shared_ptr<Matrix> localVolMatrix,
const DayCounter& dayCounter,
Extrapolation lowerExtrapolation = ConstantExtrapolation,
Extrapolation upperExtrapolation = ConstantExtrapolation);
FixedLocalVolSurface(const Date& referenceDate,
const std::vector<Time>& times,
const std::vector<ext::shared_ptr<std::vector<Real> > >& strikes,
ext::shared_ptr<Matrix> localVolMatrix,
const DayCounter& dayCounter,
Extrapolation lowerExtrapolation = ConstantExtrapolation,
Extrapolation upperExtrapolation = ConstantExtrapolation);
Date maxDate() const override;
Time maxTime() const override;
Real minStrike() const override;
Real maxStrike() const override;
template <class Interpolator>
void setInterpolation(const Interpolator& i = Interpolator()) {
for (Size j=0; j < times_.size(); ++j) {
localVolInterpol_[j] = i.interpolate(
strikes_[j]->begin(), strikes_[j]->end(),
localVolMatrix_->column_begin(j));
}
notifyObservers();
}
protected:
Volatility localVolImpl(Time t, Real strike) const override;
const Date maxDate_;
std::vector<Time> times_;
const ext::shared_ptr<Matrix> localVolMatrix_;
const std::vector<ext::shared_ptr<std::vector<Real> > > strikes_;
std::vector<Interpolation> localVolInterpol_;
Extrapolation lowerExtrapolation_, upperExtrapolation_;
private:
void checkSurface();
};
}
#endif
|