QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
twoassetbarrieroption.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) 2012 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
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
21#include <ql/exercise.hpp>
22#include <ql/event.hpp>
23
24namespace QuantLib {
25
27 Barrier::Type barrierType,
28 Real barrier,
29 const ext::shared_ptr<StrikedTypePayoff>& payoff,
30 const ext::shared_ptr<Exercise>& exercise)
31 : Option(payoff, exercise), barrierType_(barrierType), barrier_(barrier) {}
32
34 PricingEngine::arguments* args) const {
36 auto* moreArgs = dynamic_cast<TwoAssetBarrierOption::arguments*>(args);
37 QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
38 moreArgs->barrierType = barrierType_;
39 moreArgs->barrier = barrier_;
40 }
41
43 return detail::simple_event(exercise_->lastDate()).hasOccurred();
44 }
45
47 : barrierType(Barrier::Type(-1)), barrier(Null<Real>()) {}
48
51
52 switch (barrierType) {
53 case Barrier::DownIn:
54 case Barrier::UpIn:
56 case Barrier::UpOut:
57 break;
58 default:
59 QL_FAIL("unknown type");
60 }
61
62 QL_REQUIRE(barrier != Null<Real>(), "no barrier given");
63 }
64
66 switch (arguments_.barrierType) {
67 case Barrier::DownIn:
69 return underlying < arguments_.barrier;
70 case Barrier::UpIn:
71 case Barrier::UpOut:
72 return underlying > arguments_.barrier;
73 default:
74 QL_FAIL("unknown type");
75 }
76 }
77
78}
79
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
Definition: event.cpp:28
template class providing a null value for a given type.
Definition: null.hpp:76
void validate() const override
Definition: option.hpp:60
base option class
Definition: option.hpp:36
void setupArguments(PricingEngine::arguments *) const override
Definition: option.hpp:92
ext::shared_ptr< Exercise > exercise_
Definition: option.hpp:50
Arguments for two-asset barrier option calculation
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
returns whether the instrument might have value greater than zero.
TwoAssetBarrierOption(Barrier::Type barrierType, Real barrier, const ext::shared_ptr< StrikedTypePayoff > &payoff, const ext::shared_ptr< Exercise > &exercise)
#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
Base class for events associated with a given date.
Option exercise classes and payoff function.
QL_REAL Real
real number
Definition: types.hpp:50
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
Placeholder for enumerated barrier types.
Definition: barriertype.hpp:35
Barrier option on two assets.