Monte Carlo Business Case Analysis with pandas
Description: Pandas is increasingly becoming a standard tool in scientific computing. Could it also have a role in the CFO's office? CFOs regularly need to analyse the impact of different projects or business cases, and they almost universally do this using spreadsheets. Spreadsheets have many advantages - they have a low barrier to entry and are easy for most people to understand. However as they get more complicated, disadvantages start to appear; in particular, they can be inflexible and highly error-prone. In this talk I will explain how business case analysis can be done using python and pandas. The python version has several advantages over spreadsheets: it is more flexible as the business structure changes; formulas only need to be changed in a single place, reducing the chance of error; and report-ready plots are quick to produce. I'll go through a way of structuring the problem for some simple business logic, and ways to visualise the results. The example I’ll discuss is made more interest [cell cut: 1631 characters, first 1000 kept]

## Monte Carlo
Business Case Analysis
with pandas

arthur@artana.com.au

## Goal: Turn this...

## ...into this...

## ...and this...

## without using a spreadsheet

More at the European Spreadsheet Risks Interest Group

## Why pandas?

- Index by name

Crop | Cost/kg
--- | ---
apple | 0.15
pear | 0.20
orange | 0.22

Crop | Price/kg
--- | ---
pear | 2.60
apple | 3.10
orange | 2.80

## Why pandas?

- Index by name
- Handle missing data

Crop | Cost/kg
--- | ---
apple | 0.15
pear | 0.20
orange | 0.22

Crop | Price/kg
--- | ---
apple | 3.10
pear | 2.60
orange | 2.80
banana | 1.50

## Why pandas?

- Index by name
- Handle missing data
- Broadcast dimensions

Farm | Crop | Cost/kg
--- | --- | ---
Farm A | apple | 0.15
| pear | 0.20
| orange | 0.22
Farm B | apple | 0.12
| pear | 0.18
| orange | 0.25

Crop | Price/kg
--- | ---
pear | 2.60
apple | 3.10
orange | 2.80

## Overview

1. Read data
2. Simulate
3. Calculate
4. Report

## Overview

1. Read data ✓
2. Simulate
3. Calculate
4. Report

    			costs = pd.read_csv('costs.csv')
    			or
    			costs = pd.read_excel('cashflows.xlsx')

## Overview

1. Read data
2. Simulate ✓
3. Calculate
4. Report

    			data.groupby(keys).apply(sim, N)
    			def sim(g, size):
    			   return DataFrame(normal(g.mean,g.sd,
    			                           size=size))

## Overview

1. Read data
2. Simulate
3. Calculate ✓
4. Report

    			sim['revenue'] = sim['volume'] * sim['price']

## Overview

1. Read data
2. Simulate
3. Calculate
4. Report ✓

    			cashflows.hist()
    			cashflows.to_excel('report.xlsx')

## Demonstration

## Good things

- Easy to add new farms, crops etc
- Easy to add whole new dimensions (eg. years)
- Easy to add tests
- Less error-prone

## Bad things

- Spreadsheets are easy
- Pandas can be non-intuitive

## Next steps...

https://bitbucket.org/artstr/montepylib

- Draw from distribution based on parameters
- Base case, simulation, sensitivity analysis all with the same code
- Specialised IO
- This talk, & examples

## Questions?

https://bitbucket.org/artstr/montepylib