#
Optimizing Financial Modeling with *Mathematica*

February 16, 2011 — Michael Kelly, Senior Wolfram Technology Consultant, Wolfram Technology Group

On January 25 and 27 in Chicago and New York, respectively, Wolfram, in conjunction with NVIDIA, hosted a seminar themed “Optimizing Financial Modeling” to showcase how *Mathematica* and CUDA can be applied within the financial industry. Full presentations and a white paper on CUDA programming with *Mathematica* are available for download on the seminar page.

Dr. Phillip Zecher, Chief Risk Officer of EQA Partners, detailed how *Mathematica* is used in every facet of his firm’s operation, and NVIDIA’s Senior CUDA Consultant John Ashley explained how CUDA programming is changing financial computation.

My talk concerned *Mathematica* 8′s broad functionality for finance. Each capability is deserving of a full seminar unto itself, so because of the sheer number of topics and functions, I was only able to briefly touch on a few examples from each category. A full list of financial tools in *Mathematica* is available in the online documentation. The following `TabView` presents an overview of the new financial functions:

At first glance, it may seem that such an array of functions might be hard to digest, but they all come with *Mathematica*’s patented structure of `FunctionName`[arguments], where the `FunctionName` is exactly what it is called by the financial community. This makes absorbing and manipulating these new functions far more manageable than the usual array of acronyms encountered in other programs. For example, the function `TimeValue` accepts any type of financial instrument, such as annuities and cash flows, and we can replace the nominal interest rate with an effective interest rate with different periods of compounding:

We can use another `TabView` to provide a succession of examples of the functions `TimeValue`, `Annuity`, and `Cashflow` in conjunction with `Solve` and `Expectation` that makes their combined use transparent:

The evaluation of bonds also have consistent structure given by `FinancialBond[{"FaceValue"->FV,"Coupon"->Crate,"Maturity"->M, "CouponInterval"->CI,"RedemptionValue"->RV}, {"InterestRate"->IR,"Settlement"->S,"DayCountBasis"->DCB}]` so that it is easy to construct the following applet for pricing a bond and its various properties with varying yield curve and input parameters:

In the same way, financial derivatives also accept a well-defined structure of parameters and ambient parameters that fully describe the dependence of the option on its underlying security. One does not even need to remember the lists of parameters required to specify the model, but only its name. Thus the parameter specification for an American Put option is described by the command:

In this way we can easily make a template for calculating and pasting financial derivatives with variable inputs:

The output of the above `Manipulate` is copied directly onto your clipboard so that you can paste it into an input cell, wrap `ReleaseHold` around it, and replace the `PlaceHolders` by numerical values, as in the example below:

Finally, though by no means exhaustively, there is the function `TradingChart`, which takes data from the pre-existing function `FinancialData` and graphs it up with financial indicators, which can be used to identify possible trading events. In the case below, I have chosen a darker opacity for those closing prices in the bottom and top third of values because they suggest possible moments when one is most likely to buy or sell, respectively.

One of the main purposes of the conference was also to highlight *Mathematica*’s development of CUDA programming and to show that it can be applied to the massively parallel evaluation of financial options. To access this functionality, we must first load in the *CUDALink* package, which allows one to utilize the many parallel cores on the GPU. Here we simultaneously evaluate one hundred thousand different Asian arithmetic options, which are each simulated using Monte Carlo techniques. The time required to perform these calculations is a small fraction of the time required using CPU compilation.

For more information, please refer to the Financial Engineering and Mathematics page, or visit the Optimizing Financial Modeling seminar page to download the full presentations and a white paper on CUDA programming with *Mathematica*.

## 10 Comments

The use of “Optimizing” as a title for a seminar is a rather disingenuous marketing ploy. What is an “optimal model” supposed to be anyway? A model cannot be optimized. An optimum is, by definition, a state that cannot be improved anymore. In the material I find nothing that would allow me to get to the point of an optimal financial model.

Next, I find a couple of issues with some of the new FinancialDerivative function, they are far from perfect. Anything that is not perfect cannot be optimal. So, neither are the M functions optimal, nor would the seminar allow me to program an optimal model.

The new interfaces for the financial functions and the inclusion of CUDA in M8 are absolutely great. I use them myself with great eagerness. I have expressed my fascination for CUDA inclusion in blog comments before. But that doesn’t mean we have “optimal modelling”.

Except for the false advertising of the seminar and this blog post, an otherwise good summary of really great M8 features.

LOL.

Should be more careful while talking to mathematicians.

@Mooniac, “optimizing” in this context seems to be about decreasing computational time of the model (by using the GPUs) and not about creating models that are more accurate/optimal, no? Regarding FinancialDerivative[], I’d encourage you to send your feedback to Wolfram (http://www.wolfram.com/support/contact/email/?topic=Feedback).

Trying out CUDALink in Mathematica 8 and there are issues. Is the older NVIDIA Driver 257.xx – 260.xx *required* ? I’m running the 266.58 driver on Win 7 x64 and despite CUDAQ[] working the results silently fail. Help! :)

Confirmed, reverting to NVIDIA 260.99 WHQL driver fixes Mathematica 8 CUDALink. The latest WHQL 266.58 does *not* work. Huzzah!

Unfortunately TimeValue is not a good function to be using in an article about optimizing — it is a very very slow function. This function is useful for one off calculations and likely to be of use in academia or grad school, but for real world production is so slow as to be useless.

We have written our own TimeValue functions that are over 1 order of magnitude faster than the built in stuff.

Basically, built in date and time calculations, time value, cashflow discounting and so on are so slow in Mma that you simply cannot use them in a real world environment. Fortunately it is relatively straight forward to write your own functions for these tasks but it does make you wonder why the built in ones are so dreadfully slow.

In response to Mike:

The real power behind TimeValue, Annuity, Cashflow and FinancialBond, is their symbolic capabilities. One of the main benefits of these functions is the ability to use symbolic input and get back symbolic output, which is often a closed form Mathematica expressions (even in the face of complicated payment growth functions and day-count conventions). It is the symbolic output expressions that should probably be used in further computation, iteration, optimization, statistical modeling, etc, not the TimeValue suite itself. One might view the TimeValue functions as kind of like formula generators. The pre-computed formulas can then be plugged into optimization schemes.

Also, TimeValue uses built in Mathematica Date functions like DatePlus, DateDifference, etc. When doing date computations, it will only be as fast as these functions are. It is possible that performance improvements can be gained by changing the input into unitless time rather than actual dates. TimeValue also uses the symbolic capability of Series, which can sometimes take a while to find a suitable closed form expression. Performance improvements in this realm might be gained by using the option “ClosedForm”->False (an option found in Options[TimeValue]).

I think Stephen Wolfram is a genius of our time. I want to learn Mathematica before the world finds out about it! With Mathematica it seems that everything is possible. :)

Also, TimeValue uses built in Mathematica Date functions like DatePlus, DateDifference, etc. When doing date computations, it will only be as fast as these functions are. It is possible that performance improvements can be gained by changing the input into unitless time rather than actual dates. TimeValue also uses the symbolic capability of Series, which can sometimes take a while to find a suitable closed form expression. Performance improvements in this realm might be gained by using the option “ClosedForm”->False (an option found in Options[TimeValue]).

Michael Kelly and Ryan Smith,

Thank you for the tip about using the symbolic output expressions. The speed increase is amazing. I was doing a plot using FinancialBond that was taking almost 3 seconds. Using the symbolic expression in my own function made the plot appear instantaneously. If this tip isn’t in the documentation somewhere, it should be.