🎓 This repository provides code for an interactive Streamlit application that uses Monte Carlo simulation to analyze the multi-period newsvendor problem. By exploring this code and application, you will:
- ✅ Build a Streamlit web application to serve as an interactive front-end for a Monte Carlo simulation.
- ✅ Integrate Python-based Monte Carlo simulation logic (specifically for the newsvendor problem) within a Streamlit application.
- ✅ Utilize Streamlit widgets (sliders, number inputs, file uploaders) to control simulation parameters and display results dynamically, including dataframes and plots.
- 🎁 Bonus: Enhance the user experience of using your app specifically for simulation by adding a progress bar (
st.progress).
The materials have been made available under an MIT license. The materials are as-is with no liability for the author. Please provide credit if you reuse the code in your own work.
If you reuse any of the code, or the tutorial helps you work, please provide a citation.
@software{TheOpenScienceNerd_streamlit_newsvendor
author = {Monks, Thomas},
license = {MIT},
title = {TheOpenScienceNerd - Building an Interactive Newsvendor Monte Carlo Simulator with Python and Streamlit},
url = {https://github.com/TheOpenScienceNerd/monte-carlo-app}
}All dependencies can be found in binder/environment.yml and are pulled from conda-forge. To run the code locally, we recommend installing miniforge;
miniforge is Free and Open Source Software (FOSS) alternative to Anaconda and miniconda that uses conda-forge as the default channel for packages. It installs both conda and mamba (a drop in replacement for conda) package managers. We recommend mamba for faster resolving of dependencies and installation of packages.
navigating your terminal (or cmd prompt) to the directory containing the repo and issuing the following command:
mamba env create -f binder/environment.ymlActivate the mamba environment using the following command:
mamba activate mcappTo run the streamlit app:
streamlit run Simulation_model.py.
├── data
│ └── ...
├── Simulation_model.py
├── main.py
├── CHANGELOG.md
├── CITATION.cff
├── environment.yml
├── LICENSE
├── newsvendor.py
└── README.md
- environment.yml` - contains the conda environment if you wish to work the models.
newsvendor.py- contains the monte-carlo simultion modelSimulation_model.pycontains the complete streamlit app code (the main focus of the tutorial)main.py- contains outline code for running the simulation model. Modify this as you code along with the tutorial.CHANGES.md- changelog with record of notable changes to project between versions.CITATION.cff- citation information for the code.LICENSE- details of the MIT permissive license of this work.