Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
dynamicswaptionvolmatrix.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21#include <ql/termstructures/volatility/flatsmilesection.hpp>
22
23namespace QuantExt {
24
26 const QuantLib::ext::shared_ptr<SwaptionVolatilityStructure>& source, Natural settlementDays, const Calendar& calendar,
27 ReactionToTimeDecay decayMode)
28 : SwaptionVolatilityStructure(settlementDays, calendar, source->businessDayConvention(), source->dayCounter()),
29 source_(source), decayMode_(decayMode), originalReferenceDate_(source->referenceDate()),
30 volatilityType_(source->volatilityType()) {}
31
32const Period& DynamicSwaptionVolatilityMatrix::maxSwapTenor() const { return source_->maxSwapTenor(); }
33
34QuantLib::ext::shared_ptr<SmileSection> DynamicSwaptionVolatilityMatrix::smileSectionImpl(Time optionTime,
35 Time swapLength) const {
36 // null strike to indicate ATM
37 return QuantLib::ext::make_shared<FlatSmileSection>(optionTime, volatilityImpl(optionTime, swapLength, Null<Real>()),
38 source_->dayCounter(), Null<Real>(), source_->volatilityType(),
39 shiftImpl(optionTime, swapLength));
40}
41
42Volatility DynamicSwaptionVolatilityMatrix::volatilityImpl(Time optionTime, Time swapLength, Rate strike) const {
44 Real tf = source_->timeFromReference(referenceDate());
45 if (source_->volatilityType() == ShiftedLognormal) {
46 QL_REQUIRE(close_enough(source_->shift(tf + optionTime, swapLength), source_->shift(tf, swapLength)),
47 "DynamicSwaptionVolatilityMatrix: Shift must be constant in option time direction");
48 }
49 Real realisedVariance =
50 source_->blackVariance(tf + optionTime, swapLength, strike) -
51 (tf > 0.0 && !close_enough(tf, 0.0) ? source_->blackVariance(tf, swapLength, strike) : 0.0);
52 return std::sqrt(std::max(realisedVariance / optionTime, 1E-6));
53 }
55 return source_->volatility(optionTime, swapLength, strike);
56 }
57 QL_FAIL("unexpected decay mode (" << decayMode_ << ")");
58}
59
60Real DynamicSwaptionVolatilityMatrix::shiftImpl(Time optionTime, Time swapLength) const {
61 if (source_->volatilityType() == Normal) {
62 return 0.0;
63 }
65 Real tf = source_->timeFromReference(referenceDate());
66 return source_->shift(tf + optionTime, swapLength);
67 }
69 return source_->shift(optionTime, swapLength);
70 }
71 QL_FAIL("unexpected decay mode (" << decayMode_ << ")");
72}
73
74Real DynamicSwaptionVolatilityMatrix::minStrike() const { return source_->minStrike(); }
75
76Real DynamicSwaptionVolatilityMatrix::maxStrike() const { return source_->maxStrike(); }
77
80 return source_->maxDate();
81 }
83 return Date(std::min(Date::maxDate().serialNumber(), referenceDate().serialNumber() -
84 originalReferenceDate_.serialNumber() +
85 source_->maxDate().serialNumber()));
86 }
87 QL_FAIL("unexpected decay mode (" << decayMode_ << ")");
88}
89
90void DynamicSwaptionVolatilityMatrix::update() { SwaptionVolatilityStructure::update(); }
91
92} // namespace QuantExt
Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const override
QuantLib::ext::shared_ptr< SmileSection > smileSectionImpl(Time optionTime, Time swapLength) const override
Real shiftImpl(Time optionTime, Time swapLength) const override
DynamicSwaptionVolatilityMatrix(const QuantLib::ext::shared_ptr< SwaptionVolatilityStructure > &source, Natural settlementDays, const Calendar &calendar, ReactionToTimeDecay decayMode=ConstantVariance)
const QuantLib::ext::shared_ptr< SwaptionVolatilityStructure > source_
dynamic swaption volatility matrix
ReactionToTimeDecay
Reaction to Time Decay.
@ ConstantVariance
@ ForwardForwardVariance
Filter close_enough(const RandomVariable &x, const RandomVariable &y)