Frameworks in The Financial Engineering Domain An Experience Report
Frameworks in The Financial Engineering Domain An Experience Report
Frameworks in The Financial Engineering Domain An Experience Report
Abstract: To supply the financial engineering community with adequate and timely software
support we advocate a reusability oriented approach to software development. The ap proach
focuses on frameworks and reusable building blocks. This paper presents a domain specific
framework for a calculation engine to be used in financial trading software. It is as such an
example of using frameworks outside their typical domain of graphical user interfaces.
Introduction
provided, etc. With all these variable factors considerable effort, and therefore cost,
must be expended to match investors and borrowers and negotiate on the various characteristics of a potential deal. Financial instruments help reduce these costs by standardising the conditions under which financial transactions are carried out. Investors and
borrowers can then choose the most attractive construction (instrument) available to
them; typically with the aid of some intermediary. This is also eased by the fact that
most financial instruments are highly fungible and traded anonymously.
Financial instruments have evolved from mere contracts for lending and borrowing to
specialised means for transforming various characteristics of funds as corporations have
learned how to use such instruments to manage all kinds of risks. Examples of the characteristics are determination of interest amount, interest payment schedules, exposure to
market movements and currency conversion. It is therefore possible to customise a
transaction by pipe-lining several financial instruments. The result, also called a synthetic instrument, is then sold as a package.
Each instrument and its associated practices of trade can be considered as defining one
financial market. However, for a market to work efficiently, some system for price indication is needed. Active participants (especially traders) are the main source for this
information. In the markets with high turnover volumes the prices at which deals are
concluded are continuously published on electronic networks. We will refer to instruments for which the current price level is publicly known as standard instruments.
The price of a standard instrument is almost exclusively determined by supply and demand. But if a new instrument is engineered, how does one find its proper price? A
widely accepted approach is to use the prices quoted in high volume financial markets
for the derivation of a discount function. The higher the volume traded the more reliable
is the price indication.
A discount function is used to assign to any cash flow in the future an equivalent value
today. This is based on the observable fact that a Dollar received today is worth more
than a Dollar received some time in the future; this is also known as the time value of
money. Deriving a discount function effectively means expressing the time value of
money in a market independent form. The present value, and hence the price, of an instrument is found by discounting all its associated (future) cash flows.
Valuation not only makes sense in the context of a single instrument. In effect, small
and large collections of deals stemming from various instruments1 are managed and
evaluated on a portfolio basis. This is especially true for investment banks and broker
houses that actively trade in these instruments. Exposure to market movements (price
risk) and performance is measured with respect to an entire portfolio rather than on individual deals.
The rest of the paper is organised as follows: In section 2 we give an introduction to the
swaps business and shed some light on the current situation concerning software support. In section 3 we go into the details of a calculation framework for financial instruments. In section 4 we summarise our experiences of the development and usage of the
framework.
Swaps
Of the kaleidoscopic palette of todays financial instruments we will for the purpose of
this paper only consider one genre of financial instruments, so-called swaps.
2.1
Swaps are a fairly recent development. The most common of these structures is the interest rate swap where two parties agree to exchange, or swap, two sets of interest
payments which are determined by two different interest rates [Kap90]. Hence there are
two sides, or legs, to a swap. Typically, one of the interest rates is fixed at a certain percentage of some principal amount and the other is floating, i.e., pegged to some changing market index. Fig. 1 shows a situation where borrowers B and D engage in an interest rate swap. The rationale for doing this is that B can raise funds on floating rate terms
comparatively cheaper than D can. Although B supposedly prefers to engage in a fixed
rate liability it is still profitable to take on a floating rate debt and then swap it with D
who has opposite preferences.
Lenders
fixed
rate
floating
rate
fixed rate
Borrowers
floating rate
Fig. 1: Flow of interest payments when two borrowers swap their obligations
through an interest rate swap
The other frequently met construction is the currency swap in which the flow of interest
payments is identical to the interest rate swap but with the difference that the two sets
of cash flows are denominated in different currencies.
At conclusion of a swap, the two sides must have equal value under the then prevailing
market conditions. This possibly calls for a compensation payment by one of the counterparties. The value of one swap side is determined by present valuing each cash flow
according to an appropriate discount function.
In trading situations it is not the present value of the two sides that is of most relevance
to the trader or the customer. It is either the interest rate of the fixed side or the spread
in excess to the floating side that are then referred to as the price of the swap (We will
use price and rate interchangeably).
As market conditions (interest rates, exchange rates) change, the two sides of a swap
perform differently and will eventually be misbalanced. Managing these misbalances on
a portfolio basis is of paramount importance to the swaps trader.
2.2 Current Situation
The correct valuation of financial instruments in a trading situation depends on the
availability of adequate software tools. Adequacy is needed with respect to both the
user interface and the calculation support.
Innovation driven by competition among suppliers of financial instruments requires that
software tools must constantly be extended to include calculation support for new financial products.
However, current approaches to the development of software tools in financial engineering are not satisfactory. Software tools are either built on top of a spreadsheet program or as a separate application. Both approaches have a number of deficiencies.
While spreadsheets allow for fast development of new tools they are often too slow for
extensive calculations and almost impossible to maintain once the computational models become more complex. The user interface typically is very rudimentary and performs poorly under trading conditions.
Development of standalone applications is very costly and time consuming. Therefore
developers often resort to quick and dirty implementation techniques in order to meet
time constraints dictated by the fast moving markets. These time constraints have also
led to minimalistic, menu driven, user interfaces.
A very crucial shortcoming of both approaches is that similar functionality is re-engineered for every new tool.
2.3
Almost each instrument has its own trading practice and jargon. However, when looking at the instruments and the valuation procedures on a more abstract level one can
find many commonalties and interrelationships among them. Most notably:
Each deal consists of a set of actual or potential cash flows.
A cash flow has an associated business day on which it is realised.
The value of any instrument is sensitive to changes in interest rates. Therefore the
quantification and monitoring of the interest rate sensitivity is applicable to any instrument.
Arbitrage between different markets tends towards consistent time value of
money-profiles across markets which allows the valuation of one instrument in
terms of the price structure of other instruments.
Instruments can easily be expressed in terms of each other when adopting a LEGO
(or building blocks) approach in trying to understand financial instruments [Smi87].
These observations led us to the conviction that the domain of financial instruments is
ideally suited for the employment of a framework approach.
However, a framework can not be designed from scratch on paper. Rather, experience
suggests that it must grow bottom-up and successively mature by applying it to different problem (sub-)domains. Therefore, with the notion of a general framework for financial engineering in mind we set out with our first development in the domain of
swaps trading.
Fig. 2 shows a pilot application that was the result of a series of prototypes implemented in collaboration with trading specialists. The purpose of this endeavour was to
acquire initial domain know-how and experiment with various user interfaces.
The upper right window shows a domain specific desktop on which domain items are
depicted as icons. Relationships among the items may be edited through drag-and-drop
type manipulations on the icons. The bottom left window shows an editor in which data
can be modified directly via its graphical depiction by directly dragging a part of the
curve.
The following section describes the framework as it is being used in the context of a
swaps trading software.
Fig. 3 shows the structure of the framework and the most important objects. We will
show the key abstractions in more detail, and then we will describe two scenarios which
demonstrate their use.
Instrument
cfgenerator
pricer
Pricer
paymentdates
DateInterval
currency
Currency
calendar
Calendar
yieldcurve
Instrument Block
CashFlowGenerator
DFManager
rates
strategies
Rate 1
CalcStrategy 1
Rate n
CalcStrategy n
inherits
references
SwapLeg
3.1
3.1.1
Instrument
An instrument represents any traded facility for generating cash flows in todays financial markets.
Instrument
generate cash flows
calculate the present value
calculate the price
construct the payment dates
construct generator
- CFGenerator
- Pricer
- DFManager
- Calendar
- DateInterval
- Instrument
- DFManager
- Currency
- Calendar
- Accrualbasis
- DateInterval
Pricer
calculate the price
calculate the present value
- Instrument
- DFManager
- Currency
- Calendar
- Accrualbasis
Instrument
cfgenerator
SwapSide
DoMakeGenerator
DoMakePricer
pricer
FixedLegCFGenerator
FixedLegPricer
Instrument
SwapSide
Future
FRA
CompositeInstrument
SwapTransaction
Portfolio
3.1.2
10
Discount function
- Rate
- CalcStrategy
- DFCalculator
- InstrumentType
Discount
Factor
Rates
We calculate a discount factor for a given standard instrument by the method of zerocoupon pricing. For different kinds of standard instruments we use different formulas.
1.0
0.0
Money
Market
Future
Market
Swap
Market
11
DFManager
rates
strategies
Rate 1
CalcStrategy 1
Rate n
CalcStrategy n
Yield at i
DF at i
Rate at i
aStrategy
DiscountFactor
DerivativeSensitivity
CalcStrategy
MoneyMarketStrategy
FutureStrategy
SwapMarketStrategy
Fig. 12: The interface of the class CalcStrategy and its sublcasses
Based on the above factorisations, the structure of the calculation context may be set-up
at will. The DFManager inspects its structure when it has to calculate something for
the first time and installs the needed strategies (through factory methods).
Consider a trader doing business in Swiss Franc Interest Rate Swaps. In these markets
there exist several kinds of instruments which influence trading decisions. To achieve a
better overview of the current market situation, several DFManagers can be in use at
the same time. They differ in the mix of included prices. In this way we support the
trader in integrating simultaneously accessible market information and arriving at a
more accurate decision.
3.2
Scenarios
To illustrate the use of the classes, we present two scenarios which show the interac tion
among the actual objects involved.
3.2.1
In the first scenario a pricer object starts a request for a discount factor at a date
where a rate is defined, to calculate the present value of a cash flow (cf. Fig. 3).
12
What is the advantage of doing it this way? A DFManager relies only on the interface
of the collaborator objects. It just uses the responsibilities defined in their abstract base
class and manages them. We achieved a strong separation between structure information (R a t e), selector knowledge (DFManager) and procedural knowledge
(Strategy). To identify such a collaboration scheme we again use a design pattern,
the manager pattern.
To support a new kind of rate, we implement the corresponding formula in a strategy
subclass and define the new rate. So we end up implementing one new subclass with
essentially one formula and possibly a caching algorithm.
3.2.2
The second scenario shows how cash flow generation works in an instrument. We describe a fixed swap leg which is fairly easy to understand without further knowledge in
financial engineering.
A fixed swap leg is defined by several parameters, the most important being principal,
fixed rate, and accrual basis:
Principal denotes an amount of money which is the base for cash flow generation.
Fixed rate is the interest rate used on the principal to calculate the amount paid in
regular intervals.
Accrual basis is the definition of the amount of days per year for which interest accrues.
These definitions are specific to one instrument, a fixed swap leg. To process the information correctly, a generator knows about the parameters supplied by its instrument.
So a fixed leg generator accesses the information of a fixed swap leg by the specific
swap leg interface.
Information that is common to more than one class is used through the interface of the
abstract base class. The aim is to always use the most abstract interface possible.
In the scenario the swap leg collaborates with its generator to produce the cash flows.
The generator obtains the necessary parameters from its instrument, in this case the
fixed swap leg. The following shows a generic algorithm which implements the formula found in many swaps handbooks.
13
In the above code sample we use several parameter objects whose purpose we list
briefly:
AccrualBasis is an object encapsulating the convention on how to calculate interest accrual periods.
To iterate over the payment periods, the generator uses Interval. This object generates in the loop all the dates necessary for the calculation. In each iteration one cash
flow object is generated to store the information. The generator adds these to the list
and returns the list to the instrument.
Evaluation
This example shows us not only the de-coupling of what and how, but also the co-operation of smaller abstractions. The Interval is defined by one object and used by
another. The objects are solely connected by the interval object and its respective protocol. This is used in the swaps leg, for example, where one object knows how to specify
the temporal structure, and the other needs to know the actual dates for the calculation.
The AccrualBasis calculates accrual factors with the accrual basis given by the
swap leg.
To transfer cash flows as parameters we introduce a class CashFlow which stores all
relevant data for later use.
Thus we achieved effective de-coupling by introducing fine grained abstractions that
only define responsibilities. There are many different specific implementations which
are all used homogeneously.
Experience
Our experience from developing the ET++SwapsManager and from earlier projects is
that building, or better growing, a framework is hard work. It takes recurrent, conscious
efforts to review a working design and improve it.
14
Typically, in developing a software system, functionality is added and tested incrementally. As a consequence the functionality of the system grows without much concern for
the overall design. But, to really advance the design it has to be reworked periodically.
Thus it is possible that, while preserving the monotonically increased functionality, the
system decreases significantly in size, due to consolidation efforts.
Development of a framework starts with the implementation of a specific solution in a
particular domain. Then the solution is successively reworked to cover a family of applications. For this process of generalising a design we found a few rules of thumb
which were helpful in our project:
Try to consolidate similar functionality found in different parts of the system and
implement it through a common abstraction.
Split up a large abstraction into several smaller abstractions such that a team of collaborating objects results. Each of these smaller abstractions then implements only a
small set of responsibilities. A good example of this is separating pricing and cash
flow generation from the instrument abstraction as described in section 3.1.1.
Objectify abstractions that differ; implementing each variation of an abstraction as
an object increases the flexibility of a design.
Use composition instead of inheritance where possible. This reduces the number of
classes in a system. Additionally, it relieves the (re-)user of the framework from
having to deal with the inner workings of participating classes.
Especially the last rule seems crucial in the development of a highly flexible framework. The novice often tries to find class hierarchies in the problem domain and structures the needed responsibilities and code accordingly. The call for multiple inheritance
is then merely a consequence when one is confronted with implementing an abstraction
that is really a combination of already available sets of responsibilities. Structuring
functionality along inheritance hierarchies, however, leads to static configurations.
Frameworks draw their superiority from well designed collaborations among teams of
objects.
Acknowledgements
We would like to thank Erich Gamma and Andr Weinand for their constructive comments on drafts of this paper and encouragement for redesigning it. We also thank
Federico Degen and Jrg Gasser for their support on the financial engineering side of
the project.
15
References
[Beck89] K. Beck, W. Cunningham, A Laboratory For Teaching Object-Oriented
Thinking, In OOPSLA89 Conference Proceedings (October 1-6, New
Orleans, Louisiana), published as, OOPSLA89, ACM SIGPLAN Notices
Notices, Vol. 24, No. 10, November 1989, pp. 1-6.
[Bro87]
[Egg92]
[Gam92]
[Gam93]
[Joh88]
[Kap90]
K.R. Kapner and J.F.Marshall, The Swaps Handbook - Swaps and Related
Risk Management Instruments, Institute of Finance, New York, 1990.
[Mir91]
[Smi87]
[Wei89]