Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

14. Monte Carlo Simulation

How to decide when a key input is uncertain: describe it by a distribution estimated from data, play the decision thousands of times with NumPy, and judge each plan on the whole distribution of its outcome. The newsvendor model, reading risk, the number of runs, a competitive bid, and a Streamlit app that puts the simulation in the manager’s hands.

Slides

Present full screen Download the PDF

Click or tap the slide to move forward, its left edge to go back; the arrow keys work too.

Reading

Monte Carlo Simulation simulates Qahwa House’s Ramadan gift-box season at the Olaya branch: it estimates demand from the errors of nine seasons of forecasts, shows why the best order is below the forecast and not 20% above it, checks the rule on the real seasons since 2018, reads the risk of each plan, and then chooses a bid for a catering contract with a limit on the chance of a loss.

Lab 14: Simulation app

In December 2025, each branch orders its Ramadan gift boxes once, for the whole season. How many should the Corniche branch order, and what risk comes with that order? You simulate 10,000 seasons, find the best order by simulation and by the critical ratio, compare the risks of three plans, choose a bid for a university’s coffee kiosks, then write a Streamlit app in which the manager picks a branch and an order and sees the distribution of profit.

Running the app

Colab cannot display a Streamlit page, so the lab tests the app with Streamlit’s AppTest. To see it in a browser:

  1. GitHub Codespaces (free with GitHub Education) or your own computer: open a terminal in the folder with the app, run pip install streamlit pandas scipy, then streamlit run giftbox_app.py. A browser tab opens at http://localhost:8501.

  2. Share it: push the app and a requirements.txt to a GitHub repository and deploy it on Streamlit Community Cloud, choosing the repository and the file. You get a public link.

The finished course version, with the prices as inputs, the standard error, every order on the same seasons, all four branches against the ordering habit, and a second tab for the catering bid: app.py and its requirements.txt. In a clone of the course repository, run it with streamlit run week14/app/app.py.

Next week

Multi-criteria decisions with AHP and TOPSIS, responsible analytics and AI, and the capstone demos.

→ Week 15: Multi-Criteria Decisions and Responsible Analytics