29
Introduction to Monte C Simulation (using Crystal Ball) 김호 서울대학교 보건대학원

Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

  • Upload
    others

  • View
    2

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

Introduction to Monte Carlo Simulation

(using Crystal Ball)

김 호

서울대학교 보건대학원

Page 2: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

Motivation

• If X ~ N (m1, s12), Y ~ N (m2, s2

2 ),

then what is the distribution of X+Y ?

Statistical theory tells that

X+Y ~ N (m1+ m2, s12+s2

2 )

if X and Y are independent.

How to check this by simulation ?

Page 3: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

data one ;do i=1 to 500;x=rannor(i)*10+ 5 ;y=rannor(i)*5+ 9 ;z=x+y ;output ;end;run;

proc univariate ;var x y z ;histogram x y z /normal (mu=est sigma=est)midpoints = -30 to 45 by 5;;run;

평균 표준편차

X 4.41 10.06

Y 9.33 5.16

Z 13. 11.47

Page 4: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 5: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

평균 표준편차

X 4.41 10.06

Y 9.33 5.16

Z 13. 11.47

결과 이론상

약간 다르다 ?

하나의 처방 --- 반복을 한다.

평균 표준편차

X 5 10

Y 9 5

Z 14 15

Page 6: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

data old ;run;%macro sim ;%do i=0 %to 100 ;%let j=&i*500 ;

data one ;do k=&j to &j+500;x=rannor(k)*10+ 5 ;y=rannor(k+500)*5+ 9 ;z=x+y ;output ;end;run;

proc means noprint ;var x y z ;output out=p mean=mx my mz ;run;data old;set old p ;run;%end;%mend;

%sim;

proc means data=old;var mx my mz;run;

Page 7: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

The MEANS Procedure

Variable N Mean Std Dev

-------------------------------------------------------

mx 101 4.9654381 0.3952677 (5) (4.41)

my 101 8.9910255 0.2253016 (9) (9.33)

mz 101 13.9564636 0.4498997 (14) (13)

---------------------------------------------------------

Page 8: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

• We know the distribution of X+Y from statistical theory.

• How about the other forms like (10*X**2+Y*30+20) / sin(X+Y) We can do some mathematics (mainly approximation)

• More practical way is computer simulation

Page 9: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

data one ;do k=1 to 500;x=rannor(k)*10+ 5 ;y=rannor(k+500)*5+ 9 ;z=(10*X**2+Y*30+20) / sin(X+Y) ;output ;end;run;

proc univariate ;var z ;histogram z /cfill=blue;run;

Page 10: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 11: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

Crystal Ball TutorialFutura Example

1 Start Crystal Ball

2 Open the FUTURA APARTMENT spread sheet from the Crystal Ball Example Folder

3 Choose Run from the Run menu on the menu bar

4 Choose stop from the Run menu on the forecast chart

5 Press the Tab key twice or select the left edit box on the forecast window

6 Type 0 and press the Enter key

Page 12: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 13: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 14: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 15: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 16: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

Crystal Ball TutorialVision Research Example

• A business situation with uncertainty

• Development of new drug designed to correct nearsightedness

• Should complete development and test

• Should be approved by FDA

• Drug effect is marginal

• Use CB to decide whether to scrap or proceed…

Page 17: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

1 Open the VISION RESEARCH spread sheet from the Crystal Ball Example Folder

* Defining Assumptions

1 Click cell C5

2 Choose Define Assumptions from the cell menu

3 Click the Uniform distribution

4 Min=3, Max=5, enter

* Defining Market Cost: Triangular Dist

1 Click cell C6

2 Choose Define Assumptions

3 Click Triangular Dist

4 Click OK

5 Min=12, likeliest=16, Max=18

Page 18: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

* Defining Patients Cured: Binomial Dist

1 Click cell C10

2 Choose Define Assumptions

3 Click Binomial Dist

4 Click OK

5 Prob=.25, Trials=100

• Defining Growth Rate: Customer Dist

1 Click cell C15

2 Define Assumptions

3 Custom Dist

4 Value=0%, Value2=5%, Prob=75%

5 Click enter

Page 19: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

For a Second Range

6 Value=-15%, Value2=-5%, Prob=25%

7 Click enter

• Defining market penetration: Normal

1 Cell C19

2 Define Assumptions -> Normal

3 Mean=8%, SD=2%

4 5% in the left end-point grabber box

• Defining Forecasts

1 C21=C16*C19*C20

2 Define Forecast

3 unit=millions , Display Window OK

Page 20: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

* Calculate Net Profit

4 C23 = IF(C11,C21-C7,-C4-C5)

If the FDA approves the drug (C11 is true) then, then then calculate net profit by subtracting total costs(C7) from gross profit(C21).

However, if the FDA does not approve the drug(C11 is false), then calculate net profit by reducing both development costs (C4) and testing cost(C5) incurred to date.

5 Define Forecast

6 unit=millions, Display Window OK

Page 21: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

* Running a simulation

1 Run Preferences

2 Max # of trials=500, Initial seed=999

Click Use Same Sequence of Random Numbers

• Practice Routine

1 Choose Run from the run menu

2 Choose Stop from the run menu

3 Choose Continue from the run menu

• View the forecast Charts

1 Click on the Gross Profit Run Preferences

Page 22: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

2 Click Open All Forecast

3 Choose Continue from the run menu

• Defining the Certainty Level

1 Range minimum=0, Press enter

2 Range minimum=2, Press enter

3 Range minimum=4, Press enter

Page 23: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 24: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 25: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 26: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 27: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

C23 = IF(C11,C21-C7,-C4-C5)

Page 28: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)
Page 29: Introduction to Monte Carlo Simulation (using Crystal Ball)hosting03.snu.ac.kr/~hokim/seminar/Monte.pdf · 2002-07-03 · Introduction to Monte Carlo Simulation (using Crystal Ball)

C23 = IF(C11,C21-C7,-C4-C5)