Model Driven Architecture in Financial Engineering by liaoqinmei


									       Model-Driven Architecture in Financial Engineering
                        Stefan Dirnstorfer                Andreas J. Grau
                     Munich Technical University       Munich Technical University
                          Theta Engineering                Theta Engineering
                              Germany                           Germany

        The current practice in financial engineering, especially in computational finance can profit
     from the Model-Driven Architecture approach known from software engineering. Many of the
     current problems in the practical implementation of financial models can be overcome by a
     domain specific language for finance. This paper proposes ThetaML as such a language and
     presents examples for its abilities.

1    Financial modeling
Current discussions about financial modeling are mostly dominated by stochastic models for mar-
kets and processes. Prevailing mathematical tools of stochastic analysis are sufficiently advanced
to model what we call the stochastic model. A much neglected but still highly relevant part of
financial modeling is the structural model. The exact details of a complex financial product or a
complex trading strategy are hard to express mathematically. The scientific challenge of modeling
the structural model lies somewhere in between mathematics and computer science and is mostly
neglected by both.
One of the biggest modeling tasks faced by today’s financial industry is presented by an inflation of
new terminology describing innovative financial derivatives. Many expressions used by quantitative
analysts are ambiguous and cause a significant friction in communication. It is hard to locate the
difficulty in financial modeling. Payments or delivery of certain amounts are normally well known
about. Sales people do have a clear idea of all the structural features of their traded products.
But still they will not be able to quickly specify all of them in a precise manner.
As financial models, or in particular their structural part, grow above the complexity that is
representable in a mathematical formula they tend to become difficult to maintain and to document
precisely. Important details can often be found implicitly in the programming source code or in
the legal documents arranged with the customer. It should be clear, that the original goal of a
financial model is to point to a unique mathematical problem, for which solutions can be found
numerically or algebraically.
Currently there is no satisfactory standard for specifying the structural model. Therefore this
document introduces a definition language that allows the specification of securities and strategies
in a way that is intuitive and precise. The suggested language provides access to conditional
statistical properties and some aspects of the sigma algebra, while still remaining simple and
Some approaches have previously been suggested for the purpose of documenting and automated
processing of financial products. One such approach is the industry standard FpML. This is
an XML dialect that allows the specification of a wide range of securities. It is designed as an
exchange data format for the specification of traded securities [fpm04]. It is not suitable for the
description of new products or the automated derivation of algorithms, since it does not cover

the internal structure of a security. Various kinds of derivatives are just distinguished by different
names, rather than describing their internal features.
Other approaches claim to be more generic, but little information is publicly available, since they
are marketed as proprietary software products. SciComp came up with a programming language
that is encouraged by the mathematical notation of partial differential equations [KR01]. Thus,
it is mostly targeted at the defining of pricing problems and hardly serves as a human readable
documentation tool. Lexifi created a specification language for derivatives, which originates form a
functional programming style language [JES00]. Individual language features are not very generic
and limited in scope.

2    Model Driven Architecture
The problems arising from a model’s complexity are not specific to the world of finance. In fact it
is a well documented problem for which a standard approach was suggested by software engineers.
In this section, we will take a brief look at Model Driven Architecture (MDA) and transfer it
to the domain of financial engineering. MDA is an approach for the development of software
systems which separates the structure from the implementation [Fra03]. Its declared goal is the
semi automatic code generation from a precise model. MDA is similar to the Computer Aided
Software Engineering (CASE) approach, which tries to fully automate the generation of software
out of a domain specific model, including the software design. In contrast to CASE, MDA leaves
software design to the user and emphasizes the ability to adapt the model implementation to
different environments.
Model Driven Architecture supports rapid prototyping and automated code generation from a
structural model. The numeric algorithms can be directly generated from the model specification in
the domain language. Following this approach convergent numerical algorithms can be generated,
which are already useful in daily business. In some cases the generated code does not meet the
requirements on functionality or performance. But, the model based design can still accelerate
the development process of a numerical evaluator by providing a reference implementation which
can be improved manually.
An important observation is that if a financial modeling language is readable alike by traders,
quantitative analysts and programmers, it can simplify interdisciplinary communication. This can
only be attained using a simple terminology which represents the complex features of a financial
model precisely. Instead of naming each feature of a model by a new term, a description that
captures the properties of the feature is more understandable. That means that not only the
software development process benefits from a language for the finance domain, but also other
processes derivatives trading.
A Model Driven Architecture approach to finance provides major improvements for financial mod-
eling. Given that the specification can be turned into a numeric algorithm automatically, it pro-
vides early feedback to a financial engineer such that design flaws are detected during the modeling
process. Finally, the automatic generation of numerical procedures reduces redundancy in the im-
plementation and improves consistency. We want to show how to apply this technique to optimally
meet the requirements and the scope of the problem domain.

3    ThetaML
Obviously, Model Driven Architecture is not the solution it self, it only forms a powerful tool if
the domain model is set up wisely. We suggest ThetaML as a domain model that is suitable to
cover the features of a financial investment in an intuitive and mathematically precise way. For
this purpose this section introduces the building blocks which can be combined to a structural
model and their mathematical interpretation. For the building blocks we follow a chronological
description similar to that of a flow chart. For the mathematical interpretation we use an operator
calculus that is suitable to capture the details of a financial investment.

Before we go into the details of the graphical modeling let us first introduce a crucial mathematical
operator that helps us defining the elementary building blocks. The operator           can be used to
define the assignment of a value to variables [Dir04]. Most programming languages know this
operation as the assignment of a variables, but this concept not otherwise expressible in maths,
where the values of variables can not be changed.
We use the symbol       to denote the value assignment operator. Above the operators we place
the variable to which a new value should be assigned. Below we write the new value. The whole
operator with its two arguments atop and below is applied to a formula, which we want to evaluate
with the newly assigned parameters.
                                               f (x) := f y(x)                                   (1)

Prevailing mathematical notation knows this operation as the bar operator. Its symbol is a vertical
line with the value assignment in the lines index position. Other than all other mathematical
operators, the bar operator is applied from the right hand side, which makes it difficult to integrate
in larger formulas.
                                                  f =f       x=y(x)

3.1    Flow of operations
The structural model of a financial investment is specified through a sequence of elementary events
or actions. The graphical model initializes such a sequence with a small black circle. Starting
from that circle a sequence of additional operations O1 to On is connected in chronological order.
There is no physical time passing in between these operations. All of them happen within an
indefinitely short time.

This sequence has a direct correspondence to a sequence of operators. The initial operator repre-
sented by the black circle is mathematically translated to an initialization of a variable state Xt .
We consider Xt to be state of market parameters at time t. Thus, the corresponding operator
sequence is:
                                                      O1 O2 O3                                   (3)

3.2    Theta flows
Theta flows are represented by bold connections between two operations. They indicate physical
time to pass. The label next to the bold connection line indicates the time that passes or the date
at which the next operation is about to happen.

Theta flows are expressed by the Θ operator. Considering X to be a stochastic Markov process,
with Xt its value at time t and each value depending on a random seed ω. We can define Θ∆t as
the operator that moves forward the state by time ∆t.
                                               Θ∆t =                                             (4)

Another possible definition of Θ was suggested as the expected value of this definitions right hand
side [Dir04]. That would confine access to future variable values to their expected value. Moreover
the measure of that expected value is also set by the Θ operator.

3.3    Assignment
Assignments change the value of variables. However, unlike other programming paradigms the
assigned value is not only accessible after the assignment. By writing a plus sign in the index we
indicate, that the next assigned value of that variable is accessed. The future value accessed in that
way might not be fully measurable with information at that time. Hence, statistical expressions
can be computed, such as the expected value or the correlation between stochastic variables (beta).
These values are always conditional on knowledge at that time. As ThetaML charts describe the
behavior of a trader following a specified strategy or investment, in is possible that payments or
exercising conditions depend on what can be expected according to a given model. An option can
be exercised according to whatever choice has the higher expected pay off. Such a condition can
only be expressed with access to future variables.
The following simple examples shows a variable A being assigned a future value of S. The first
assignment operator assigns the future value of B to A. The dotted stroke may indicate any
arbitrary operations, after which B is set to the value of S at that future time.

The value of variables resulting from a sequence of operators can be accessed by applying the oper-
ator sequence to the variable in question. · · · S B simplifies to · · · S, with the dots indicating any
operator sequence. The whole graphical notation from above is now turned into a mathematical
                                                  A           B
                                                        ···                                        (5)
                                                 ···S         S

3.4    Flow control
Loops can be used for repeated operations. The loop is graphically represented by a small circle
containing the time spent in the loop. The maximum length of a loop should always be made
explicit. Conditional branches are indicated as in flow charts by the rhombus containing the
branch condition.

The operator expression for the loop with dt time step is to be represented as a limit of dt to zero
and the actual number of loop cycles to infinity. The conditional branch can be expressed as a
piecewise defined function with the two choices evaluating two different operators O1 and O2 .

                                                 T                     b
                                          a      dt                 a>     O1
                            lim   Θdt                         and                                  (6)
                           dt→0         a+S dt                             O2

The call operator is represented by a rounded rectangle. The call operator contains the name of
the model to call, the variables to pass to and the variables to retrieve from the submodel. For
every variable that is undefined in the submodel a local variable can be exported, as indicated

by the arrow pointing to the left. In case local and external variable have the same name it is
sufficient to state the variable with a right pointing arrow. Imported variables are indicated by a
left pointing arrow. Any variable computed by the called function can be retrieved and optionally
renamed into the local variable space.

4    Fixed income
One aspect in financial modeling is the problem of discounting future cash values. Any sufficiently
general definition of financial investments must specify discounting instructions clearly. For that
purpose we introduced a currency numeraire. Any cash value that is received at any time must be
multiplied with its discounting process. If for example a transaction involves the value of 100$, we
can treat the unit symbol as the discounting process and include it in the formula. The unit symbol
must not be confused with a physical unit, since it can be resolved to a numeric discount factor.
Different symbols refer to different discount factors. Thus all cash values are always discounted
present values. This has further consequences to be discussed later.
For now we look at a simple stochastic model for the e process. This process describes the value of
one euro coin, measured in todays present value. With the money market account as the numeraire
it means a permanent loss to hold one euro cash.

Zero bond A zero bond is modeled in two steps. After the initialization the zero bond product
stays inactive for the maturity time T . At maturity, the bond V is then assigned a value of 100e.
The currency unit indicates that this value is to be discounted, for the purpose of pricing.

Although this is just the most primitive bond type that one can imagine, we think it is almost
trivial to add additional features such as coupons and exercising conditions. Once, the analogy
between security feature and programming is established there are no further obstacles to the
specification of any of the currently traded security types.

Risk neutral price Having our previous model for our bond value V we can introduce a new
variable P that describes the bond’s price at any time of the process. We assume the Q is the
pricing measure and EQ computes the price at which the value in variable V can be bought. Based
on this price P we could introduce additional features of a derivative or a strategy based on bond
prices. Computing the expected value

To illustrate to procedure of pricing we will do some evaluation of that model. Although the
pricing of derivatives is not in the focus of this document, a small example may be helpful for

the understanding of the modeling technique itself. For the purpose of simplicity we chose a
deterministic process for the discounting process e.

                                  Θ=            and         e0 = 1                             (7)
                                       e−r e

The price P can be computed as the expected value of V+ which in turn is the operator sequence
applied to V . according to the definition of everything resolves into a deterministic value for
the bond price.

                                                 e         V
                                   P   = EQ          ΘT          V                             (8)
                                                 1        100e

                                       = EQ          ΘT 100e

                                       = EQ          100e−rT e

                                       = 100e   −rT

More complicated securities can be resolved accordingly [Dir04]. Important for the moment is
however the fact, that the notation of ThetaML does actually lead to a computable formula and
does easily express currently traded securities.

A price process This simple model creates a time series of bond prices, whereas the price P
converges to exactly 100 at maturity time. After the start, there are two connections indicating
parallel execution of both branches. One branch calls the bond model, the other computes the
series of non discounted prices. As indicated before we suggest for the definition of securities to
express all financial values in terms of present values. Sometimes, however, securities depend on
the denoted value of a product. For that purpose we can divide the value of the bond by the unit
value of the currency it denotes in. All value that are not meant to be discounted must be divided
accordingly, to reverse the discounting effect.

5    Numerical examples
The ThetaML language is independent of its algorithmic implementation. Whether an evaluation
uses Monte-Carlo, PDE methods or even computer algebra does not affect the structural model.
The presented examples have been computed with a an implementation which is similar to the
Least-Square Monte Carlo Method [Car96, LS01]. This method is an extremely efficient alternative
to nested simulation.

Structural model and stochastic model The structure model captures the details of a finan-
cial model which graphically defines the interdependencies of parameters and stochastic variables.
A stochastic model is required to supplement a structural model, whenever the latter references
stochastic variables. It is defined in the notation of stochastic differential equations, which has
proved to be useful and is widely used in the literature.
The following stochastic model is used to evaluate the three examples below. The variable S is
the process for the discounted value of a stock with volatility 40%. The numeraire e models the
discount factor. The process variables are propagated whenever the Θ operation is applied, as
represented by a bold line with a time span written next to it.
                                   dS   = 0.4dW           S0 = 100
                                  de    = −0.05dt           e0 = 1.
The use of a currency symbol allows the direct notation of cash amounts together with the appro-
priate discount curve. In larger models multiple currencies might occur. Since ThetaML is not
designed for the representation of stochastic processes, the implementation of the stochastic model
is conducted in a more suitable language (Matlab/Octave). This approach allows the utilization
of existing code, which is in line with the Model Driven Architecture process.

Example: Option The first example of a ThetaML model shows its similarity to a flow chart.
Here, the flow describes a chronological sequence. The small circle on the left indicates the start.
The thick connection indicates a time span of T , after which the option can be exercised with a
strike price of K denoting in e. The plot shows the result for value V given our stochastic model
and strike price K = 100.

                                                             Histogram of 10000 Simulations



                                                               -80                             -60      -40      -20         0
                                                                                                Option Price (P)

Example: Risk neutral pricing The next model describes a process for an option price. After
initialization two connections leave the start point. The rounded rectangle calls our previous model
and imports the value V . The section branch enters a loop in which the conditional expected value
of V is repeatedly evaluated. The expected option value divided by the value of 1e gives us its
price in units of our chosen currency.

                                                               Option price process (P)

                                                                                           0     0.2     0.4     0.6   0.8

Example: Simulated Hedging Instead of pricing the option as an expected value we also
replicate it in a dynamic portfolio, a method which works also in incomplete markets with a
real-world measure and without risk neutral probabilities [Gra06].

Π is the value of the replicating portfolio, B the number of bonds, δ the number of stocks. Reading
the chart in backward order we start to initialize the final state to have zero stocks and exactly the
number of bonds that pay the option, specified previously. Moving backwards in time, we compute
the number of previously held stocks from the beta factor (correlation) between the underlying
and the portfolio and stock. The bond amount is updated such that the difference of held stocks
δ+ − δ can be financed. Repeating that loop over a maturity of T the present value of the hedging
costs will be computed as a random variable.
With a hedging interval of dt = 1/250 the following plot shows that hedging costs have low variance
initially and diverge in accordance to the change of the option price. The algorithm also works in
incomplete markets and leads to a variance minimal hedging strategy.

                                                                            10                                 Max

                                                                             0                                 97.5%

                                                          Portfolio (Pi)
                                                                           -30                                 50.0%

                                                                           -40                                 25.0%
                                                                                 0   0.2   0.4 0.6   0.8   1

6    Conclusion
The huge amount of different derivative types that emerge on the market with a rapid pace do
cause large frictions in communication and implementation. This paper introduced a modeling
technique that could allow the idea of Model Driven Architecture to be used in the area of financial
modeling. The effort spent on the implementation of an appropriate computational infrastruc-
ture could be significantly reduced. The suggested domain-specific language ThetaML is easy
to understand, since it relies on a relatively small basic vocabulary to express derivative types.
Moreover, ThetaML is sufficiently precise to allow automated processing and code generation.
The expressiveness of ThetaML is not limited to derivatives. As we have seen non trivial hedging
strategies can be written in a compact manner. Further applications include risk management,
firm modeling, portfolio analysis and dynamic investment strategies. The crucial simplifications
over alternative approaches are the strictly chronological order of investment features, the acces-
sibility of variables defined later in the flow and the identification of the discount process with a
currency unit. We expect appropriate software for code generation and common data standards
to emerge in the near future.

[Car96] J. F. Carriere. Valuation of the early-exercise price for options using simulations and
        nonparametric regression. Insurance: Mathematics and Economics, 19:19–30, 1996.
[Dir04] S. Dirnstorfer. On the representation of trading strategies and financial portfolios. In
        intelligent finance, ISBN 187685118X, pages 131–143, 2004.
[fpm04] Fpml 4.0 specification. Technical report,, 2004.
[Fra03] D. S. Frankel. Model Driven Architecture. Applying MDA to Enterprise Computing. John
        Wiley & Sons, 2003.
[Gra06] A. J. Grau. A monte carlo method for option pricing in the real world. working paper
        (, 2006.

[JES00] Simon Peyton Jones, Jean-Marc Eber, and Julian Seward. Composing contracts: an
        adventure in financial engineering, 2000.
[KR01] Elaine Kant and Curt Randall. System and Method for Financial instrument medelling
       and using Monte Carlo Simulation. jan 2001. US 6772136.
[LS01]   F. A. Longstaff and E. S. Schwartz. Valuing American options by simulation - a simple
         least-squares approach. The Review of Financial Studies, 14(1):113–147, 2001.


To top