Mathematica in Your Information Infrastructure

The 1999 Mathematica Developer Conference

Roman E. Maeder

MathConsult Dr. R. Mäder
Samstagernstraße 58a
8832 Wollerau
Switzerland
http://www.mathconsult.ch
mailto:maeder@mathconsult.ch

A look at Mathematica as part of your IT infrastructure with an example from Finance.

© 1999 MathConsult Dr. R. Mäder. All rights reserved.

About the Speaker

Dr. Roman E. Maeder

The speaker is one of the developers of Mathematica and has used it in teaching and research since 1988. Dr. Maeder published several books about Mathematica.
After several years as professor of computer science at ETH Zurich he is now the founder and owner of the consulting company MathConsult Dr. R. Mäder.

Application Development

Why are software projects always late and over budget?

Mathematica can help you deliver on time and within budget.

Rapid Prototyping

Software Engineering

({{DBAccessProto.m, DBAccess.m}, {BeginPackage["DBAccess"]
GetData::usage="..."
Begin["`Private`"]

GetData[source_String]:= 
  {fakedata,...}
End[]
EndPackage[], BeginPackage["DBAccess"]
GetData::usage="..."
Begin["`Private`"]
Needs["Database`Database`"]
GetData[source_String]:= 
  SQLSelect[...]
End[]
EndPackage[]}})

In your application, first do this

Needs["DBAccess`", "DBAccessProto`"]

later, use

Needs["DBAccess"]

What about OO programming?

Proof of concept: QR Streams: custom-built OO framework inside Mathematica, offers all features of OO that make OO programming so successful.

For prototypes: Classes.m, see The Mathematica Programmer II

Interfacing

MathLink

MathLink is the standard communication protocol between the kernel and frontend. It is available also for other applications and allows other programs to communicate with Mathematica. A development environment for MathLink applications is part of the standard Mathematica software release.

Existing and Custom Links

The Mathematica kernel is the perfect choice as driver/server for your application. It interfaces well with many existing protocols and frontends.

Products and Tools mentioned

The Parallel Computing Toolkit (PCT)
brings parallelism to Mathematica, developed by Roman Maeder
soon to be released by Wolfram Research and MathDirect, http://www.mathdirect.com/products/par/

⟹ See presentation on Friday, 9am

Mathematica Link for Excel (Excel-Link)
a Mathematica-Excel interface
by Episoft/Wolfram Research, http://www.wolfram.com/products/applications/excel_link/

⟹ See presentation on Thursday, 8pm

Mathematica Link for MS Word (Word-Link)
a Mathematica-Word interface
by Wolfram Research, http://www.wolfram.com/products/applications/word_link/

Database Access Kit (DBAK)
interfaces with any datasource known to the MDAC, the Microsoft Data Access Components (ODBC)
under development by Wolfram Research (β test completed).

⟹ See presentation on Thursday, 7pm

J/Link
a Mathematica-Java interface (two-way)
under development by Todd Gayley, tgayley@linkobjects.com, http://www.linkobjects.com/

⟹ See presentations on Friday, 2pm, and Saturday, 4pm

Perl-Link
Math::ematica is a Perl module that allows accessing Perl from within Mathematica, developed by Ulrich Pfeifer, pfeifer@wait.de
Allows using the large number of existing Perl extensions (most are freely available) from Mathematica. Available from CPAN.

Stop Press:

Mathematica for Active-X Toolkit
Visual Basic interface to the kernel
under development by Anton Rowe, http://www.episoft.com/

⟹ See exhibit at the Mathematica store, developer is present Fri/Sat 11-12

I am glad to note that this list is not complete.

A General Framework for Interfacing with Third-Party Protocols

Custom-built interfaces by MathConsult, using, for example,

Linking Existing Libraries with the Mathematica Kernel

For C/C++, you write a little driver/dispatch program,
for Java classes J/Link provides this functionality.
See also MathCode C++

Two Simple Examples from Finance

In each case using the Mathematica kernel and the Excel front end.

A Term Structure with Regression

Simple user interaction, with a look at the components first.

Modell of Cox, Ingersoll, Ross

Here we implement the CIR model to find the best parameter fit to historical data.

3-month LIBOR, 1981-1994

liborData = ReadList["Data/Libor3.txt", {Word, Number}];  
    Dimensions[liborData]

liborHeaders = {"Datum", "Zins"};

libor = Transpose[liborData][[2]]

ListPlot[libor, AxesLabel -> "3-Monats LIBOR", 
        PlotStyle -> PointSize[0.005]];

The model

d r = a(b - r) d t + σ (Sqrt[ r]) 
          d z

maximum likelihood Method, which is a generalization of least squares for variable variances.

(Subscript[h, t]) = (σ^2) (Subscript[r, t]) und die Residuen (Subscript[z, t]) = (Subscript[dr, t]) - a (b - (Subscript[r, t]))

\(\(CIR[a_, b_, σ_]\)[data_] := 
	
      Module[{dr, rt, ht, zt}, 
		dr = 
          Drop[data, 1] - Drop[data, \(-1\)]; 
		rt = 
          Drop[data, \(-1\)]; 
		ht = \(σ\^2\) rt; 
		zt = 
          dr - a \((b - rt)\); 
		Transpose[{zt, ht}]
		]\)

Log-Likelihood ∑(((-(Subscript[lnh, t]))/2) - (((Subscript[z, t])^2)/(2  (Subscript[h, t]))))

\(logLikelihood[data_List, model_] := 

      Plus @@ Apply[
          Function[{zt, ht}, \(-\(Log[ht]\/2\)\) - zt\^2\/\(2  ht\)], 
          model[data], {1}]\)

rr = libor/100.0;
days = 261.0;

Starting values (least squares)...

rt = Drop[rr, -1];
dr = Drop[rr, 1] - Drop[rr, -1];

fit = Fit[Transpose[{rt, dr}], {1, r}, r]

{(Subscript[a, 0]), 
        (Subscript[b, 0])} = {a, 
          b} /. SolveAlways[a (b - r) == fit, r][[1]]

...sample standard deviation

(Subscript[σ, 0]) = StandardDeviation[rt]/(Sqrt[Mean])[rt]

maximize:

{max, params} = 
      FindMinimum[-logLikelihood[rr, CIR[a, b, σ]], {a, (Subscript[a, 0]), 0, 
          0.1}, {b, (Subscript[b, 0]), 0, 0.1}, {σ, (Subscript[σ, 0]), 0.001, 
          0.2}]

Now to Excel to play with the zero coupon bond pricing formula P[t, T, (Subscript[r, t])], implemented below.

\(Function[{a, b, σ}, 

        With[{γ = \@\(a\^2 + 2  σ\^2\)}, 
		A[t_, 
              T_] := \((\(2  γ\ E\^\(\((a + γ)\) \((T - t)\)/2\)\)\/\(\((γ + a)\) \((E\^\(γ \((T - t)\)\) - 1)\) + 2  γ\))\)\^\(2  a\ b/σ\^2\); 
		B[t_, 
              T_] := \(2 \((E\^\(γ \((T - t)\)\) - 1)\)\)\/\(\((γ + a)\) \((E\^\(γ \((T - t)\)\) - 1)\) + 2  γ\); 
		P[t_, T_, r_] := 
            A[t, T] E\^\(\(-B[t, T]\) r\);
		]]\)@@({a days,b,σ (Sqrt[days])}/.params)

This leads to the following expression for the term structure at time t, maturity T-t.

R[t_, T_, r_] := -(1/(T - t)) Log[P[t, T, r]]

Mathematica Consulting and
Application Development

Using Mathematica productively requires some experience.

I am one of the original developers of Mathematica. After several years as professor of computer science at ETH in Zurich I established, in 1996, my own consulting business, MathConsult Dr. R. Mäder, specializing in Mathematica consulting for Finance and other fields.

My consulting services are an efficient way to develop your Mathematica applications into the productive stage.

Books by Roman Maeder

⟹ On display at the Wolfram Research bookstore booth