1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/*
Copyright (C) 2000-2004 StatPro Italia srl
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
/*! \defgroup instruments Financial instruments
Since version 0.3.4, the <tt>Instrument</tt> class was reworked
as shown in the following figure.
\latexonly
\begin{center}
\includegraphics[width=14cm]{instrument}
\end{center}
\endlatexonly
\htmlonly
<center><img src="instrument.png" alt="UML diagram"></center>
\endhtmlonly
On the one hand, the checking of the expiration condition is now
performed in a method <tt>isExpired()</tt> separated from the actual
calculation, and a <tt>setupExpired()</tt> method is provided.
The latter sets the NPV to 0.0 and can be extended in derived
classes should any other results be returned.
On the other hand, the pricing-engine machinery previously
contained in the Option class was moved upwards to the Instrument
class. Also, the <tt>setupEngine()</tt> method was replaced by a
<tt>setupArguments(Arguments*)</tt> method. This allows one to
cleanly implement containment of instruments with code such as:
\code
class FooArguments : public Arguments { ... };
class Foo : public Instrument {
public:
void setupArguments(Arguments*);
...
};
class FooOptionArguments : public FooArguments { ... };
class FooOption : public Option {
private:
Foo underlying_;
public:
void setupArguments(Arguments* args) {
underlying_.setupArguments(args);
// set the option-specific part
}
...
};
\endcode
which was more difficult to write with <tt>setupEngine()</tt>.
Therefore, there are now two ways to inherit from
<tt>Instrument</tt>, namely:
-# implement the <tt>isExpired</tt> method, and completely
override the <tt>performCalculations</tt> method so that
it bypasses the pricing-engine machinery. If the class
declared any other results beside <tt>NPV_</tt> and
<tt>errorEstimate_</tt>, the <tt>setupExpired</tt> method
should also be extended so that those results are set to a
value suitable for an expired instrument. This was the migration
path taken for all instruments not previously deriving from
the <tt>Option</tt> class.
-# define suitable argument and result classes for the instrument
and implement the <tt>isExpired</tt> and <tt>setupArguments</tt>
methods, reusing the pricing-engine machinery provided by
the default <tt>performCalculations</tt> method. The latter
can be extended by first calling the default implementation
and then performing any additional tasks required by the
instrument---most often, copying additional results from the
pricing engine results to the corresponding data members of
the instrument. As in the previous case, the <tt>setupExpired</tt>
method can be extended to account for such extra data members.
*/
|