title: Simulating for loop 100 times with a matrix
body: <p>I am currently trying to run a simulation of MBS a 100 times. I have written the for loop that I need, however I need to make this loop run 100 times. After consulting with a friend, I believe that I need to specify the &quot;size&quot; parameter in np.random.normal as a matrix, however my coding skills are limited and I would greatly appreciate your help with doing so. Specifically, for a sequence of correlation parameter ρ (rho) between 0 and 1, I need to simulate 100 MBSs, and report the average payoff of each tranche across the simulations Below is my code with notes.</p>
  <p>EDIT:
  I appreciate the code proposed in the answers and it is indeed very useful. I have one last hurdle now to include: How do I include a payment structure that is sequential. Specifically, The junior tranche is the first to absorb losses from the
  underlying collateral pool and does so until the portfolio loss exceeds 5% (i.e. the proportion of defaults exceeds 10%) at which point the junior tranche becomes worthless. The mezzanine
  tranche begins to absorb losses once the portfolio loss exceeds 5% and continues to do so until the portfolio loss reaches 10% (i.e. the proportion of defaults exceeds 20%). Finally, the senior
  tranche absorbs portfolio losses in excess of 10%. As of now we've only considered an average payoff given a specific share of the total payoff.</p>
  <pre><code>rho_list = [0,0.2, 0.5,0.6, 1] 
  
  # parameters 
  n_borrowers = 10
  payoff_default = 0.5
  payoff_nodefault = 1
  threshold = -1.65
  
  # draw of income shocks (I have to draw new values of s and eps for each simulation)
  s = np.random.normal(0,1,size=1) # common s for all borrowers
  eps = np.random.normal(0,1,size=n_borrowers) # each borrower has their own eps
  
  for rho in rho_list :
  
    # compute the borrower's income
    x = np.sqrt(rho) * s + np.sqrt(1-rho) * eps
  
    # which borrower defaults?
    loan_payoff = (x &lt; threshold) * payoff_default + (x &gt;= threshold) * payoff_nodefault
  
    # total pool 
    total_payoff = np.sum(loan_payoff)
  
    # how much does each investor receive from total_payoff?
    senior_payoff = 0.82 * total_payoff 
    mezz_payoff = 0.12 * total_payoff 
    junior_payoff = 0.6 * total_payoff 
  
    print('total: {}, senior: {}, mezz: {}, junior: {}'.format(total_payoff, senior_payoff, mezz_payoff, junior_payoff))
  
  # next steps (this is what I need help with)
  # repeat this for 100 simulations and compute the average payoff to each investor
  # is it possible to generate the income for all simulations in one step? 
  # Idea: specify the &quot;size&quot; parameter in np.random.normal as a matrix 
  </code></pre>