Course Motivation Kipp Martin University of Chicago Booth School of Business January 4, 2012
Excel and MATLAB: Why? Course: Tools for Business Analysis: Excel and Matlab Why study Excel and MATLAB? What role do Excel and MATLAB play in moderate corporate problem solving? What can you do with Excel and MATLAB?
Outline 3 Example 1 Hospital Scheduling Example 2 Optimal Energy Dispatch Example 3 Portfolio Optimization Course Objectives
Hospital Scheduling Develop an application for a large hospital to take: Requests for surgical spaces (e.g., a cardiology surgery, at Location 1, in the AM, two days a week, two weeks per planning horizon) Requests for clinical spaces (e.g., an ENT clinic, at Location 2, all day, Monday and Wednesday, every week) Doctor requests (e.g., I play golf every Tuesday afternoon) Find a schedule: Match available surgery and clinic rooms at the various locations with the space requests Match doctor requests as closely as possible to the space request assignments
Hospital Scheduling Administrative assistants for each specialty need to sit at their desktop machines and enter the space and doctor request information for the given specialty. The requests across all specialties must be gathered, aggregated, and stored somewhere. An optimization model must be built and solved that finds a feasible allocation of space requests to available rooms and doctors to meet the requests The results need to be returned to the desktops of each administrative assistant in order to schedule the doctors. The system must be run and used every month by people that know nothing about optimization.
Hospital Scheduling There are two problems here: 1. Develop an optimization model to solve a complex scheduling problem. 2. Incorporate the model into an architecture so that the model is actually used. What do I mean by architecture?
Hospital Scheduling 7 Figure: Entering the Data.
8 Hospital Scheduling Data entry form (this is an Excel UserForm):
Hospital Scheduling 9 MySQL Excel UserForm Tomcat Web Server Java Web Services Application Java Database Driver Tomcat Web Server COIN-OR OS COIN-OR Bcp Figure: Calling the Scheduling Application
Hospital Scheduling 10 Solve the problem with optimization solvers:
Hospital Scheduling 11 Model solution form (another Excel UserForm):
Hospital Scheduling What is involved? Excel/Visual Basic User Forms Excel/Visual Basic Create SQL requests from User Forms MySQL (Relational Data Base) An optimization model Optimization solvers Web Server Excel/Visual Basic Web Services communication (send and receive over the Web). You will learn to have VBA generate code for you!
Hospital Scheduling Key Takeaway: What is the role of Excel and VBA? Store the data? No! Build the model? No! Solve the model? No! The role of Excel and VBA system integration!!!
Optimal Energy Dispatch The Problem: A utility wants to achieve an energy level reduction during certain time periods (usually peak periods) Customers agree to have their service interrupted or curtailed Customers receive compensation for this How does the utility interrupt in a way to maximize revenue
Optimal Energy Dispatch Key Components: Utility portal run/invoke the models Customer portal lets customers decide to participate in an event (i.e., to let us control their appliances) or to override during an event. Database Microsoft SQL Server Demand and energy cost forecasting modules An optimization model A optimization solver
Optimal Energy Dispatch 16
Optimal Energy Dispatch 17
Energy Dispatch Key Takeaways: An optimization model is the critical to the system A fast solver is needed for the system things happen in real time Must get data in and out of the model Note: in this case the portal is a web page rather than an Excel UserForm and is a system integrator.
Model: Portfolio Optimization n = number of stocks under consideration x i = percentage of portfolio invested in stock i X = [x 1 x 2 x n ] C = n n variance-covariance matrix µ i expected return for stock i R = required portfolio return C = variance-covariance matrix min X CX (1) n µ i x i R (2) i=1 n x i = 1 (3) i=1 x i 0, i = 1,..., n (4)
Load the data into MATLAB Model: Import Data prices = load( ASWch8ex13stockprices.txt ) Table: Stock Price Data for Apple, AMD, and Oracle AAPL AMD ORCL 4.16 17.57 4.32 4.58 10.10 3.88 10.30 11.47 9.23 25.94 18.00 24.98 10.81 24.60 29.12 12.36 16.05 17.26 7.18 5.24 12.03 11.28 14.86 13.86 38.45 15.80 13.77 75.51 41.80 12.57
Model: Massage the Data Calculate returns from prices and create a variance-covariance matrix. p i,t+1 = p it e r. Taking the natural logarithm of both sides gives the return r = ln(p i,t+1 /p it ) % get rows 2 through 10 of prices pricesmod1 = prices(2: numrows, :); % get rows 1 through 10 of prices pricesmod2 = prices(1: numrows - 1, :); % calculate the returns (assumes continuous compounding) returns = log(pricesmod1./pricesmod2)
Model: Calculate Model Parameters C = cov(returns, 1) C = 0.4253 0.1852 0.1393 0.1852 0.4458 0.1388 0.1393 0.1388 0.2314 The variance-covariance matrix is used in the optimization model. In MATLAB use the mean() function, or in Excel use the AVERAGE() function to get the expected stock returns.
Model: Optimize the Model Both MATLAB and Excel have optimization routines. However, we might wish to solve the model on a remote faster machine. The optimal solution is x 1 = 0.1818, x 2 = 0.1688, x 3 = 0.6495
Model: Visualization Excel and MATLAB are also ideal tools for analyzing problem results and visualizing functions and data. 24
Example Summary What roles do MATLAB and Excel play 1. import data from various sources, modify the data, and analyze the data 2. use data to create a model instance 3. solve the model 4. analyze the problem results 5. provide visualization 6. act as middleware, provide an interface (API - application program interface) to other software 7. provide a user interface for the underlying model
Summary Takeaways 1. A real system is complex there are lot of parts that need to be connected. You need to move information around. 2. It is critical, for example in consulting, to have knowledge about how to connect things together. At least know what tools are available and what are the capabilities of these tools. 3. In most interesting applications there are lots of tradeoffs too many for a human to enumerate. A model is needed to find the best solution. This can have a large impact on profitability.
Course Objectives 1. Learn VBA (Visual Basic for Applications), a key tool that adds tremendous functionality to Microsoft Excel. This tool is widely used in business. 2. Learn to use MATLAB. This is an important program used in a number of other Booth courses. In the business world it is used extensively on Wall Street. 3. Develop skill in building realistic optimization models to support decision making. 4. Learn how to access and integrate data that reside in different locations and use these data as input to models. 5. Learn to use the General Algebraic Modeling System (GAMS) developed at the World Bank. This modeling system will allow students to formulate and solve realistic models using the input from Excel and MATLAB.