QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
dividendbarrieroption.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Andreas Gaida
5 Copyright (C) 2008 Ralph Schreyer
6 Copyright (C) 2008 Klaus Spanderen
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/instruments/dividendbarrieroption.hpp>
23#include <ql/utilities/dataformatters.hpp>
24#include <ql/exercise.hpp>
25
26namespace QuantLib {
27
29 Barrier::Type barrierType,
30 Real barrier,
31 Real rebate,
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 : BarrierOption(barrierType, barrier, rebate, payoff, exercise),
37 cashFlow_(DividendVector(dividendDates, dividends)) {}
38
39
41 PricingEngine::arguments* args) const {
43
44 QL_DEPRECATED_DISABLE_WARNING
45 auto* arguments = dynamic_cast<DividendBarrierOption::arguments*>(args);
46 QL_REQUIRE(arguments != nullptr, "wrong engine type");
47
49 QL_DEPRECATED_ENABLE_WARNING
50 }
51
52
55
56 Date exerciseDate = exercise->lastDate();
57
58 for (Size i = 0; i < cashFlow.size(); i++) {
59 QL_REQUIRE(cashFlow[i]->date() <= exerciseDate,
60 "the " << io::ordinal(i+1) << " dividend date ("
61 << cashFlow[i]->date()
62 << ") is later than the exercise date ("
63 << exerciseDate << ")");
64 }
65 }
66
68 switch (arguments_.barrierType) {
69 case Barrier::DownIn:
71 return underlying < arguments_.barrier;
72 case Barrier::UpIn:
73 case Barrier::UpOut:
74 return underlying > arguments_.barrier;
75 default:
76 QL_FAIL("unknown type");
77 }
78 }
79
80}
Barrier option on a single asset.
void setupArguments(PricingEngine::arguments *) const override
Concrete date class.
Definition: date.hpp:125
void setupArguments(PricingEngine::arguments *) const override
DividendBarrierOption(Barrier::Type barrierType, Real barrier, Real rebate, const ext::shared_ptr< StrikedTypePayoff > &payoff, const ext::shared_ptr< Exercise > &exercise, const std::vector< Date > &dividendDates, const std::vector< Real > &dividends)
ext::shared_ptr< Exercise > exercise() const
Definition: option.hpp:46
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
QL_REAL Real
real number
Definition: types.hpp:50
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