QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
compositeinstrument.hpp
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) 2006 StatPro Italia srl
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/*! \file compositeinstrument.hpp
21 \brief Composite instrument class
22*/
23
24#ifndef quantlib_composite_instrument_hpp
25#define quantlib_composite_instrument_hpp
26
27#include <ql/instrument.hpp>
28#include <list>
29#include <utility>
30
31namespace QuantLib {
32
33 //! %Composite instrument
34 /*! This instrument is an aggregate of other instruments. Its NPV
35 is the sum of the NPVs of its components, each possibly
36 multiplied by a given factor.
37
38 \warning Methods that drive the calculation directly (such as
39 recalculate(), freeze() and others) might not work
40 correctly.
41
42 \ingroup instruments
43 */
45 typedef std::pair<ext::shared_ptr<Instrument>, Real> component;
46 typedef std::list<component>::iterator iterator;
47 typedef std::list<component>::const_iterator const_iterator;
48 public:
49 //! adds an instrument to the composite
50 void add(const ext::shared_ptr<Instrument>& instrument,
51 Real multiplier = 1.0);
52 //! shorts an instrument from the composite
53 void subtract(const ext::shared_ptr<Instrument>& instrument,
54 Real multiplier = 1.0);
55 //! \name Observer interface
56 //@{
57 void deepUpdate() override;
58 //@}
59 //! \name Instrument interface
60 //@{
61 bool isExpired() const override;
62
63 protected:
64 void performCalculations() const override;
65 //@}
66 private:
67 std::list<component> components_;
68 };
69
70}
71
72#endif
std::pair< ext::shared_ptr< Instrument >, Real > component
void performCalculations() const override
void add(const ext::shared_ptr< Instrument > &instrument, Real multiplier=1.0)
adds an instrument to the composite
bool isExpired() const override
returns whether the instrument might have value greater than zero.
std::list< component >::iterator iterator
std::list< component >::const_iterator const_iterator
void subtract(const ext::shared_ptr< Instrument > &instrument, Real multiplier=1.0)
shorts an instrument from the composite
std::list< component > components_
Abstract instrument class.
Definition: instrument.hpp:44
QL_REAL Real
real number
Definition: types.hpp:50
Abstract instrument class.
Definition: any.hpp:35