QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
partialtimebarrieroption.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) 2014 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
23namespace QuantLib {
24
26 PartialBarrier::Type barrierType,
27 PartialBarrier::Range barrierRange,
28 Real barrier,
29 Real rebate,
30 Date coverEventDate,
31 const ext::shared_ptr<StrikedTypePayoff>& payoff,
32 const ext::shared_ptr<Exercise>& exercise)
33 : OneAssetOption(payoff, exercise),
34 barrierType_(barrierType), barrierRange_(barrierRange),
35 barrier_(barrier), rebate_(rebate),
36 coverEventDate_(coverEventDate) {}
37
39 PricingEngine::arguments* args) const {
41
42 auto* moreArgs = dynamic_cast<PartialTimeBarrierOption::arguments*>(args);
43 QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
44 moreArgs->barrierType = barrierType_;
45 moreArgs->barrierRange = barrierRange_;
46 moreArgs->barrier = barrier_;
47 moreArgs->rebate = rebate_;
48 moreArgs->coverEventDate = coverEventDate_;
49 }
50
52 : barrierType(PartialBarrier::Type(-1)),
53 barrierRange(PartialBarrier::Range(-1)),
54 barrier(Null<Real>()), rebate(Null<Real>()),
55 coverEventDate(Null<Date>()) {}
56
58 OneAssetOption::arguments::validate();
59
60 // checking barrier type and suitable barrier range
61 switch (barrierType) {
64 QL_REQUIRE(barrierRange == PartialBarrier::Start ||
65 barrierRange == PartialBarrier::End,
66 "in-barrier requires Start or End range");
67 break;
70 QL_REQUIRE(barrierRange == PartialBarrier::Start ||
71 barrierRange == PartialBarrier::EndB1 ||
72 barrierRange == PartialBarrier::EndB2,
73 "out-barrier requires Start, EndB1 or EndB2 range");
74 break;
75 default:
76 QL_FAIL("unknown barrier type");
77 }
78
79 QL_REQUIRE(barrier != Null<Real>(), "no barrier given");
80 QL_REQUIRE(rebate != Null<Real>(), "no rebate given");
81 QL_REQUIRE(coverEventDate != Null<Date>(), "no cover event date given");
82 QL_REQUIRE(coverEventDate < exercise->lastDate(),
83 "cover event date equal or later than exercise date");
84 }
85
86}
87
Concrete date class.
Definition: date.hpp:125
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.
Arguments for barrier option calculation
void setupArguments(PricingEngine::arguments *) const override
PartialTimeBarrierOption(PartialBarrier::Type barrierType, PartialBarrier::Range barrierRange, Real barrier, Real rebate, Date coverEventDate, 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
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
Partial-time barrier option.