QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
gaussian1dswaptionvolatility.cpp
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
20#include <ql/math/solvers1d/newtonsafe.hpp>
21#include <ql/termstructures/volatility/gaussian1dsmilesection.hpp>
22#include <ql/termstructures/volatility/swaption/gaussian1dswaptionvolatility.hpp>
23#include <utility>
24
25namespace QuantLib {
26
28 const Calendar& cal,
30 ext::shared_ptr<SwapIndex> indexBase,
31 const ext::shared_ptr<Gaussian1dModel>& model,
32 const DayCounter& dc,
33 ext::shared_ptr<Gaussian1dSwaptionEngine> swaptionEngine)
34 : SwaptionVolatilityStructure(model->termStructure()->referenceDate(), cal, bdc, dc),
35 indexBase_(std::move(indexBase)), model_(model), engine_(std::move(swaptionEngine)),
36 maxSwapTenor_(100 * Years) {}
37
38 ext::shared_ptr<SmileSection>
40 ext::shared_ptr<SmileSection> tmp = ext::make_shared<Gaussian1dSmileSection>(
41 d, indexBase_->clone(tenor), model_, this->dayCounter(), engine_);
42 return tmp;
43}
44
45ext::shared_ptr<SmileSection>
47 Time swapLength) const {
48 DateHelper hlp(*this, optionTime);
49 NewtonSafe newton;
50 Date d(static_cast<Date::serial_type>(newton.solve(
51 hlp, 0.1,
52 365.25 * optionTime + static_cast<Real>(referenceDate().serialNumber()),
53 1.0)));
54 Period tenor(
55 static_cast<Integer>(Rounding(0)(swapLength * 12.0)),
56 Months);
57 d = indexBase_->fixingCalendar().adjust(d);
58 return smileSectionImpl(d, tenor);
59}
60
62 const Period &tenor,
63 Rate strike) const {
64 return smileSectionImpl(d, tenor)->volatility(strike);
65}
66
68 Time swapLength,
69 Rate strike) const {
70 return smileSectionImpl(optionTime, swapLength)->volatility(strike);
71}
72}
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
day counter class
Definition: daycounter.hpp:44
Gaussian1dSwaptionVolatility(const Calendar &cal, BusinessDayConvention bdc, ext::shared_ptr< SwapIndex > indexBase, const ext::shared_ptr< Gaussian1dModel > &model, const DayCounter &dc, ext::shared_ptr< Gaussian1dSwaptionEngine > swaptionEngine=ext::shared_ptr< Gaussian1dSwaptionEngine >())
ext::shared_ptr< Gaussian1dSwaptionEngine > engine_
ext::shared_ptr< SmileSection > smileSectionImpl(const Date &, const Period &) const override
Volatility volatilityImpl(const Date &, const Period &, Rate) const override
safe Newton 1-D solver
Definition: newtonsafe.hpp:40
basic rounding class
Definition: rounding.hpp:35
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Definition: solver1d.hpp:84
Time swapLength(const Period &swapTenor) const
implements the conversion between swap tenor and swap (time) length
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
BusinessDayConvention
Business Day conventions.
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
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
STL namespace.