-
Notifications
You must be signed in to change notification settings - Fork 1
/
micro_project.py
67 lines (52 loc) · 1.92 KB
/
micro_project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import random
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def show_up(probability_show):
if random.random() <= probability_show:
return True
else:
return False
def simulate_flight(nb_tickets_sold, probability_show):
n = 0 # number of folks who bought tix that will show up
for i in range(0,nb_tickets_sold):
if show_up(probability_show):
n = n + 1
return n
def simulate_net_revenue(nb_tickets_sold, nb_seats,
probability_show, revenue_per_seat, voucher_cost):
# how many ticket purchasers actually showed up?
nb_shows = simulate_flight(nb_tickets_sold, probability_show)
# no one bumped from flight if less or equal folks show up than for
# the number of seats we have
if nb_shows <= nb_seats:
return revenue_per_seat * nb_shows
# if more customers show up than seats we hv, must pay out vouchers
else:
vouchers_out = nb_shows - nb_seats
return nb_seats * revenue_per_seat - voucher_cost * vouchers_out
probability_show = 0.935
nb_seats = 100
revenue_per_seat = 350.0 # USD
voucher_cost = revenue_per_seat * 2.0 # USD
nb_flights = 10000
max_overbooking = 16
revenue = np.zeros((nb_flights, max_overbooking))
for tix_overbooked in range(0, max_overbooking):
nb_tickets_sold = nb_seats + tix_overbooked
for f in range(0, nb_flights): # simulate nb_flights flights
revenue[f][tix_overbooked] = simulate_net_revenue(nb_tickets_sold, +
nb_seats, probability_show, revenue_per_seat, voucher_cost)
print(revenue)
col = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
index = range(10000)
df = pd.DataFrame(data=revenue[0:,0:], index=index, columns=col)
df.head(5)
df.tail(5)
df.describe()
# ax = plt.boxplot(revenue)
#f, ax = plt.subplots()
#l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
#ax.boxplot(revenue)
#ax.set_xticklabels(l)
#plt.show()