Skip to content

Instantly share code, notes, and snippets.

@gerald-kim
Created April 10, 2023 07:17
Show Gist options
  • Save gerald-kim/dc6fbfdab80c583afe7196cc0c5cad94 to your computer and use it in GitHub Desktop.
Save gerald-kim/dc6fbfdab80c583afe7196cc0c5cad94 to your computer and use it in GitHub Desktop.
프로젝트 종료일 monte carlo simulation
import random
import numpy as np
data = [
[1, 100, 2, 10],
[2, 108, 10, 9],
[3, 109, 5, 8],
[4, 106, 2, 11]
]
# Extract the relevant data
added_stories = [row[2] for row in data]
completed_stories = [row[3] for row in data]
def simulate_sprint(total_stories, remaining_stories):
added = random.choice(added_stories)
completed = random.choice(completed_stories)
remaining_stories += added - completed
total_stories += added
return total_stories, remaining_stories
def monte_carlo_simulation(total_stories, remaining_stories, num_simulations=1000):
sprints_to_completion = []
for _ in range(num_simulations):
sprints = 0
remaining = remaining_stories
while remaining > 0:
total_stories, remaining = simulate_sprint(total_stories, remaining)
sprints += 1
sprints_to_completion.append(sprints)
return sprints_to_completion
initial_total_stories = data[0][1]
initial_remaining_stories = initial_total_stories - data[0][3]
num_simulations = 50
sprints_to_completion = monte_carlo_simulation(initial_total_stories, initial_remaining_stories, num_simulations)
# Calculate average sprints to completion
average_sprints = np.mean(sprints_to_completion)
print(f"Average sprints to completion: {average_sprints}")
prob_completion = {i: sprints_to_completion.count(i) / num_simulations for i in set(sprints_to_completion)}
# Calculate cumulative probability
cumulative_prob = {}
running_total = 0
for k in sorted(prob_completion.keys()):
running_total += prob_completion[k]
cumulative_prob[k] = running_total
# Print cumulative probabilities
print("Cumulative probability of completing the project by a specific sprint:")
for k, v in cumulative_prob.items():
print(f"By sprint {k}: {v * 100}%")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment