QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
vanillaoption.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003 Ferdinando Ametrano
6 Copyright (C) 2007 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/exercise.hpp>
28#include <memory>
29
30namespace QuantLib {
31
33 const ext::shared_ptr<StrikedTypePayoff>& payoff,
34 const ext::shared_ptr<Exercise>& exercise)
35 : OneAssetOption(payoff, exercise) {}
36
37
39 Real targetValue,
40 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
41 Real accuracy,
42 Size maxEvaluations,
43 Volatility minVol,
44 Volatility maxVol) const {
45 return impliedVolatility(targetValue, process, DividendSchedule(),
46 accuracy, maxEvaluations, minVol, maxVol);
47 }
48
50 Real targetValue,
51 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
52 const DividendSchedule& dividends,
53 Real accuracy,
54 Size maxEvaluations,
55 Volatility minVol,
56 Volatility maxVol) const {
57
58 QL_REQUIRE(!isExpired(), "option expired");
59
60 ext::shared_ptr<SimpleQuote> volQuote(new SimpleQuote);
61
62 ext::shared_ptr<GeneralizedBlackScholesProcess> newProcess =
64
65 // engines are built-in for the time being
66 std::unique_ptr<PricingEngine> engine;
67 switch (exercise_->type()) {
69 if (dividends.empty())
70 engine = std::make_unique<AnalyticEuropeanEngine>(newProcess);
71 else
72 engine = std::make_unique<AnalyticDividendEuropeanEngine>(newProcess, dividends);
73 break;
76 if (dividends.empty())
77 engine = std::make_unique<FdBlackScholesVanillaEngine>(newProcess);
78 else
79 engine = std::make_unique<FdBlackScholesVanillaEngine>(newProcess, dividends);
80 break;
81 default:
82 QL_FAIL("unknown exercise type");
83 }
84
86 *engine,
87 *volQuote,
88 targetValue,
89 accuracy,
90 maxEvaluations,
91 minVol, maxVol);
92 }
93
94}
95
Analytic discrete-dividend European engine.
Analytic European engine.
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
market element returning a stored value
Definition: simplequote.hpp:33
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
VanillaOption(const ext::shared_ptr< StrikedTypePayoff > &, const ext::shared_ptr< Exercise > &)
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)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Option exercise classes and payoff function.
Finite-differences Black Scholes vanilla option engine.
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
Utilities for implied-volatility calculation.
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
Vanilla option on a single asset.