QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
gaussian1dsmilesection.cpp
Go to the documentation of this file.
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#include <utility>
25
26using std::sqrt;
27
28namespace QuantLib {
29
31 const Date& fixingDate,
32 ext::shared_ptr<SwapIndex> swapIndex,
33 const ext::shared_ptr<Gaussian1dModel>& model,
34 const DayCounter& dc,
35 const ext::shared_ptr<Gaussian1dSwaptionEngine>& swaptionEngine)
36 : SmileSection(fixingDate, dc, model->termStructure()->referenceDate()),
37 fixingDate_(fixingDate), swapIndex_(std::move(swapIndex)), model_(model),
38 engine_(swaptionEngine) {
39
40 atm_ = model_->swapRate(fixingDate_, swapIndex_->tenor(), Null<Date>(), 0.0, swapIndex_);
41 annuity_ =
42 model_->swapAnnuity(fixingDate_, swapIndex_->tenor(), Null<Date>(), 0.0, swapIndex_);
43
44 if (engine_ == nullptr) {
45 engine_ = ext::make_shared<Gaussian1dSwaptionEngine>(
46 model_, 64, 7.0, true, false, swapIndex_->discountingTermStructure());
47 }
48 }
49
51 const Date& fixingDate,
52 ext::shared_ptr<IborIndex> iborIndex,
53 const ext::shared_ptr<Gaussian1dModel>& model,
54 const DayCounter& dc,
55 const ext::shared_ptr<Gaussian1dCapFloorEngine>& capEngine)
56 : SmileSection(fixingDate, dc, model->termStructure()->referenceDate()),
57 fixingDate_(fixingDate), iborIndex_(std::move(iborIndex)), model_(model), engine_(capEngine) {
58
59 atm_ = model_->forwardRate(fixingDate_, Null<Date>(), 0.0, iborIndex_);
60 CapFloor c =
63 annuity_ = iborIndex_->dayCounter().yearFraction(c.startDate(), c.maturityDate()) *
64 model_->zerobond(c.maturityDate());
65
66 if (engine_ == nullptr) {
67 engine_ = ext::make_shared<Gaussian1dCapFloorEngine>(
68 model_, 64, 7.0, true,
69 false); // use model curve as discounting curve
70 }
71 }
72
74
76 Real discount) const {
77
78 if (swapIndex_ != nullptr) {
84 Real tmp = s.NPV();
85 return tmp / annuity_ * discount;
86 } else {
87 CapFloor c =
89 iborIndex_->tenor(), iborIndex_, strike, 0 * Days)
92 Real tmp = c.NPV();
93 return tmp / annuity_ * discount;
94 }
95}
96
98 Real vol = 0.0;
99 try {
100 Option::Type type = strike >= atm_ ? Option::Call : Option::Put;
101 Real o = optionPrice(strike, type);
102 vol = blackFormulaImpliedStdDev(type, strike, atm_, o) /
103 sqrt(exerciseTime());
104 } catch (...) {
105 }
106 return vol;
107}
108}
Black formula.
ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:60
Base class for cap-like instruments.
Definition: capfloor.hpp:55
Date startDate() const
Definition: capfloor.cpp:179
Date maturityDate() const
Definition: capfloor.cpp:183
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
ext::shared_ptr< IborIndex > iborIndex_
ext::shared_ptr< SwapIndex > swapIndex_
ext::shared_ptr< PricingEngine > engine_
ext::shared_ptr< Gaussian1dModel > model_
Gaussian1dSmileSection(const Date &fixingDate, ext::shared_ptr< SwapIndex > swapIndex, const ext::shared_ptr< Gaussian1dModel > &model, const DayCounter &dc, const ext::shared_ptr< Gaussian1dSwaptionEngine > &swaptionEngine=ext::shared_ptr< Gaussian1dSwaptionEngine >())
Real optionPrice(Rate strike, Option::Type=Option::Call, Real discount=1.0) const override
Real volatilityImpl(Rate strike) const override
Real NPV() const
returns the net present value of the instrument.
Definition: instrument.hpp:167
MakeCapFloor & withEffectiveDate(const Date &effectiveDate, bool firstCapletExcluded)
MakeCapFloor & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
MakeSwaption & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
MakeSwaption & withUnderlyingType(Swap::Type type)
template class providing a null value for a given type.
Definition: null.hpp:76
interest rate volatility smile section
virtual Time exerciseTime() const
Swaption class
Definition: swaption.hpp:88
smile section generated by a gaussian 1d model
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Helper class to instantiate standard market cap/floor.
Helper class to instantiate standard market swaption.
Definition: any.hpp:35
Real blackFormulaImpliedStdDev(Option::Type optionType, Real strike, Real forward, Real blackPrice, Real discount, Real displacement, Real guess, Real accuracy, Natural maxIterations)
STL namespace.