# How can you compute Itō Integrals with Mathematica?

How can you compute Itō Integrals with Mathematica? I tried searching through the documentations but I didn't find anything.

P.S. I was not at all sure how to tag this question. I had to put in at least one tag, and I do not have enough reputation to create a new one. Somebody with more rep can feel free to tag it appropriately.

-
I could explain how to solve a Stratonovich SDE (which is simply related to an Ito SDE). Would that be enough or do you need more? – acl Mar 18 '12 at 11:21
What is an Itô Integral? (please include links to this kind of information in your questions) – Mr.Wizard Mar 18 '12 at 12:31

While I cannot answer your question I would like to point at Computational Financial Mathematics using MATHEMATICA®: Optimal Trading in Stocks and Options, which should answer it.

From the index:

-

One good way would be to attend my Warsaw University seminar ;-) Seriously, you should specify if you are interested in symbolic or numerical computation. It is a very different thing (just as in the stochastic case) Stojanovic's book has a nice implementation of the multi-dimensional Ito formula - which is essentially a (continuous) stochastic calculus analogue of the chain rule in ordinary calculus. Since it is a lot more complicated than the chain rule, it is useful to be able to use a computer algebra system for this purpose. Computing Ito integrals numerically is quite a different matter and is basically the same thing as "simulation". Stojanovic implementation is for Mathematica 3 so it is way too inefficient compared with what you can do in version 6 and later. Remember - the key thing is that it is much faster to generate random vectors and arrays than individual random numbers that are their elements.

Edit:

Well, for numerical Ito integrals you could always take a look at my old demonstration on Wolfram's Demonstrations Project.

-
 Both, actually. I am taking a course in Financial Mathematics, and we rely on hand calculation and Excel. I trust neither my hand calculations nor Excel, so I figured I ought try doing this in Mathematica, hence the question. – Mr Alpha Mar 20 '12 at 17:42

Mathematica doesn't have built-in functions to compute things around Ito integrals.

I know two authors who have done packages around this, I've never used them though.

From Mark Fisher (see the stochastic calculus paragraph for ItosLemma and EulerSimulate packages) http://www.markfisher.net/~mefisher/mma/mathematica.html

Here's an example of how you could generate paths of a Black-Scholes process. You can generalize this example to more complex cases (if you look for optimizations you'll find that inverting the FoldList and Map leads to a better speed but the code is less readable.)

SimpleBSPaths[S0_,r_,sigma_,nPaths_,dt_,nTimeSteps_,seed_:1] :=
Module[ {randomNumbers},

SeedRandom[seed];

randomNumbers = RandomReal[NormalDistribution[],{nPaths,nTimeSteps-1}];

Map[ (*equivalent to a loop for each path*)
FoldList[ (*equivalent to a loop for each timestep*)
(#1 Exp[(r-1./2 sigma^2) dt + sigma Sqrt[dt] #2])& (*#1= St-1, #2=n01 for this path and timestep*)
,
S0
,
# (*all random numbers for this path, has dimension {nTimeSteps-1}*)
]& (*produced path of dimension {nTimeSteps}*)
,
randomNumbers (*all random numbers for all paths, has dimension {nPaths,nTimeSteps-1}*)
] (*produced paths of dimension {nPaths,nTimeSteps}*)
];


Example

S0=100;
r=0.03;
sigma=0.2;
nPaths=5;
dt=1;
nTimeSteps=20;
SimpleBSPaths[S0,r,sigma,nPaths,dt,nTimeSteps]//ListLinePlot


Similarly for correlated Black-Scholes paths

SimpleMultiBSPaths[S0_,r_,sigma_,correlMatrix_,nPaths_,dt_,nTimeSteps_,seed_:1] :=

SeedRandom@seed;

A = Transpose@CholeskyDecomposition@covar;

numberOfUnderlyings=Length@S0;
randomNumbers = RandomReal[NormalDistribution[],{nPaths,nTimeSteps-1,numberOfUnderlyings}];

Map[ (*equivalent to a loop for each path*)
FoldList[ (*equivalent to a loop for each timestep*)
(#1 Exp[(r-1./2 sigma^2) dt + Sqrt[dt] A.#2])& (*#1= St-1, #2=n01s for this path and timestep*)
,
S0
,
# (*all random numbers for this path, has dimension {nTimeSteps-1,numberOfUnderlyings}*)
]& (*produced path of dimension {nTimeSteps,numberOfUnderlyings}*)
,
randomNumbers (*all random numbers for all paths, has dimension {nPaths,nTimeSteps-1,numberOfUnderlyings}*)
] (*produced paths of dimension {nPaths,nTimeSteps,numberOfUnderlyings}*)
];


Example:

S0 = {100, 105};
r = 0.03;
sigma = {0.2, 0.3};
correlMatrix = {{1., 0.8}, {0.8, 1.}};
nPaths = 5;
dt = 1/12.;
nTimeSteps = 24;
paths = SimpleMultiBSPaths[S0, r, sigma, correlMatrix, nPaths, dt, nTimeSteps];
(*Displays two correlated underlyings on one path*)
paths[[1]] // Transpose // ListLinePlot

-

It looks like Wolfram have written some stochastic stuff for their finance platform:

http://www.wolfram.com/training/special-event/wolfram-finance-platform-2012/

These are presumably internally written (by Michael Kelly?) add on packages.

-