QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
dividend.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2005 Joseph Wang
5 Copyright (C) 2006 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/cashflows/dividend.hpp>
22#include <ql/patterns/visitor.hpp>
23
24namespace QuantLib {
25
27 auto* v1 = dynamic_cast<Visitor<Dividend>*>(&v);
28 if (v1 != nullptr)
29 v1->visit(*this);
30 else
31 CashFlow::accept(v);
32 }
33
34 std::vector<ext::shared_ptr<Dividend> >
35 DividendVector(const std::vector<Date>& dividendDates,
36 const std::vector<Real>& dividends) {
37
38 QL_REQUIRE(dividendDates.size() == dividends.size(),
39 "size mismatch between dividend dates and amounts");
40
41 std::vector<Date>::const_iterator dd;
42 std::vector<Real>::const_iterator d;
43 std::vector<ext::shared_ptr<Dividend> > items;
44 items.reserve(dividendDates.size());
45 for (dd = dividendDates.begin(), d = dividends.begin();
46 dd != dividendDates.end(); ++dd, ++d) {
47 items.push_back(ext::shared_ptr<Dividend>(new
48 FixedDividend(*d, *dd)));
49 }
50 return items;
51 }
52
53}
54
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
void accept(AcyclicVisitor &) override
Definition: dividend.cpp:26
Predetermined cash flow.
Definition: dividend.hpp:59
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
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