generated from TheOpenScienceNerd/tosn_python_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (46 loc) · 1.25 KB
/
main.py
File metadata and controls
58 lines (46 loc) · 1.25 KB
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
"""
Simulation model skeleton code for you to modify when
following the tutorial.
Author: www.youtube.com/@TheOpenScienceNerd
Year: 2025
"""
import pandas as pd
from newsvendor import (
Experiment,
multiple_replications,
create_profit_histogram,
DEFAULT_PATH_DAY_TYPE,
DEFAULT_PATH_DEMAND,
)
def main():
purchase_cost = 33.0
sale_price = 50.0
salvage_price = 5.0
# Operational parameters
order_qty = 70
n_days = 20
n_reps = 1000
df_daytype = pd.read_csv(DEFAULT_PATH_DAY_TYPE)
df_demand = pd.read_csv(DEFAULT_PATH_DEMAND)
# Run the simulation with the progress callback
exp = Experiment(
order_quantity=order_qty,
periods=n_days,
purchase_cost=purchase_cost,
sale_price=sale_price,
salvage_price=salvage_price,
# strip formatting from distribution dataframes
day_type=df_daytype,
demand_prob=df_demand,
)
results = multiple_replications(
exp, n_reps
)
# Display summary statistics formatted as currency
print(
results[["profit"]].describe().iloc[1:].map(lambda x: f"£{x/100:.2f}")
)
# fig = create_profit_histogram(results.profit / 100)
# fig.show
if __name__ == "__main__":
main()