''' DS2500 Spring 2025 Sample code from class -- monte carlo simulation to determine whether we should open a bar on Huntington Ave (but NOT on campus property) We sell: * Laney's LI Iced Tea * Soda * Wings Prob distribution Iced tea: 100 @ 40%,200 @ 20%, 500 @ 2% Profit for wings: $3.50 EV comes from weighted average: .4 * 100 + .2 * 200 + .02 * 500 Simulation comes from choosing based on prob distribution: - sim for a day of sales: 100 OR 200 OR 500 - with a 40% chance of 100, 20% chance of 200, 2% chance of 500 ''' import numpy as np import seaborn as sns import matplotlib.pyplot as plt SIMS = 10000 DAYS = 365 START = 750000 NUMS = [100, 200, 500] LI = [.6, .38, .02] SODA = [.7, .1, .2] WINGS = [.35, .15, .5] LI_PROF = 8 SODA_PROF = 2 WING_PROF = 3.5 DAILY_OP = 500 def main(): # start off with expected value (always the same, based as a weighted average) ev_li = np.average(NUMS, weights = LI) ev_soda = np.average(NUMS, weights = SODA) ev_wings = np.average(NUMS, weights = WINGS) print(f"Expected values: {ev_li, ev_soda, ev_wings}") # how much profit do we expect to make in a year ev_profit = (ev_li * LI_PROF + ev_soda * SODA_PROF + ev_wings * WING_PROF - DAILY_OP) * \ DAYS - START print(f"Expected profit in a year: ${ev_profit}") # now, on to simulations # run this simulation a bunch of times outcomes = [] for _ in range(SIMS): # simulate the one day 365 times yearly_profit = 0 for _ in range(DAYS): # start with one day daily_li = np.random.choice(NUMS, p = LI) * LI_PROF daily_soda = np.random.choice(NUMS, p = SODA) * SODA_PROF daily_wings = np.random.choice(NUMS, p = WINGS) * WING_PROF daily_profit = daily_li + daily_soda + daily_wings - DAILY_OP yearly_profit += daily_profit yearly_profit -= START outcomes.append(yearly_profit) # print(f"After a year of simulated business, we made ${yearly_profit}") # how did we do? sns.histplot(outcomes, color = "magenta") plt.show() if __name__ == "__main__": main()