QuantLib: Quotes

Quotes are one of the most basic pieces of financial information. A quote is a value of any market observable. Quotes come in many shapes and forms and usually reflect the price at which a commodity traded. The Quote class in QuantLib defines the abstract base class for all quotes. Quote only has two abstract methods.

virtual Real value() const = 0;
virtual bool isValid() const = 0;

value() returns the value of a quote and isValid()  returns true if the quote holds a valid value. Both these methods have to be implemented by a concrete sub-class of Quote.

Quote inherits from Observable. This makes it possible for observers to be notified when the value of a quote changes.


The simplest implementation of the abstract Quote class is SimpleQuote. SimpleQuote does not depend on an underlying quantity but stores the value of the quote directly. The value of the simple quote can be passed in the constructor.

SimpleQuote(Real value = Null<Real>());

This will initialize the quote with a given value. Note how the default value is Null<Real>(). This value indicates that the quote does not hold a valid value.

Real value() const;
bool isValid() const;

These two methods have been implemented to return the stored value and to indicate if a valid value has been stored. The method isValid() will return false if the value which is stored in the SimpleQuote equals to Null<Real>().

Real setValue(Real value = Null<Real>());
void reset();

The value of the simple quote can be modified by these two methods. setValue() will update the quote with a new value, or erase the value of the quote is no argument is given. The method will return the difference between the old value and the new value. If the value has changed any observers of the quote will be notified (see Observer and Observable). The convenience method reset() will erase any value stored in the quote. It is equivalent to calling setValue() without arguments.

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>