VIEWS: 4 PAGES: 9 POSTED ON: 9/23/2011 Public Domain
Model-Driven Architecture in Financial Engineering Stefan Dirnstorfer Andreas J. Grau Munich Technical University Munich Technical University Theta Engineering Theta Engineering Germany Germany stefan@thetae.com andreas@thetae.com Abstract The current practice in ﬁnancial engineering, especially in computational ﬁnance can proﬁt from the Model-Driven Architecture approach known from software engineering. Many of the current problems in the practical implementation of ﬁnancial models can be overcome by a domain speciﬁc language for ﬁnance. This paper proposes ThetaML as such a language and presents examples for its abilities. 1 Financial modeling Current discussions about ﬁnancial modeling are mostly dominated by stochastic models for mar- kets and processes. Prevailing mathematical tools of stochastic analysis are suﬃciently advanced to model what we call the stochastic model. A much neglected but still highly relevant part of ﬁnancial modeling is the structural model. The exact details of a complex ﬁnancial product or a complex trading strategy are hard to express mathematically. The scientiﬁc 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 ﬁnancial industry is presented by an inﬂation of new terminology describing innovative ﬁnancial derivatives. Many expressions used by quantitative analysts are ambiguous and cause a signiﬁcant friction in communication. It is hard to locate the diﬃculty in ﬁnancial 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 ﬁnancial models, or in particular their structural part, grow above the complexity that is representable in a mathematical formula they tend to become diﬃcult 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 ﬁnancial 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 deﬁnition language that allows the speciﬁcation 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 computable. Some approaches have previously been suggested for the purpose of documenting and automated processing of ﬁnancial products. One such approach is the industry standard FpML. This is an XML dialect that allows the speciﬁcation of a wide range of securities. It is designed as an exchange data format for the speciﬁcation 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 1 the internal structure of a security. Various kinds of derivatives are just distinguished by diﬀerent 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 diﬀerential equations [KR01]. Thus, it is mostly targeted at the deﬁning of pricing problems and hardly serves as a human readable documentation tool. Lexiﬁ created a speciﬁcation 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 speciﬁc to the world of ﬁnance. 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 ﬁnancial 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 speciﬁc 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 diﬀerent 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 speciﬁcation 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 ﬁnancial 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 ﬁnancial 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 beneﬁts from a language for the ﬁnance domain, but also other processes derivatives trading. A Model Driven Architecture approach to ﬁnance provides major improvements for ﬁnancial mod- eling. Given that the speciﬁcation can be turned into a numeric algorithm automatically, it pro- vides early feedback to a ﬁnancial engineer such that design ﬂaws 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 ﬁnancial 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 ﬂow chart. For the mathematical interpretation we use an operator calculus that is suitable to capture the details of a ﬁnancial investment. 2 Before we go into the details of the graphical modeling let us ﬁrst introduce a crucial mathematical operator that helps us deﬁning the elementary building blocks. The operator can be used to deﬁne 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. x f (x) := f y(x) (1) y(x) 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 diﬃcult to integrate in larger formulas. x f =f x=y(x) (2) y(x) 3.1 Flow of operations The structural model of a ﬁnancial investment is speciﬁed 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 indeﬁnitely 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: Xt O1 O2 O3 (3) X0 3.2 Theta ﬂows Theta ﬂows 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 ﬂows 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 deﬁne Θ∆t as the operator that moves forward the state by time ∆t. Xt Θ∆t = (4) Xt+∆t Another possible deﬁnition of Θ was suggested as the expected value of this deﬁnitions right hand side [Dir04]. That would conﬁne access to future variable values to their expected value. Moreover the measure of that expected value is also set by the Θ operator. 3 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 speciﬁed 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 oﬀ. 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 ﬁrst 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- B ator sequence to the variable in question. · · · S B simpliﬁes to · · · S, with the dots indicating any operator sequence. The whole graphical notation from above is now turned into a mathematical formula. 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 ﬂow 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 inﬁnity. The conditional branch can be expressed as a piecewise deﬁned function with the two choices evaluating two diﬀerent 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 undeﬁned in the submodel a local variable can be exported, as indicated 4 by the arrow pointing to the left. In case local and external variable have the same name it is suﬃcient 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 ﬁnancial modeling is the problem of discounting future cash values. Any suﬃciently general deﬁnition of ﬁnancial 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. Diﬀerent symbols refer to diﬀerent 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 speciﬁcation 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 5 the understanding of the modeling technique itself. For the purpose of simplicity we chose a deterministic process for the discounting process e. 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 deﬁnition of everything resolves into a deterministic value for the bond price. e V P = EQ ΘT V (8) 1 100e e = EQ ΘT 100e 1 e = EQ 100e−rT e 1 = 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 deﬁnition of securities to express all ﬁnancial 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 eﬀect. 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 aﬀect 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 eﬃcient alternative to nested simulation. 6 Structural model and stochastic model The structure model captures the details of a ﬁnan- cial model which graphically deﬁnes 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 deﬁned in the notation of stochastic diﬀerential 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 ﬁrst example of a ThetaML model shows its similarity to a ﬂow chart. Here, the ﬂow 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. 1500 Histogram of 10000 Simulations 9065 1000 500 0 -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. 60 Option price process (P) 50 40 30 20 10 0 0 0.2 0.4 0.6 0.8 time 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]. 7 Π 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 ﬁnal state to have zero stocks and exactly the number of bonds that pay the option, speciﬁed 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 diﬀerence of held stocks δ+ − δ can be ﬁnanced. 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% -10 75.0% -20 Portfolio (Pi) -30 50.0% -40 25.0% -50 2.5% -60 Min -70 -80 0 0.2 0.4 0.6 0.8 1 time 6 Conclusion The huge amount of diﬀerent 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 ﬁnancial modeling. The eﬀort spent on the implementation of an appropriate computational infrastruc- ture could be signiﬁcantly reduced. The suggested domain-speciﬁc language ThetaML is easy to understand, since it relies on a relatively small basic vocabulary to express derivative types. Moreover, ThetaML is suﬃciently 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, ﬁrm modeling, portfolio analysis and dynamic investment strategies. The crucial simpliﬁcations over alternative approaches are the strictly chronological order of investment features, the acces- sibility of variables deﬁned later in the ﬂow and the identiﬁcation 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. References [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 ﬁnancial portfolios. In intelligent ﬁnance, ISBN 187685118X, pages 131–143, 2004. [fpm04] Fpml 4.0 speciﬁcation. Technical report, www.fpml.com, 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 (grau@ma.tum.de), 2006. 8 [JES00] Simon Peyton Jones, Jean-Marc Eber, and Julian Seward. Composing contracts: an adventure in ﬁnancial 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. Longstaﬀ and E. S. Schwartz. Valuing American options by simulation - a simple least-squares approach. The Review of Financial Studies, 14(1):113–147, 2001. 9