QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
abcdatmvolcurve.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Cristina Duminuco
5 Copyright (C) 2007 Ferdinando Ametrano
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/experimental/volatility/abcdatmvolcurve.hpp>
22#include <ql/quote.hpp>
23#include <ql/utilities/dataformatters.hpp>
24#include <utility>
25
26namespace QuantLib {
27
28 // floating reference date, floating market data
30 const Calendar& cal,
31 const std::vector<Period>& optionTenors,
32 const std::vector<Handle<Quote> >& volsHandles,
33 std::vector<bool> inclusionInInterpolationFlag,
35 const DayCounter& dc)
36 : BlackAtmVolCurve(settlDays, cal, bdc, dc), nOptionTenors_(optionTenors.size()),
37 optionTenors_(optionTenors), optionDates_(nOptionTenors_), optionTimes_(nOptionTenors_),
38 actualOptionTimes_(nOptionTenors_), volHandles_(volsHandles), vols_(volsHandles.size()),
39 actualVols_(volsHandles.size()),
40 inclusionInInterpolation_(std::move(inclusionInInterpolationFlag)) {
45 for (Size i=0; i<vols_.size(); ++i)
46 vols_[i] = volHandles_[i]->value();
48 }
49
51 {
52 QL_REQUIRE(!optionTenors_.empty(), "empty option tenor vector");
53 QL_REQUIRE(nOptionTenors_==vols_.size(),
54 "mismatch between number of option tenors (" <<
55 nOptionTenors_ << ") and number of volatilities (" <<
56 vols_.size() << ")");
57 QL_REQUIRE(optionTenors_[0]>0*Days,
58 "negative first option tenor: " << optionTenors_[0]);
59 for (Size i=1; i<nOptionTenors_; ++i)
60 QL_REQUIRE(optionTenors_[i]>optionTenors_[i-1],
61 "non increasing option tenor: " << io::ordinal(i) <<
62 " is " << optionTenors_[i-1] << ", " <<
63 io::ordinal(i+1) << " is " << optionTenors_[i]);
64 if (inclusionInInterpolation_.size()==1) {
66 for(Size j=1; j<nOptionTenors_;++j)
68 } else
70 "mismatch between number of option tenors (" <<
71 nOptionTenors_ << ") and number of inclusion's flags (" <<
72 inclusionInInterpolation_.size() << ")");
73 }
74
76 {
77 for (auto& volHandle : volHandles_)
78 registerWith(volHandle);
79 }
80
82 {
83 interpolation_ = ext::make_shared<AbcdInterpolation>(actualOptionTimes_.begin(),
85 actualVols_.begin());
86 }
87
89 auto* v1 = dynamic_cast<Visitor<AbcdAtmVolCurve>*>(&v);
90 if (v1 != nullptr)
91 v1->visit(*this);
92 else
93 QL_FAIL("not a AbcdAtmVolCurve visitor");
94 }
95
97 {
98 // recalculate dates if necessary...
99 if (moving_) {
101 if (evaluationDate_ != d) {
104 }
105 }
108 }
109
111 {
112 // the input time data
113 for (Size i=0; i<nOptionTenors_; ++i) {
116 }
117 // the time data used for interpolation
118 actualOptionTimes_.clear();
119 for (Size i=0; i<nOptionTenors_; ++i) {
121 actualOptionTimes_.push_back(optionTimes_[i]);
123 }
124 }
125 }
126
128
129 actualVols_.clear();
130 for (Size i=0; i<nOptionTenors_; ++i) {
131 vols_[i] = volHandles_[i]->value();
133 actualVols_.push_back(vols_[i]);
134 }
135 }
136
138 {
139 // check if date recalculation must be called here
140 actualVols_.clear();
141 for (Size i=0; i<vols_.size(); ++i) {
142 vols_[i] = volHandles_[i]->value();
144 actualVols_.push_back(vols_[i]);
145 }
146 interpolation_->update();
147 }
148
149}
std::vector< Date > optionDates_
void performCalculations() const override
std::vector< Volatility > actualVols_
void accept(AcyclicVisitor &) override
std::vector< Time > optionTimes_
AbcdAtmVolCurve(Natural settlementDays, const Calendar &cal, const std::vector< Period > &optionTenors, const std::vector< Handle< Quote > > &volsHandles, std::vector< bool > inclusionInInterpolationFlag=std::vector< bool >(1, true), BusinessDayConvention bdc=Following, const DayCounter &dc=Actual365Fixed())
floating reference date, floating market data
std::vector< bool > inclusionInInterpolation_
std::vector< Period > optionTenors_
std::vector< Period > actualOptionTenors_
std::vector< Volatility > vols_
void initializeOptionDatesAndTimes() const
std::vector< Handle< Quote > > volHandles_
std::vector< Time > actualOptionTimes_
ext::shared_ptr< AbcdInterpolation > interpolation_
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Black at-the-money (no-smile) volatility curve.
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
void update() override
Definition: lazyobject.hpp:188
virtual void update()=0
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
Time timeFromReference(const Date &date) const
date/time conversion
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Date optionDateFromTenor(const Period &) const
period/date conversion
BusinessDayConvention
Business Day conventions.
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.