Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackvolsurfacewithatm.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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
21namespace QuantExt {
22
23BlackVolatilityWithATM::BlackVolatilityWithATM(const QuantLib::ext::shared_ptr<BlackVolTermStructure>& surface,
24 const Handle<Quote>& spot, const Handle<YieldTermStructure>& yield1,
25 const Handle<YieldTermStructure>& yield2)
26 : BlackVolatilityTermStructure(0, surface->calendar(), surface->businessDayConvention(), surface->dayCounter()),
27 surface_(surface), spot_(spot), yield1_(yield1), yield2_(yield2) {
28
29 QL_REQUIRE(!spot.empty(), "No spot handle provided");
30
31 if (surface->allowsExtrapolation())
32 this->enableExtrapolation();
33
34 registerWith(surface);
35 registerWith(spot);
36 registerWith(yield1);
37 registerWith(yield2);
38}
39
40Volatility BlackVolatilityWithATM::blackVolImpl(Time t, Real strike) const {
41 if (strike == Null<Real>() || strike == 0) {
42 // calculate fwd(t)
43 strike = spot_->value();
44 if (!yield1_.empty() && !yield2_.empty())
45 strike *= yield2_->discount(t, true) / yield1_->discount(t, true);
46 }
47 return surface_->blackVol(t, strike);
48}
49
50} // namespace QuantExt
Wrapper class for a BlackVolTermStructure that easily exposes ATM vols.
Handle< YieldTermStructure > yield2() const
QuantLib::ext::shared_ptr< BlackVolTermStructure > surface_
QuantLib::ext::shared_ptr< BlackVolTermStructure > surface() const
Handle< YieldTermStructure > yield1() const
Handle< YieldTermStructure > yield1_
Volatility blackVolImpl(Time t, Real strike) const override
Handle< YieldTermStructure > yield2_
BlackVolatilityWithATM(const QuantLib::ext::shared_ptr< BlackVolTermStructure > &surface, const Handle< Quote > &spot, const Handle< YieldTermStructure > &yield1=Handle< YieldTermStructure >(), const Handle< YieldTermStructure > &yield2=Handle< YieldTermStructure >())
Constructor. This is a floating term structure (settlement days is zero)