Background Information:
Consider the Psedocode:
Question:
I am trying to implement the above in C++ but I don't really understand how to implement it correctly. Note, the ZZ
is the Z_ij
in the Pseudocode. We have S[0] = 50
. Here is my code:
for(int j = 1; j <= N; j++){
for(int i = 1; i <= n; i++){
S[i] = S[i-1]*exp((mu - sigma/2)*(t[i] - t[i-1]) + sqrt(sigma)*sqrt(t[i] - t[i-1])*ZZ[i]);
}
}
Big N = 10000
and n = 10
. I know that my outer loop does nothing but heat up my cpu, but I am not sure how to use the outer loop from the Pseudocode above. Any suggestions are greatly appreciated.
Here is the time vector I created, we use 10 time steps t_0 = 0, t_1 = \Delta t, t_2 = 2\Delta t,...,t_10 = 10\Delta t = T. Note T = 1. Here is the code:
double t[n+1];
for(int i = 0; i <= n; i++){
t[i] = (double)i*T/(n-1);
}