Day 3 – Choosing My Path: The Start of a Focused Exploration

Bhavesh KapilBhavesh Kapil
2 min read

I watched a 5 minute video on Monte Carlo Simulation today, and it was very intriguing. What I found most interesting was how the simulation was able to determine answers to complex probabilistic questions in such a simplified way.

How the Monte Carlo Simulation works:

You first take the problem and define a range for the possible inputs: like a minimum and maximum and decide on a probability distribution. That could be uniform (where every value is equally likely), or something else like normal or triangular, depending on the situation. Then we use a computer to run multiple simulations, usually thousands or even millions and let it pick random values from that distribution for each run. Based on how the results vary across these simulations, we can plot a graph to visualize the spread, and also estimate probabilities. For example, we can find out the percentage chance that some task or event will finish within a certain time or cost range.

Example:

Let’s say you have to complete two assignments by the end of the day and you have to attend a party at 10 in night and right now it’s 2 in the noon, you have 8 hours to complete the assignments.

The question arrives, will you be able to make it to the party or should you cancel it right now. In order to determine the answer to this question you need to use the Monte Carlo Simulation.

We’ll first decide a time range to complete both the assignments based on past experiences. Let’s say 2hr to 6hr for the first assignment and 1hr to 4hr for the second one.

We take a uniform probabilistic model for this and let the computer run say a million simulations and based on the result we get our chances of making it to the party.

Using Python to solve the above problem:

import numpy as np
import matplotlib.pyplot as plt

sims = 1000000
A = np.random.uniform(2, 6, sims)  # Time for assignment 1
B = np.random.uniform(1, 4, sims)  # Time for assignment 2

duration = A + B

# Plotting the distribution
plt.figure(figsize=(6, 3))
plt.hist(duration, bins=100, density=True, color='skyblue')
plt.axvline(8, color='red', linestyle='--', label='8 hour mark')
plt.title('Distribution of Total Time')
plt.xlabel('Total Hours')
plt.ylabel('Probability Density')
plt.legend()
plt.show()

# Calculating the chance of finishing within 8 hours
chance = (duration <= 8).sum() / sims
print(f"Chance of finishing in time: {chance * 100:.2f}%")

0
Subscribe to my newsletter

Read articles from Bhavesh Kapil directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Bhavesh Kapil
Bhavesh Kapil

I'm a BTech CSE undergrad from a tier 3 college, documenting my journey from academic setbacks to building real-world skills in coding, ML, and finance. This blog is for anyone who believes in second chances and self-made success. I'm going to document everything I learn here and help you all connect with me by being real and also sharing the mistakes I made along the way, so you don't repeat the same. Let’s go on a journey of self-improvement and see how consistency and the mindset of showing up every day help beat the odds.