QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
dividendvanillaoption.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004, 2007 StatPro Italia srl
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
20#include <ql/cashflows/cashflowvectors.hpp>
21#include <ql/exercise.hpp>
22#include <ql/instruments/dividendvanillaoption.hpp>
23#include <ql/instruments/impliedvolatility.hpp>
24#include <ql/pricingengines/vanilla/analyticdividendeuropeanengine.hpp>
25#include <ql/pricingengines/vanilla/fdblackscholesvanillaengine.hpp>
26#include <ql/utilities/dataformatters.hpp>
27#include <memory>
28
29namespace QuantLib {
30
32 const ext::shared_ptr<StrikedTypePayoff>& payoff,
33 const ext::shared_ptr<Exercise>& exercise,
34 const std::vector<Date>& dividendDates,
35 const std::vector<Real>& dividends)
36 : OneAssetOption(payoff, exercise),
37 cashFlow_(DividendVector(dividendDates, dividends)) {}
38
39
41 Real targetValue,
42 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
43 Real accuracy,
44 Size maxEvaluations,
45 Volatility minVol,
46 Volatility maxVol) const {
47
48 QL_REQUIRE(!isExpired(), "option expired");
49
50 ext::shared_ptr<SimpleQuote> volQuote(new SimpleQuote);
51
52 ext::shared_ptr<GeneralizedBlackScholesProcess> newProcess =
54
55 // engines are built-in for the time being
56 std::unique_ptr<PricingEngine> engine;
57 switch (exercise_->type()) {
59 QL_DEPRECATED_DISABLE_WARNING
60 engine = std::make_unique<AnalyticDividendEuropeanEngine>(newProcess);
61 QL_DEPRECATED_ENABLE_WARNING
62 break;
64 engine = std::make_unique<FdBlackScholesVanillaEngine>(newProcess);
65 break;
67 QL_FAIL("engine not available for Bermudan option with dividends");
68 break;
69 default:
70 QL_FAIL("unknown exercise type");
71 }
72
74 *engine,
75 *volQuote,
76 targetValue,
77 accuracy,
78 maxEvaluations,
79 minVol, maxVol);
80 }
81
82
84 PricingEngine::arguments* args) const {
86
87 auto* arguments = dynamic_cast<DividendVanillaOption::arguments*>(args);
88 QL_REQUIRE(arguments != nullptr, "wrong engine type");
89
91 }
92
93
95 OneAssetOption::arguments::validate();
96
97 Date exerciseDate = exercise->lastDate();
98
99 for (Size i = 0; i < cashFlow.size(); i++) {
100 QL_REQUIRE(cashFlow[i]->date() <= exerciseDate,
101 "the " << io::ordinal(i+1) << " dividend date ("
102 << cashFlow[i]->date()
103 << ") is later than the exercise date ("
104 << exerciseDate << ")");
105 }
106 }
107
108}
109
Concrete date class.
Definition: date.hpp:125
DividendVanillaOption(const ext::shared_ptr< StrikedTypePayoff > &payoff, const ext::shared_ptr< Exercise > &exercise, const std::vector< Date > &dividendDates, const std::vector< Real > &dividends)
void setupArguments(PricingEngine::arguments *) const override
Volatility impliedVolatility(Real price, const ext::shared_ptr< GeneralizedBlackScholesProcess > &process, Real accuracy=1.0e-4, Size maxEvaluations=100, Volatility minVol=1.0e-7, Volatility maxVol=4.0) const
virtual void setupArguments(PricingEngine::arguments *) const
Definition: instrument.cpp:45
Base class for options on a single asset.
bool isExpired() const override
returns whether the instrument might have value greater than zero.
ext::shared_ptr< Exercise > exercise_
Definition: option.hpp:50
ext::shared_ptr< Exercise > exercise() const
Definition: option.hpp:46
market element returning a stored value
Definition: simplequote.hpp:33
static ext::shared_ptr< GeneralizedBlackScholesProcess > clone(const ext::shared_ptr< GeneralizedBlackScholesProcess > &, const ext::shared_ptr< SimpleQuote > &)
static Volatility calculate(const Instrument &instrument, const PricingEngine &engine, SimpleQuote &volQuote, Real targetValue, Real accuracy, Natural maxEvaluations, Volatility minVol, Volatility maxVol)
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendVector(const std::vector< Date > &dividendDates, const std::vector< Real > &dividends)
helper function building a sequence of fixed dividends
Definition: dividend.cpp:35