Financial instruments
Detailed Description
Since version 0.3.4, the Instrument class was reworked as shown in the following figure.
On the one hand, the checking of the expiration condition is now performed in a method isExpired() separated from the actual calculation, and a setupExpired() 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 setupEngine() method was replaced by a setupArguments(Arguments*) method. This allows one to cleanly implement containment of instruments with code such as:
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);
}
...
};
which was more difficult to write with setupEngine() .
Therefore, there are now two ways to inherit from Instrument , namely:
- implement the
isExpired method, and completely override the performCalculations method so that it bypasses the pricing-engine machinery. If the class declared any other results beside NPV_ and errorEstimate_ , the setupExpired 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 Option class. - define suitable argument and result classes for the instrument and implement the
isExpired and setupArguments methods, reusing the pricing-engine machinery provided by the default performCalculations 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 setupExpired method can be extended to account for such extra data members.
|