QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
doublebarrieroption.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) 2015 Thema Consulting SA
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/exercise.hpp>
24#include <memory>
25
26namespace QuantLib {
27
29 DoubleBarrier::Type barrierType,
30 Real barrier_lo,
31 Real barrier_hi,
32 Real rebate,
33 const ext::shared_ptr<StrikedTypePayoff>& payoff,
34 const ext::shared_ptr<Exercise>& exercise)
35 : OneAssetOption(payoff, exercise),
36 barrierType_(barrierType), barrier_lo_(barrier_lo),
37 barrier_hi_(barrier_hi), rebate_(rebate) {}
38
40
42
43 auto* moreArgs = dynamic_cast<DoubleBarrierOption::arguments*>(args);
44 QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
45 moreArgs->barrierType = barrierType_;
46 moreArgs->barrier_lo = barrier_lo_;
47 moreArgs->barrier_hi = barrier_hi_;
48 moreArgs->rebate = rebate_;
49 }
50
51
53 Real targetValue,
54 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
55 Real accuracy,
56 Size maxEvaluations,
57 Volatility minVol,
58 Volatility maxVol) const {
59
60 QL_REQUIRE(!isExpired(), "option expired");
61
62 ext::shared_ptr<SimpleQuote> volQuote(new SimpleQuote);
63
64 ext::shared_ptr<GeneralizedBlackScholesProcess> newProcess =
66
67 // engines are built-in for the time being
68 std::unique_ptr<PricingEngine> engine;
69 switch (exercise_->type()) {
71 engine = std::make_unique<AnalyticDoubleBarrierEngine>(newProcess);
72 break;
75 QL_FAIL("engine not available for non-European barrier option");
76 break;
77 default:
78 QL_FAIL("unknown exercise type");
79 }
80
82 *engine,
83 *volQuote,
84 targetValue,
85 accuracy,
86 maxEvaluations,
87 minVol, maxVol);
88 }
89
90
92 : barrierType(DoubleBarrier::Type(-1)), barrier_lo(Null<Real>()),
93 barrier_hi(Null<Real>()), rebate(Null<Real>()) {}
94
96 OneAssetOption::arguments::validate();
97
98 QL_REQUIRE(barrierType == DoubleBarrier::KnockIn ||
99 barrierType == DoubleBarrier::KnockOut ||
100 barrierType == DoubleBarrier::KIKO ||
101 barrierType == DoubleBarrier::KOKI,
102 "Invalid barrier type");
103
104 QL_REQUIRE(barrier_lo != Null<Real>(), "no low barrier given");
105 QL_REQUIRE(barrier_hi != Null<Real>(), "no high barrier given");
106 QL_REQUIRE(rebate != Null<Real>(), "no rebate given");
107 }
108
110 return underlying <= arguments_.barrier_lo || underlying >= arguments_.barrier_hi;
111 }
112
113}
114
Analytic double barrier european option engines.
Arguments for double barrier option calculation
Double-Barrier-option engine base class
DoubleBarrierOption(DoubleBarrier::Type barrierType, Real barrier_lo, Real barrier_hi, Real rebate, const ext::shared_ptr< StrikedTypePayoff > &payoff, const ext::shared_ptr< Exercise > &exercise)
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
template class providing a null value for a given type.
Definition: null.hpp:76
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
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)
double Barrier european option on a single asset
#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.
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
Placeholder for enumerated barrier types.
@ KOKI
lower barrier KI, upper KO