Professional Documents
Culture Documents
VBA
Giovanni Zucchinetti
giovanni.zucchinetti@gitec.ch
HEC Lausanne
Computanional Tools for Actuaries (CTA)
1
Agenda
1. General approach
2. Case study
3. Second example
2
Introduction
• Monte Carlo methods are a class of computational algorithms that rely on
repeated random sampling to compute their results.
• Monte Carlo methods are often used in computer simulations of
mathematical systems.
• These methods are most suited to calculation by a computer and tend to
be used when it is infeasible to compute an exact result with a
deterministic algorithm.
• They are used to model phenomena with uncertainty in inputs, such as
the calculation of risk in business.
[Source: Wikipedia]
CTA - G. Zucchinetti 3
Defining Simulation
• Simulation is a software-generated display of a process which one
wants to observe.
• It benefits from trial and error without the cost of materials, labor and
time that would be necessary to observe the same results on the
original process.
• Simulation differs from optimization in that it does not aim to find the
best result for some given inputs.
CTA - G. Zucchinetti 4
Working with Distributions
• Simulation is useful because it can handle variability of
parameters in a model.
CTA - G. Zucchinetti 5
Monte Carlo simulation method
Monte Carlo methods vary, but tend to follow this general pattern :
CTA - G. Zucchinetti 6
Illustration
3 dices game
- Model :
- Possible values for the uncertain input :
- Random number generation :
- Multiple computation of the model :
- Aggregation of results :
Decision :
CTA - G. Zucchinetti 7
1st example
HEC Lausanne
Computanional Tools for Actuaries (CTA)
Case study - Eearly retirement
• Mr X has stopped working at age 55.
• He will be entitled to a pension only from 65
• Inbetween, he will live on a termination capital of CHF 500’000 he
received from his employer.
• His banker advised him to invest it in a « balanced » fund, which has
an expected return of 4%. His banker told that the expected volatility
(standard deviation) is 5% ; the distribution of the returns is
supposed to follow a Normal distribution.
• Mr X wants to withdraw a constant yearly amount.
• He wants help in his decision making on the yearly withdrawal, with
regards to the risk of being short of money before 65.
CTA - G. Zucchinetti 9
Case study - Model
• Inputs
• Formulas
• Results
CTA - G. Zucchinetti 10
Uncertain input
Normal distribution (4% ; 5%)
1.00
1.00
Random numbers
0.90
0.80
0.70
0.60
0.50
0.40
0.30
0.20
0.10
0.00 -
-20%
-8.00%
-5.00%
-2.00%
1.00%
4.00%
7.00%
10.00%
13.00%
16.00%
19.00%
-17.00%
-14.00%
-11.00%
CTA - G. Zucchinetti 11
Generating Random Numbers
• To generate a random number from a particular distribution,
we can use Excel’s inverse distribution functions.
CTA - G. Zucchinetti 12
Rand Num and Dist
• To generate a random number within a given distribution, we
must use the inverse distribution functions.
CTA - G. Zucchinetti 13
Generating Random Numbers
We will use the RAND function as our value for the probability
parameter to generate some number between 0 and 1.
CTA - G. Zucchinetti 14
Excel formula implementation
Capital
Simulation Year
0 1 2 3 4 5 6 7
1 500'000 468'553 444'261 426'399 359'381 298'771 262'951 213'018
2 500'000 480'348 443'924 373'187 353'212 323'840 288'182 239'913
CTA - G. Zucchinetti 15
Aggregating results
Useful Excel functions
- COUNTIF : counts the number of nonblank cells within a range
that meet the given criteria
- https://support.office.com/en-us/article/Excel-functions-by-
category-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb
CTA - G. Zucchinetti 16
Decision criteria
• What’s the possible evolution of the remaining capital ?
CTA - G. Zucchinetti 17
Simulations - Plot
CTA - G. Zucchinetti 18
Confidence levels
Confidence levels
600'000
500'000
400'000 2.50%
300'000 10.00%
200'000 50.00%
100'000 90.00%
- 97.50%
0 1 2 3 4 5 6 7 8 9 10
Years
CTA - G. Zucchinetti 19
Shortfall probability
CTA - G. Zucchinetti 20
CTA - G. Zucchinetti
0%
5%
10%
15%
20%
25%
30%
Histogram
0
9'369
18'737
28'106
37'474
46'843
56'211
65'580
74'948
84'317
93'685
103'054
112'423
121'791
131'160
140'528
149'897
Remaining capital a er 10 years
159'265
168'634
178'002
21
Other indicators that make sense ?
CTA - G. Zucchinetti 22
Simulation with VBA
CTA - G. Zucchinetti 23
Steps
1. Getting the inputs from XL’s sheet
2. Defining the measured variables
3. Initializing the simulation
4. Generating the random element
5. Computing & storing
6. Aggregate results or transfer to XL sheet
CTA - G. Zucchinetti 24
Making Runs and Collecting Data
As seen in the code above, we can use For, Next loops to
generate multiple data values.
We may ask the user how many criteria they want to use for the
simulation.
CTA - G. Zucchinetti 25
Runs and Data
We then need to determine if we will be storing this data and the results
of the specified calculations in arrays or in a spreadsheet.
For speed reasons, it’s better to limit the transfers to the excel file
CTA - G. Zucchinetti 26
2nd example
HEC Lausanne
Computanional Tools for Actuaries (CTA)
Simulation mechanism
px 0.93 (survives)
0.00
CTA - G. Zucchinetti 28
Simulation algorithm
CTA - G. Zucchinetti 29
Simulation algorithm
CTA - G. Zucchinetti 30
Simulation algorithm
CTA - G. Zucchinetti 31
Simulation algorithm
CTA - G. Zucchinetti 32
Simulation - Analyse the data with
Excel
CTA - G. Zucchinetti 33
References
• [Maksay 08] Maksay Gabor, Pigneur Yves, Modéliser par l'exemple, Presses
polytechniques et universitaires romande, 2008,
http://www.ppur.org/produit/290/9782880748951/Modeliser%20par%20lexemple
%20
• [Seref 07] Michelle M.H. Şeref, Ravindra K. Ahuja, and Wayne L. Winston ;
Developing Spreadsheet-Based Decision Support Systems Using Excel and
VBA for Excel ; Dynamic Ideas, Belmont, Massachusetts 2007
CTA - G. Zucchinetti 34