code: def test_mc_optimisation():
      d = d_pass[4]
      pf = build_portfolio(**d)
      # since the monte carlo optimisation is based on random numbers,
      # we set a seed, so that the results can be compared.
      np.random.seed(seed=0)
      # orig values:
      minvol_res_orig = [
          0.18560926749041448,
          0.1333176229402258,
          1.3547291311321408,
      ]
      maxsharpe_res_orig = [
          0.33033770744503416,
          0.16741461860370618,
          1.9433052511092475,
      ]
      minvol_w_orig = [
          0.09024151309669741,
          0.015766238378839476,
          0.514540537132381,
          0.37945171139208195,
      ]
      maxsharpe_w_orig = [
          0.018038812127367274,
          0.37348740385059126,
          0.5759648343129179,
          0.03250894970912355,
      ]
      labels_orig = [
          "min Volatility",
          "max Sharpe Ratio",
          "Initial Portfolio",
      ]
      xlabel_orig = "Volatility [period=252]"
      ylabel_orig = "Expected Return [period=252]"
      # run Monte Carlo optimisation through pf
      opt_w, opt_res = pf.mc_optimisation(num_trials=500)
      # tests
      assert (
          minvol_res_orig - opt_res.iloc[0].values <= strong_abse
      ).all()
      assert (
          maxsharpe_res_orig - opt_res.iloc[1].values <= strong_abse
      ).all()
      assert (minvol_w_orig - opt_w.iloc[0].values <= strong_abse).all()
      assert (
          maxsharpe_w_orig - opt_w.iloc[1].values <= strong_abse
      ).all()
  
imports: import datetime
  import os
  import pathlib
  import matplotlib.pylab
  import numpy
  import pandas
  import pytest
  import quandl
  import yfinance
  from finquant.efficient_frontier import EfficientFrontier
  from finquant.portfolio import Portfolio, build_portfolio
  from finquant.stock import Stock
label_desc: Use image node_id 8 for calling a global function with example usage: test_mc_optimisation() without return types