Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
spreadedblackvolatilitycurve.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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
22
23namespace QuantExt {
24
25SpreadedBlackVolatilityCurve::SpreadedBlackVolatilityCurve(const Handle<BlackVolTermStructure>& referenceVol,
26 const std::vector<Time>& times,
27 const std::vector<Handle<Quote>>& volSpreads,
28 const bool useAtmReferenceVolsOnly)
29 : BlackVolatilityTermStructure(referenceVol->businessDayConvention(), referenceVol->dayCounter()),
30 referenceVol_(referenceVol), times_(times), volSpreads_(volSpreads),
31 useAtmReferenceVolsOnly_(useAtmReferenceVolsOnly), data_(times.size(), 0.0) {
32 registerWith(referenceVol_);
33 QL_REQUIRE(times_.size() >= 2, "at least two times required");
34 QL_REQUIRE(times_.size() == volSpreads_.size(), "size of time and quote vectors do not match");
35 for (Size i = 0; i < volSpreads_.size(); ++i)
36 registerWith(volSpreads_[i]);
37 interpolation_ = QuantLib::ext::make_shared<FlatExtrapolation>(
38 QuantLib::ext::make_shared<LinearInterpolation>(times_.begin(), times_.end(), data_.begin()));
39 interpolation_->enableExtrapolation();
40}
41
42Date SpreadedBlackVolatilityCurve::maxDate() const { return referenceVol_->maxDate(); }
43
44const Date& SpreadedBlackVolatilityCurve::referenceDate() const { return referenceVol_->referenceDate(); }
45
46Calendar SpreadedBlackVolatilityCurve::calendar() const { return referenceVol_->calendar(); }
47
48Natural SpreadedBlackVolatilityCurve::settlementDays() const { return referenceVol_->settlementDays(); }
49
50Real SpreadedBlackVolatilityCurve::minStrike() const { return referenceVol_->minStrike(); }
51
52Real SpreadedBlackVolatilityCurve::maxStrike() const { return referenceVol_->maxStrike(); }
53
55 LazyObject::update();
56 BlackVolatilityTermStructure::update();
57}
58
60 for (Size i = 0; i < times_.size(); ++i) {
61 QL_REQUIRE(!volSpreads_[i].empty(), "SpreadedBlackVolatilityCurve: empty quote at index " << (i - 1));
62 data_[i] = volSpreads_[i]->value();
63 }
64 interpolation_->update();
65}
66
68 calculate();
69 return referenceVol_->blackVol(t, useAtmReferenceVolsOnly_ ? Null<Real>() : k) + (*interpolation_)(t);
70}
71
72} // namespace QuantExt
Real blackVolImpl(Time t, Real) const override
SpreadedBlackVolatilityCurve(const Handle< BlackVolTermStructure > &referenceVol, const std::vector< Time > &times, const std::vector< Handle< Quote > > &volSpreads, const bool useAtmReferenceVolsOnly=false)
QuantLib::ext::shared_ptr< Interpolation > interpolation_
flat interpolation decorator
Spreaded Black volatility curve.