Message Boards Message Boards

Speeding up a simulation

Posted 9 years ago

Hi All,

I have tried my best to speed up the simulation below. Could it be made more time efficient ? Please ignore the LV function for now.

TFinal = 0.5;
NN = 10;
r = 0;
dt = TFinal/NN;
(*Initial Stock*)
(*All the parameters should be easily extractable from the files \
available*)
S0 = 1;

Num = 100000;

(**)

Tmin = 0.01;
T = Tmin;
LV = Compile[{{x, _Real}}, 0.8];
(******************)



ParallelEvaluate[Off[InterpolatingFunction::dmval]];

(*Initial Simulation Block*)
SimPathsLV = Transpose[Reap[
      Sow[ParallelTable[S0, {Num}]];
      Sow[
       SamplePaths2 = 
        ParallelTable[
         Nest[(a = RandomVariate[NormalDistribution[0, 1]]; #*
             Exp[((r - 0.5*(LV[#])^2)*dt + (LV[#])*Sqrt[dt]*a)]) &, 
          S0, 1], {Num}]];
      For[k = 0, T < TFinal, k++,
       T = T + dt;
       Sow[
        SamplePaths2 = 
         ParallelTable[
          Nest[(a = RandomVariate[NormalDistribution[0, 1]]; #*
              Exp[((r - 0.5*(LV[#])^2)*dt + (LV[#])*Sqrt[dt]*a)]) &, 
           SamplePaths2[[i]], 1], {i, 1, Num}]]
       (*Appending out iteration of the simulation*)
       ]][[2, 1]]] // Timing;

SimPathsLV[[1]]
POSTED BY: Nabeel Butt
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract