title: Python: Monte Carlo Simulation
body: <p>I am not sure how to even proceed or where I went wrong, I am getting a large array</p>
  <p>This is the instruction</p>
  <p>Create a markdown cell that displays a level 2 header that reads: &quot;Part D: Monte Carlo Simulation&quot;. Also add some text briefly describing the purpose of your code in this part.
  Write a function named monte_carlo. The function should accept five parameters: start, rate, vol, days, and num_runs. The function should use a loop to generate a number of simulated stock runs equal to num_runs. The characteristics of the runs are provided by the parameters start, rate, vol, and days. A detailed description of this function is provided below. Each time you loop executes, the following steps should be performed:</p>
  <ol>
  <li>Simulate a run using the supplied parameters. Store the resulting array in a variable.</li>
  <li>Determine the final simulated price of the stock and append it into a list called final_prices.</li>
  <li>Determine the annual yield for the simulated run and append it into a list called annual_yields.
  When the loop is done executing, convert the two lists you have constructed to numpy arrays and
  return both of them.</li>
  </ol>
  <p>Create a markdown cell to explain that you are about to test the function by running a Monte Carlo simulation with a specific seed.
  Set a seed of 1, and run a Monte Carlo simulation consisting of 10,000 simulated runs for a stock with a current price of 200, an expected annual return of 10%, and a volatility of 0.4. Each run should be over a period of 500 days. Create a histogram of the final prices. Use bins=np.arange(0, 1600, 50), and set the edgecolor to black. Set the size of the
  figure to be [10,5].
  If your code is correct, your histogram should have a peak around 200 and should have a long tail trailing off to the right.
  This shows that the majority of the simulated final prices are near 200, but there are some very large outliers.</p>
  <p>Create a markdown cell to explain that you are about to display the 10th, 25th, 50th, 75th, and 90th percentiles of the simulated final prices.
  Use np.percentile to calculate the 10th, 25th, 50th, 75th, and 90th percentiles for the final prices in the simulated runs generated for the stock. Display the results by creating five lines of output, with each line using the following format: __th
  percentile: _____
  Round the display percentiles to 2 decimal places.
  If done correctly, you should get a 10th percentile of 118.05 and a 90th percentile of 505.91.</p>
  <pre><code>def monte_carlo(start, rate, vol, days, num_runs):
      final_prices =[]
      annual_yields =[]
      for runs in range(0, num_runs):
          runs = simulate_stock(start, rate, vol, days)
          y = runs[-1]
          final_prices.append(y)
          z = find_yield(runs)
          annual_yields.append(z)
      np.asarray(final_prices)
      np.asarray(annual_yields)
      return final_prices, annual_yields
  
  np.random.seed(1)
  final_prices, annual_yields = monte_carlo(200, 0.1, 0.4, 500, 10000)
  plt.figure(figsize=[10, 5])
  plt.hist(final_prices, bins=np.arange(0, 1600, 50), edgecolor='black')
  </code></pre>