QuantLib: Cashflow and SimpleCashFlow

CashFlow is an abstract base class for cash flows. The cash flow interface is implemented by many classes such as SimpleCashFlow, Coupon and many more. The multitude of different cash flows will be handled in another post. Here we will focus on the base class for all these cash flows and the simplest implementations.

CashFlow inherits from the Event interface. The Event::date() method is still left as an abstract method. The method hasOccured() is changed so that the global setting is taken into account. The Settings singleton defines a method

boost::optional &Settings::includeTodaysCashFlows();

If set, this setting overrides any includeRefDate parameter passed to the hasOccurred() method.

The method that has been added to the CashFlow interface is the amount() method. The declaration is

virtual double amount() = 0;

This method should be implemented by a cash flow class to return the cash flow amount.

In addition to the above, the CashFlow class implements the Visitability concept. This means it has a method called accept() which accepts an AcyclicVisitor.

virtual void accept(AcyclicVisitor &v);

The visitability concept is dealt with in a separate article. Here we will only state that the accept() method attempts to convert the visitor into the Visitor<CashFlow> type using a dynamic typecast. If the cast is successful, the visit method of the visitor class is called.

The file cashflow.hpp also includes a type definition for Leg, a collection of cash flows.

typedef std::vector > Leg;

SimpleCashFlow

As an example consider the simplest cash flow class SimpleCashFlow. This class represents a fixed cash flow at a specific date. The constructor of this class takes a date and the amount and these values are stored internally.

SimpleCashFlow(Real amount, const Date& date);

The date() method is implemented to return the specified date, and the amount() method is implemented to return the specified amount.

Other simple cash flows

Two more cash flows exist that inherit from SimpleCashFlow without adding any more functionality. These are the classes Redemption and AmortizingPayment.

The reason for defining these two cash flows is for visitors to distinguish between different types of cash flows. Visitation is dealt with in a separate post and an example involving these cash flows is given there. Suffice to say here that these two cash flows re-implement the accept() method which attempts to call the appropriate function of the visitor passed to them.

Follow the author

2 Comments

  1. fahd

    Hello ,
    Many thanks for all these posts…
    Please i’m not familiar with this library… i have questions:
    *First of all can you send me a template for cashflow (for example) .

    *If i make a project how can i use the quantlib ?
    for example if i made a cach flow project do i have to create my own header with classes or i will not ? and how to instanciate the quantlib library?

    Please i have many questions that might seem very basic for you.. but .. share answers

    Thank you all

    Reply
    1. mikail (Post author)

      You can find basic information about the QuntLib library, how to install it and how to use it on the QuantLib Home Page.

      Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>