Contents
Specify parameters
S0 = 50; % Spot price mu = 0.1; % drift parameter sigma = 0.3; % diffusion parameter T = 1; % maturity NSteps = 250; % Number of time steps NRepl = 3; % Number of generated trajectories
This example uses normally-distributed random numbers
Reset generator.
randn('seed',0);
randn(NRepl, 5)
randn(NRepl, 10000);
hist(ans(:),50)
ans =
1.1650 0.3516 0.0591 0.8717 1.2460
0.6268 -0.6965 1.7971 -1.4462 -0.6390
0.0751 1.6961 0.2641 -0.7012 0.5774

Note the 'n' in 'randn'
rand(NRepl, 1000); hist(ans(:))

AssetPaths - finding cumulative sums by columns
A = magic(3)
cumsum(A)
% And by rows (second parameter is the dimension)
cumsum(A,2)
A =
8 1 6
3 5 7
4 9 2
ans =
8 1 6
11 6 13
15 15 15
ans =
8 9 15
3 8 15
4 13 15
EuroMC - feval
EuroMC takes a function as a parameter, e.g. MyCall or MyPut In order to compute the function on multiple values use feval.
A = 15*rand(5,2)
feval('MyCall', A, 3)
A =
4.7764 2.5946
1.2723 6.3158
2.2323 3.2416
0.5818 6.9656
10.2351 5.7911
ans =
1.7764 0
0 3.3158
0 0.2416
0 3.9656
7.2351 2.7911
An alternative approach
This works because the parameters to MyCall can be matrices.
A = 15*rand(5,2) B = 3 * ones(size(A)) MyCall(A, B)
A =
14.4104 2.0833
5.0947 3.9955
13.6042 7.0120
11.8220 6.9748
10.0508 13.1728
B =
3 3
3 3
3 3
3 3
3 3
ans =
11.4104 0
2.0947 0.9955
10.6042 4.0120
8.8220 3.9748
7.0508 10.1728
Parameter estimates for normal data (by columns)
[muhat, sigmahat] = normfit(5*randn(10,2)+100)
muhat =
99.5729 99.3482
sigmahat =
5.4693 5.1680