title: Efficient Way to Recursively Multiply
body: <p>I'm creating <code>N_MC</code> paths of simulated stock prices <code>S</code> with <code>n</code> points in each path, excluding the initial point.  The algorithm to do so is recursive on the previous value of the stock price, for a given path.  Here's what I have now:</p>
  
  <pre><code>import numpy as np
  import time
  
  N_MC = 1000
  n = 10000
  
  S = np.zeros((N_MC, n+1))
  S0 = 1.0
  S[:, 0] = S0
  
  start_time_normals = time.clock()
  Z = np.exp(np.random.normal(size=(N_MC, n)))
  print "generate normals time = ", time.clock() - start_time_normals
  
  start_time_prices = time.clock()
  for i in xrange(N_MC):
      for j in xrange(1, n+1):
          S[i, j] = S[i, j-1]*Z[i, j-1]
  
  print "pices time = ", time.clock() - start_time_prices
  </code></pre>
  
  <p>The times were:</p>
  
  <pre><code>generate normals time =  1.07
  pices time =  9.98
  </code></pre>
  
  <p>Is there a much more efficient way to generate the arrays <code>S</code>, perhaps using Numpy's routines?  It would be nice if the normal random variables <code>Z</code> could be generated more quickly, too, but I'm not as hopeful.</p>