So, I'm kind of at a loss here as to how to fix this issue. For a homework assignment, I'm supposed to implement two approximations of the geometric Brownian motion and compare them to the explicit solution. In both cases below, W represents a Brownian path I generate seperately with Levy-Ciesielski to be able to gauge the accuracy of the approximations.
Picard:
Picard = function(N, m, W){
Pfad = seq(1, 1, length.out=2^m+1);
for (i in 1:N){
NeuerPfad = vector(length=2^m+1);
NeuerPfad[1] = 1;
for (j in 2:2^m+1){
NeuerPfad[j] = NeuerPfad[j - 1] + Pfad[j - 1]/(2^m) + 2 * Pfad[j - 1] * (W[j] - W[j - 1]);
}
Pfad = NeuerPfad;
}
return(Pfad);
}
The problem with this one is that the results break apart more and more with every iteration. For some reason, I end up with N zeroes at the start of the path (exempting the initial 1) and I have no idea why that's the case.
Strong solution:
StarkeLoesung = function(m, W){
Pfad = vector(length=2^m+1);
Pfad[1] = 1;
for (i in 2:2^m+1){
Pfad[i] = Pfad[i - 1];
Pfad[i] = Pfad[i] * (2^(-m) + 2 * (W[i] - W[i - 1]));
}
return(Pfad);
}
I'm not sure what the problem with this one is at all since it seems to flatout skip the for loop. No matter what I do to this function, all it returns at the end is a vector with a 1 at the start and a whole bunch of zeroes.