QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
gaussian1dswaptionvolatility.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2015 Peter Caspers
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
24#ifndef quantlib_swaption_gaussian1d_swaption_volatility_hpp
25#define quantlib_swaption_gaussian1d_swaption_volatility_hpp
26
27#include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp>
28#include <ql/time/period.hpp>
29#include <ql/indexes/swapindex.hpp>
30#include <ql/models/shortrate/onefactormodels/gaussian1dmodel.hpp>
31#include <ql/pricingengines/swaption/gaussian1dswaptionengine.hpp>
32
33namespace QuantLib {
34
35class Quote;
36
38 public:
41 ext::shared_ptr<SwapIndex> indexBase,
42 const ext::shared_ptr<Gaussian1dModel>& model,
43 const DayCounter& dc,
44 ext::shared_ptr<Gaussian1dSwaptionEngine> swaptionEngine =
45 ext::shared_ptr<Gaussian1dSwaptionEngine>());
47 Date maxDate() const override { return Date::maxDate(); }
49
51 Real minStrike() const override { return 0.0; }
52 Real maxStrike() const override { return QL_MAX_REAL; }
54
56 const Period& maxSwapTenor() const override { return maxSwapTenor_; }
58 protected:
59 ext::shared_ptr<SmileSection> smileSectionImpl(const Date&, const Period&) const override;
60 ext::shared_ptr<SmileSection> smileSectionImpl(Time, Time) const override;
61 Volatility volatilityImpl(const Date&, const Period&, Rate) const override;
62 Volatility volatilityImpl(Time, Time, Rate) const override;
63
64 private:
65 ext::shared_ptr<SwapIndex> indexBase_;
66 ext::shared_ptr<Gaussian1dModel> model_;
67 ext::shared_ptr<Gaussian1dSwaptionEngine> engine_;
69
70 class DateHelper {
71 public:
72 DateHelper(const TermStructure &ts, const Time t) : ts_(ts), t_(t) {}
73 Real operator()(Real date) const {
74 Date d1(static_cast<Date::serial_type>(date));
75 Date d2(static_cast<Date::serial_type>(date) + 1);
76 Real t1 = ts_.timeFromReference(d1) - t_;
77 Real t2 = ts_.timeFromReference(d2) - t_;
78 Real h = date - static_cast<Date::serial_type>(date);
79 return h * t2 + (1.0 - h) * t1;
80 }
81 Real derivative(Real date) const {
82 // use fwd difference to avoid dates before reference date
83 return (operator()(date + 1E-6) - operator()(date)) * 1E6;
84 }
86 const Time t_;
87 };
88};
89}
90
91#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
std::int_fast32_t serial_type
serial number type
Definition: date.hpp:128
static Date maxDate()
latest allowed date
Definition: date.cpp:771
day counter class
Definition: daycounter.hpp:44
ext::shared_ptr< Gaussian1dSwaptionEngine > engine_
Real minStrike() const override
the minimum strike for which the term structure can return vols
ext::shared_ptr< SmileSection > smileSectionImpl(const Date &, const Period &) const override
Volatility volatilityImpl(const Date &, const Period &, Rate) const override
Date maxDate() const override
the latest date for which the curve can return values
Real maxStrike() const override
the maximum strike for which the term structure can return vols
const Period & maxSwapTenor() const override
the largest length for which the term structure can return vols
Basic term-structure functionality.
Time timeFromReference(const Date &date) const
date/time conversion
BusinessDayConvention
Business Day conventions.
#define QL_MAX_REAL
Definition: qldefines.hpp:176
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35