Probabilistic Modeling

Incorporate probabilities into models to be able to directly model uncertainty, and to know not only the most likely outcome but also the chance of different outcomes occurring.

Introduction to Probabilistic Modeling


Notes

  • Probability is a key concept for financial models as it related to risk

  • The base result from a deterministic model only gives a single answer, but does not consider the probability distribution of the result

  • E.g. your model could predict a positive NPV from a project, but through probabilistic modeling you determine that there is a 98% chance the NPV is negative. Do you still want to take the project? This is important information to know when making that decision.

  • We discuss three techniques in this course that take advantage of probability theory: scenario modeling, internal randomness, and Monte Carlo simulation

  • Scenario modeling and Monte Carlo simulation are also methods of exploring the parameter space, just like sensitivity analysis

  • Internal randomness is useful for when the probability is so core to the model that it should be built in from the beginning, rather than extending the base model to add probability

Transcript

  • 00:03: hey everyone
  • 00:04: nick dear verdict here teaching you
  • 00:05: financial modeling today we're going to
  • 00:07: be talking about
  • 00:08: probabilistic modeling this is an
  • 00:11: introduction
  • 00:11: to the topic at the start of our lecture
  • 00:14: series on a topic
  • 00:16: so thus far
  • 00:19: we have built out models that have been
  • 00:23: completely deterministic
  • 00:27: whatever inputs you pass you're going to
  • 00:29: get a certain answer
  • 00:30: as a result and as long as you're
  • 00:32: passing those same inputs you're going
  • 00:34: to get that same output
  • 00:36: as a result further we get one
  • 00:40: result from our model and we don't have
  • 00:43: any understanding
  • 00:45: of the probability of achieving that
  • 00:48: outcome
  • 00:49: it's just kind of the expected outcome
  • 00:53: but it is important um to think about
  • 00:58: the probability of your result
  • 01:01: because probability is strongly related
  • 01:04: to
  • 01:04: risk in finance we're always concerned
  • 01:07: about the
  • 01:08: risk return trade-off we should be
  • 01:10: compensated with additional return
  • 01:12: if we take on additional risk and we
  • 01:15: want to minimize
  • 01:16: risk for a given amount of return
  • 01:20: so thinking about only the baseline
  • 01:23: result
  • 01:23: is kind of like thinking about only the
  • 01:25: return side of things and not
  • 01:27: the risk side of things so
  • 01:31: with probability modeling we can analyze
  • 01:33: the risk of our result the probability
  • 01:35: of different outcomes from our model
  • 01:40: and an example of why you
  • 01:43: should care about this think about a
  • 01:45: situation
  • 01:46: where you have some capital budgeting
  • 01:49: project
  • 01:50: and you have calculated the mpv of that
  • 01:53: project
  • 01:54: and ultimately you see that the mpv
  • 01:58: is positive so you think okay i should
  • 02:00: take the project
  • 02:02: but now you start analyzing the
  • 02:05: different
  • 02:06: possibilities for the inputs in your
  • 02:07: model and you ultimately are able to
  • 02:09: come up
  • 02:10: with a probability distribution of the
  • 02:13: result
  • 02:14: and you find that 98 of the time the npv
  • 02:18: is negative
  • 02:19: two percent of the time the mpv is
  • 02:21: positive enough
  • 02:22: that it makes the overall expected mpv
  • 02:25: positive
  • 02:27: is this still a project that you want to
  • 02:28: take on when 98 of the time
  • 02:31: it's going to be a value losing
  • 02:33: proposition
  • 02:34: maybe maybe not but that's something
  • 02:36: that you should be considering
  • 02:38: when you decide whether to take the
  • 02:40: project not only
  • 02:42: just the baseline uh npv expected
  • 02:46: from the baseline model
  • 02:50: and then going even further with this
  • 02:53: we can also think about not only just
  • 02:56: uh the expected outcome or a probability
  • 02:59: distribution
  • 03:00: of outcomes from our model we can also
  • 03:03: think about different scenarios and that
  • 03:05: can be powerful to understand
  • 03:07: different situations that we could end
  • 03:09: up in
  • 03:11: so the most common application of
  • 03:14: looking at scenarios
  • 03:15: is to think about uh the state of the
  • 03:19: economy
  • 03:19: are we in a recession are we in a normal
  • 03:22: economy or are we an expansionary period
  • 03:25: and that can have a lot of effect on the
  • 03:27: outcome from a financial
  • 03:29: model so it can be useful to think about
  • 03:32: these cases separately
  • 03:33: that you can say well if we had a
  • 03:35: recession then we can expect this kind
  • 03:37: of outcome
  • 03:38: but if we stay in this normal economy
  • 03:40: then we're going to expect this kind of
  • 03:42: outcome so it can help you frame your
  • 03:43: thinking about the problem in different
  • 03:45: situations or scenarios
  • 03:49: um and uh
  • 03:53: yeah the reason we care so much about
  • 03:56: risk and finance is because
  • 03:57: there's a lot of randomness going on in
  • 03:59: the real world you never
  • 04:01: know truly what is going to happen and
  • 04:04: really there's not going to be one
  • 04:06: outcome that's just always going to
  • 04:07: occur
  • 04:08: it can be any set of outcomes um and you
  • 04:11: want to understand the chance of each of
  • 04:13: those outcomes
  • 04:14: and not only the one that you expect to
  • 04:16: happen
  • 04:20: so there's a few different ways that we
  • 04:21: can incorporate
  • 04:23: probability into our financial models
  • 04:27: so we started to already touch on a
  • 04:29: little bit scenario modeling
  • 04:32: where we think about different possible
  • 04:34: situations we could end up in
  • 04:36: a recession neutral economy expansion
  • 04:39: economy
  • 04:40: or whatever other different scenarios
  • 04:42: you want to think about
  • 04:45: and we basically take all the inputs of
  • 04:48: the model
  • 04:49: and think about what would be the values
  • 04:51: of these inputs
  • 04:53: in each of these situations or scenarios
  • 04:55: so in a bad economy
  • 04:57: what's going to be interest rate what's
  • 04:59: going to be the savings rate
  • 05:00: etc whatever inputs are relevant to your
  • 05:02: model
  • 05:04: and kind of lining up all the inputs for
  • 05:06: that situation
  • 05:08: to see what the outcome is when all
  • 05:09: those inputs align with that situation
  • 05:13: and then you can assign probabilities to
  • 05:16: each of these cases
  • 05:18: and you can take an expected value to
  • 05:19: determine uh
  • 05:21: what you expect to happen based off of
  • 05:23: your scenarios
  • 05:27: so then the next method we'll talk about
  • 05:29: is internal randomness
  • 05:31: and internal randomness the
  • 05:35: randomness or probability is included
  • 05:38: directly into the model itself
  • 05:40: there's something core about the model
  • 05:43: which uses
  • 05:44: this randomness or chance
  • 05:48: maybe you have like an investment model
  • 05:51: where the investment return is going to
  • 05:53: be random each year
  • 05:55: with some parameters
  • 05:58: or something like that so it's built
  • 06:00: into the main model itself
  • 06:03: and the last that we'll talk about in
  • 06:05: the course is monte carlo simulation
  • 06:08: and monte carlo simulation we'll dig
  • 06:11: into that a lot more in a future lecture
  • 06:13: but uh the basic idea is for each one of
  • 06:17: our inputs we're going to assign a
  • 06:18: probability distribution
  • 06:20: to each of those inputs so that each
  • 06:22: time you run the model you get a
  • 06:23: different value of each one of those
  • 06:24: inputs
  • 06:25: based on the distributions and
  • 06:28: then by doing that we run the model a
  • 06:30: whole bunch of times
  • 06:32: and we get the results from all those
  • 06:34: and that allows us to get a probability
  • 06:36: distribution
  • 06:37: of the results from the model as well
  • 06:40: so that is what will allow us to say you
  • 06:43: know there's
  • 06:44: a 37 chance that we'll have a positive
  • 06:47: mpv
  • 06:49: and statements like that so
  • 06:53: and then monte carlo simulation and
  • 06:56: scenario modeling
  • 06:57: are both other methods of exploring the
  • 07:00: parameter space
  • 07:01: just like sensitivity analysis
  • 07:04: whereas internal randomness is just a
  • 07:07: particular feature
  • 07:08: of the model that you're building it's
  • 07:10: actually built into the base model
  • 07:12: itself
  • 07:13: rather than be an extension of the model
  • 07:17: so that's a quick overview of
  • 07:20: probabilistic
  • 07:21: modeling and how it relates to financial
  • 07:24: models
  • 07:25: we'll come back next time to do a quick
  • 07:28: math review
  • 07:29: um on the mathematical tools that we
  • 07:31: need
  • 07:32: to work with probability and our models
  • 07:35: so thanks for listening and see you next
  • 07:39: time

Math Review for Probabilistic Modeling


Notes

  • Discrete variables: specific values, continuous variables: range of values. Note that an underlying variable can be continuous but the modeler can choose to make it discrete within the model to simplify it. E.g. condition of the economy is continuous, but you might make it discrete by classifying the economic conditions into recession, neutral, or expansion. This does not work in the other direction: a variable which is truly discrete cannot be made continuous

  • Expected value is a key concept in probability theory. We will use it in scenario analysis to get the expected outcome across multiple different cases of the inputs

  • The variance graph shows two series with the same mean but different variances. Variance is a measure of how much the value is moving around. If it moves a lot, it has high variance. Variance has nothing to do with the average, mean, or expected value.

  • Probability distributions tell you how likely it is to observe different values of a given variable

  • Discrete variables: think table of values with probabilities. Continuous variables: think curve, usually displayed by a graph but defined by a function

  • The CLT is extremely powerful, because of it most of the distributions for continuous variables are normal distributions. So if we need to pick a distribution for a variable, the normal distribution is reasonable choice the majority of the time

Transcript

  • 00:02: hey everyone
  • 00:03: nick dear burtis here teaching you
  • 00:05: financial modeling today we're going to
  • 00:07: be doing
  • 00:08: a math review as we get into our
  • 00:11: lecture segment on probabilistic
  • 00:14: modeling so
  • 00:16: we talked last time about the
  • 00:20: introduction to probabilistic modeling
  • 00:21: what's it all about why do we want to do
  • 00:23: it
  • 00:24: now let's look at some mathematical
  • 00:26: tools that we need
  • 00:27: to be able to carry out this
  • 00:30: probabilistic modeling adding
  • 00:31: probability to our financial models
  • 00:35: so the first concept we'll look at here
  • 00:39: is
  • 00:40: about random variables and whether that
  • 00:44: random variable is
  • 00:45: discrete or continuous
  • 00:48: so discrete variables are
  • 00:51: having a certain set of values it's it's
  • 00:54: one of a certain set of values
  • 00:57: whereas continuous variables are defined
  • 00:59: by a range
  • 01:00: it's between two values
  • 01:04: and it can be any number between those
  • 01:06: two values
  • 01:08: um so you know something like
  • 01:12: an interest rate you can think of as
  • 01:14: continuous
  • 01:15: the rate could be six six percent it
  • 01:18: could be six point one percent it could
  • 01:19: be six point one one percent
  • 01:21: six point one one one one et cetera you
  • 01:23: can keep
  • 01:24: uh finding additional numbers in that
  • 01:26: range it can be any number
  • 01:28: in the range of of possible reasonable
  • 01:31: percentages
  • 01:32: [Music]
  • 01:34: so and then discrete variables
  • 01:37: um taking one of a specific set
  • 01:40: of values um
  • 01:42: [Music]
  • 01:44: so it could be something like um
  • 01:48: an example is maybe a boolean variable
  • 01:51: like uh
  • 01:52: take the project or don't take the
  • 01:53: project that only has two possible
  • 01:55: values
  • 01:56: uh yes i'm taking it or no i'm not
  • 01:58: taking it
  • 01:59: [Music]
  • 02:02: and then you can
  • 02:06: read continuous variables as discrete
  • 02:10: in your model if it's helpful to
  • 02:12: simplify things
  • 02:14: like even though interest rate is
  • 02:17: continuous
  • 02:18: you might say uh it's only going to take
  • 02:21: the values of five six
  • 02:22: or seven percent and then all of a
  • 02:24: sudden it becomes a discrete variable
  • 02:26: in your model even though it's truly a
  • 02:28: continuous variable
  • 02:30: um but you cannot go in the other
  • 02:32: direction you cannot take a discrete
  • 02:34: variable
  • 02:35: and make it into a continuous variable
  • 02:38: in your model
  • 02:43: then thinking about expected value
  • 02:46: expected value
  • 02:47: is the average outcome over repeated
  • 02:50: trials so it's the way that we can think
  • 02:53: of
  • 02:54: the outcome that we expect to happen um
  • 02:58: you know if you want to be able to put
  • 03:01: what's going to happen into a single
  • 03:02: number
  • 03:03: that's the expected value now it's not
  • 03:06: going to be able to capture
  • 03:08: the risk of that result at all
  • 03:12: you know kind of what we've got coming
  • 03:13: out of our
  • 03:15: original determine original
  • 03:17: deterministic models is basically like
  • 03:19: an expected value
  • 03:21: um but it only gives us a very small
  • 03:24: understanding
  • 03:24: of the distribution of possible results
  • 03:28: but it's still very helpful to be able
  • 03:29: to give a single number
  • 03:31: which sums up the outcome that we're
  • 03:33: expecting
  • 03:36: so the calculation of it is a little bit
  • 03:39: different
  • 03:40: depending on whether the variable is
  • 03:42: discrete or continuous
  • 03:44: so with a discrete variable you take
  • 03:47: each possible outcome and you multiply
  • 03:50: it by the probability
  • 03:52: of that outcome and then you sum each of
  • 03:55: those terms up
  • 03:57: whereas with continuous it's just an
  • 04:00: average
  • 04:01: across the outcomes which have occurred
  • 04:06: um so we'll look at applying
  • 04:10: both of these in our models throughout
  • 04:13: the course
  • 04:17: um and then thinking about variance
  • 04:21: so variance is what we're usually
  • 04:24: talking about when we think about the
  • 04:26: risk
  • 04:27: of a result so variance is about how
  • 04:30: much
  • 04:31: the result is moving around how much
  • 04:34: does it change
  • 04:35: from one occurrence to the next etc
  • 04:39: so this picture i think captures the
  • 04:41: concept of variance very well
  • 04:44: and that we have two different random
  • 04:46: variables here
  • 04:48: plotted across the different instances
  • 04:51: occurrences
  • 04:52: of the random variable and
  • 04:55: those two variables have the same exact
  • 04:58: mean or average or expected value
  • 05:01: where they differ is they have different
  • 05:03: variances and you can look at that and
  • 05:05: you can clearly see those two lines look
  • 05:06: different
  • 05:08: but you can also see on average they're
  • 05:10: both
  • 05:11: basically around zero uh the orange line
  • 05:14: is of course
  • 05:15: moving up and down a lot more but it's
  • 05:17: still basically centered around zero
  • 05:20: so where is centered that's the average
  • 05:22: or expected value that's the mean
  • 05:25: and then the variance is how much it
  • 05:26: moves around that mean so the orange
  • 05:28: line is moving a lot around it
  • 05:30: as a high variance the blue line is
  • 05:32: moving a small around around it it has a
  • 05:34: small variance
  • 05:38: and then as far as the calculation
  • 05:41: um so for
  • 05:45: a uh we'll just look at a continuous
  • 05:49: variable here that's typically where
  • 05:51: you're going to need to do that
  • 05:54: um so there's the formula there for
  • 05:58: the variance of a continuous variable
  • 06:00: each
  • 06:02: occurrence minus the average summed up
  • 06:05: and then multiplying that
  • 06:07: by one over n minus one is going to get
  • 06:09: us the variance
  • 06:12: um and then
  • 06:16: we typically talk about variance in
  • 06:18: terms of
  • 06:20: standard deviation rather than
  • 06:23: the variance
  • 06:28: and that's because the variance
  • 06:32: actually has units in
  • 06:35: squared terms of the original variable
  • 06:38: whereas the standard deviation has units
  • 06:42: in the original terms of the variable um
  • 06:48: so the um
  • 06:52: the reason you know being that um
  • 06:55: you think about you've got like an
  • 06:57: investment return
  • 06:59: um say it has an average of six percent
  • 07:03: um it's going to be moving around that
  • 07:06: six percent
  • 07:07: with ease observation based on the
  • 07:09: variance or standard deviation
  • 07:12: and you might say it has a standard
  • 07:13: deviation of two percent
  • 07:15: and so then you would expect most of the
  • 07:17: values to lie between like four and
  • 07:18: eight percent
  • 07:20: um sometimes they're going out to like
  • 07:22: two to ten percent
  • 07:24: and rarely they're going out to zero to
  • 07:27: uh twelve percent
  • 07:31: whereas the uh variance for that would
  • 07:34: then be like
  • 07:34: point zero zero zero four because it's
  • 07:37: squared percentage
  • 07:40: uh which is a weird unit to work with
  • 07:42: and
  • 07:43: is hard to understand in terms of our
  • 07:45: original variable
  • 07:47: so that's why we just take the square
  • 07:48: root of variance and that gets us
  • 07:51: the standard deviation
  • 07:55: and there is actually a squared term
  • 07:58: missing on this formula there should be
  • 07:59: a squared there
  • 08:01: and that's why we get the squared units
  • 08:06: so then moving on to the
  • 08:10: probability distributions is the next
  • 08:12: concept
  • 08:14: so probability distributions tell you
  • 08:17: about the likelihood of different
  • 08:19: outcomes
  • 08:20: of a given random variable
  • 08:23: [Music]
  • 08:24: and the way that it looks is different
  • 08:27: depending on whether it's a discrete
  • 08:29: or a continuous variable so
  • 08:32: for a discrete variable you can
  • 08:34: basically think of
  • 08:36: the probability distribution being a
  • 08:38: table
  • 08:39: where we have each possible outcome in
  • 08:41: the table and then each probability
  • 08:43: associated with each of those outcomes
  • 08:47: and that defines the probability
  • 08:49: distribution because there's only a
  • 08:50: fixed number of possible values you just
  • 08:52: put
  • 08:53: a percentage to each and then you have a
  • 08:56: probability distribution
  • 08:59: for continuous variables it's going to
  • 09:02: be in the form of a curve
  • 09:03: instead and so typically those are
  • 09:05: represented by a graph
  • 09:07: rather than with a table because there's
  • 09:10: actually a
  • 09:11: function which takes the
  • 09:15: which converts the probability into the
  • 09:19: outcome
  • 09:20: and that's what defines the probability
  • 09:23: distribution
  • 09:25: um but you can just know that it's
  • 09:28: continuous it's going to be formed by a
  • 09:30: curve um
  • 09:32: and higher points on that curve means a
  • 09:35: more likely
  • 09:37: outcome
  • 09:42: so then we're talking specifically about
  • 09:46: the normal distribution as a type of
  • 09:48: probability distribution
  • 09:49: for continuous variables and you've
  • 09:52: probably heard about the normal
  • 09:53: distribution before
  • 09:55: because it's very common in nature
  • 09:58: and that's because of the central limit
  • 10:01: theorem which is
  • 10:02: extremely powerful and important which
  • 10:05: says
  • 10:05: that any average of random variables
  • 10:10: is going to be normally distributed
  • 10:12: regardless
  • 10:13: of the distribution of those original
  • 10:16: random variables that you averaged
  • 10:19: and that's that's very very powerful
  • 10:20: because all of a sudden
  • 10:22: no matter what that crazy distribution
  • 10:24: there is in the original variable
  • 10:26: you just average it across a few
  • 10:28: different
  • 10:29: sets and then you've got a normal
  • 10:32: distribution
  • 10:34: which we know how to work with um
  • 10:37: so this has tons and tons of
  • 10:38: applications
  • 10:40: for example thinking about an investment
  • 10:43: return
  • 10:44: um you know what's the true distribution
  • 10:47: of any individual
  • 10:48: investment it's really hard to say
  • 10:52: but for an investment return we can view
  • 10:55: that as the return on a portfolio of
  • 10:57: investments
  • 10:58: where each of those individual
  • 10:59: investments is itself
  • 11:01: a random variable and
  • 11:04: those distributions can be whatever they
  • 11:06: are but by the time we take those all
  • 11:08: and put them into a portfolio return
  • 11:10: it's averaging across the individual
  • 11:12: investments
  • 11:13: now our portfolio return has a normal
  • 11:15: distribution regardless
  • 11:16: of the distributions of the original
  • 11:19: returns
  • 11:21: so kind of the outcome from that is that
  • 11:25: the majority of the time we can use a
  • 11:28: normal distribution and it's going to be
  • 11:29: a good
  • 11:31: choice of distribution or whatever
  • 11:33: random variable
  • 11:34: that we're looking at because most
  • 11:36: variables can be thought of
  • 11:38: an aggregation of uh
  • 11:41: more individual random variables
  • 11:45: so if you're not sure what distribution
  • 11:47: to pick just pick the normal
  • 11:49: distribution
  • 11:50: and most the time that's going to be a
  • 11:52: reasonable assumption
  • 11:56: um so then this this uh slide
  • 12:00: is just um hitting home
  • 12:04: this concept of discrete versus
  • 12:05: continuous and how you can
  • 12:07: treat a continuous variable as discrete
  • 12:09: within your model
  • 12:11: or you can treat it as continuous
  • 12:14: and this is basically saying that we
  • 12:16: would take our existing
  • 12:18: retirement model instead of just having
  • 12:20: interest rate
  • 12:21: as an input one particular value
  • 12:25: we can make it a random variable in the
  • 12:27: model so we can either
  • 12:29: treat it as continuous and draw that
  • 12:33: return from a normal distribution with a
  • 12:35: certain average
  • 12:36: and a certain uh variance or standard
  • 12:39: deviation
  • 12:41: so we could say it's it's going to be
  • 12:42: five percent with a two percent
  • 12:44: five percent mean two percent standard
  • 12:46: deviation normal distribution
  • 12:48: um or we can treat it as a discrete
  • 12:51: variable
  • 12:52: here we've got three different possible
  • 12:54: values for the interest rate
  • 12:56: and three different probabilities for
  • 12:58: each so this is also
  • 13:01: showing you how the difference in the
  • 13:03: probability distributions are when you
  • 13:04: treat it as continuous versus discrete
  • 13:07: discrete we've got a table with the
  • 13:09: probabilities associated with the
  • 13:11: outcomes and continuous it's defined by
  • 13:14: a distribution
  • 13:17: so that concludes the math review for
  • 13:20: probabilistic
  • 13:20: modeling we'll come back next time to
  • 13:23: talk about scenario analysis
  • 13:26: so thanks for listening and see you next
  • 13:29: time

Introduction to Scenario Analysis


Notes

  • Scenario modeling is another way to explore the parameter space, just like sensitivity analysis

  • Scenario modeling is carried out in the same way as sensitivity analysis: run the model with each set of inputs and display the outputs with the inputs

  • The difference is that unlike in sensitivity analysis where we tweak one input at a time, in scenario analysis, we consider some situations and determine all the values of the inputs that align with each situation

  • We can also optionally assign probabilities to the situations, then take an expected value to get an expected outcome from our model

  • Internal vs. external scenario analysis is just about whether the scenarios are included in the core model (internal), or as an extension to the base model (external)

Transcript

  • 00:03: hey everyone
  • 00:04: nick dear burtis here teaching you
  • 00:05: financial modeling today we're going to
  • 00:07: be doing an introduction
  • 00:09: to scenario analysis this is part of our
  • 00:13: lecture segment on probabilistic
  • 00:15: modeling
  • 00:16: so last time we finished up the math
  • 00:20: review
  • 00:20: which is allowing us to work with
  • 00:23: probability in our models
  • 00:25: and now we're going to look at the first
  • 00:26: application of probability modeling
  • 00:29: which is scenario modeling or scenario
  • 00:31: analysis
  • 00:34: so the whole idea behind scenario
  • 00:37: modeling
  • 00:38: is you want to come up with different
  • 00:39: situations
  • 00:41: or scenarios which are relevant to your
  • 00:44: model
  • 00:45: and kind of the classic example for
  • 00:48: scenario analysis is to think about the
  • 00:51: state of the economy
  • 00:53: are we in a recession are we in a normal
  • 00:55: period are we an expansion period
  • 00:58: and that's the classic example because
  • 01:01: the state of the economy will affect
  • 01:03: nearly every financial model and so it's
  • 01:07: a natural choice
  • 01:08: a natural thing to look at in scenario
  • 01:11: analysis
  • 01:12: now you can also pick other scenarios
  • 01:15: which are relevant to whatever you're
  • 01:17: analyzing
  • 01:18: maybe it's some project some capital
  • 01:20: budgeting
  • 01:22: model you're evaluating some project and
  • 01:25: there is different things that could
  • 01:27: occur once you are working on the
  • 01:28: project
  • 01:29: um you know maybe you're a
  • 01:34: firm that's that's mining a mine and
  • 01:37: there are different scenarios for
  • 01:39: uh how much gold you find in the mine
  • 01:42: or you know whatever is appropriate for
  • 01:45: the problem that you're working on
  • 01:46: whatever is relevant
  • 01:47: to think about as far as different
  • 01:49: situations
  • 01:52: but here looking at the city of the
  • 01:53: economy is going to apply to
  • 01:55: most models
  • 01:58: and so the idea behind scenario analysis
  • 02:02: is that we're going to think about each
  • 02:04: one of these different situations
  • 02:06: here recession normal expansion economy
  • 02:10: and we're going to say let's look at all
  • 02:12: the different inputs of the model
  • 02:14: and what values of the inputs make sense
  • 02:17: in that situation
  • 02:19: so in a recession you're going to be
  • 02:21: earning a
  • 02:24: lower interest rate
  • 02:27: and then here it really depends on the
  • 02:32: individual
  • 02:33: whether they would be saving more or
  • 02:34: saving less in a recession
  • 02:36: if you're very financially constrained
  • 02:38: you would probably be saving less
  • 02:39: because you're probably earning less and
  • 02:41: you need to pay your expenses
  • 02:43: um but if you're more financially well
  • 02:46: off you might save more in a recession
  • 02:48: just because
  • 02:50: uh you're kind of worried about the
  • 02:52: state of things
  • 02:53: so you're going to save in response to
  • 02:55: that
  • 02:56: so let's go with that case and say that
  • 03:00: that for this person that we're modeling
  • 03:03: the savings rate is also going to be
  • 03:05: higher during a recession
  • 03:07: and you would want to do that for all
  • 03:09: the other inputs in the model as well
  • 03:11: what makes sense in a recession and line
  • 03:13: all those up
  • 03:15: and then go to thinking about the normal
  • 03:16: economy interest rates going to go up
  • 03:19: savings rates going to go down and think
  • 03:21: about all the other inputs as well
  • 03:22: same thing for the expansion economy
  • 03:25: whatever situations that you have
  • 03:27: think about them separately and all the
  • 03:29: inputs that make sense
  • 03:30: for that particular situation
  • 03:34: um and then the idea is then to run the
  • 03:37: model
  • 03:38: with each of these different sets of the
  • 03:39: inputs and look at the outcomes
  • 03:42: and you can stop there and not
  • 03:46: uh work the probability modeling side of
  • 03:48: it you can just say
  • 03:50: this is my number for a recession this
  • 03:52: is my normal
  • 03:53: number for a normal economy this is it
  • 03:54: for the expansion economy
  • 03:57: uh but where we can work probability in
  • 03:59: here is then we can also assign a
  • 04:00: probability to each one of these cases
  • 04:04: so then the different scenarios
  • 04:07: are a discrete variable here and we
  • 04:10: now have a probability distribution for
  • 04:12: those scenarios
  • 04:14: by just assigning a probability to each
  • 04:16: case
  • 04:17: here we're saying 30 recession 50 normal
  • 04:20: economy
  • 04:20: 20 expansion economy
  • 04:24: and what that allows you to do is then
  • 04:26: take an expected value
  • 04:27: across the different cases to get an
  • 04:30: expected outcome from your model that's
  • 04:32: uh separate from the baseline result but
  • 04:35: maybe more realistic
  • 04:36: because you've thought about scenarios
  • 04:39: rather than
  • 04:40: just the most likely value of each input
  • 04:47: so
  • 04:50: [Music]
  • 04:51: then as far as implementing scenario
  • 04:53: modeling so there's two main
  • 04:55: approaches here to go about it whether
  • 04:58: you implement it
  • 04:59: internally or externally to your
  • 05:02: model and the distinction here
  • 05:06: is just about we've already been talking
  • 05:09: about
  • 05:10: this concept of the base model which
  • 05:12: gives you the basic result
  • 05:13: and then extensions to the model where
  • 05:16: you can explore the parameter space and
  • 05:17: do other things
  • 05:19: um to get a better understanding of the
  • 05:21: results from your model
  • 05:23: so internal means put it in the base
  • 05:26: model itself
  • 05:27: external means do it as part of those
  • 05:30: extensions
  • 05:31: to the existing model
  • 05:35: so if it's internal then you have
  • 05:38: these different situations cases of the
  • 05:41: inputs within the model itself
  • 05:44: and then within the model it's going to
  • 05:45: take an expected value
  • 05:47: across those and now
  • 05:51: depends on where you're using it it
  • 05:52: could be that um
  • 05:54: it's doing that for the inputs and now
  • 05:56: you get an expected value of each input
  • 05:58: or it could be at the end of the model
  • 06:00: and you're getting expected value across
  • 06:01: the different cases
  • 06:02: as your output from the model um
  • 06:06: there's a number of different ways to
  • 06:07: apply it but the key distinction is that
  • 06:10: it's within your basic model any other
  • 06:12: extensions to your model
  • 06:14: are now going to be uh
  • 06:18: outside of that scenario analysis as in
  • 06:20: there's going to be scenario analysis
  • 06:22: included within
  • 06:23: any other extensions to the model as
  • 06:25: well
  • 06:28: whereas with the external implementation
  • 06:31: you take that base model and you don't
  • 06:33: change anything about it
  • 06:36: you then extend it with scenario
  • 06:38: analysis
  • 06:39: separately so there your basic model
  • 06:43: just takes the inputs and returns the
  • 06:46: outputs corresponding those inputs
  • 06:48: but now you look at the different cases
  • 06:50: different situation scenarios
  • 06:54: and run the model with each of those
  • 06:55: different scenarios and get the results
  • 06:58: from that
  • 07:02: and then here's um
  • 07:06: sort of the pros and cons of
  • 07:09: internal versus external scenario
  • 07:11: analysis
  • 07:13: um this is talking about
  • 07:16: taking an existing model and then adding
  • 07:19: scenario analysis to it
  • 07:21: um so for internal
  • 07:25: um an advantage to the external
  • 07:28: approach is that the original model is
  • 07:30: still as it was
  • 07:32: you can still use it as you were before
  • 07:34: doing the scenario analysis
  • 07:35: you can do other extensions which are
  • 07:38: not
  • 07:38: having to also run the scenario analysis
  • 07:42: so it's more kind of flexible and
  • 07:45: extensible that way whereas you go with
  • 07:48: the internal
  • 07:50: then what you have before is now an old
  • 07:52: version of the model
  • 07:53: now you have this new version which has
  • 07:55: the scenario analysis
  • 07:56: baked in and now those two things are
  • 07:59: inherently entwined and anything else
  • 08:01: you do with the model is going to be
  • 08:02: running that scenario analysis
  • 08:04: as well
  • 08:07: um then next is an advantage to
  • 08:12: internal scenario analysis where
  • 08:15: you don't have to do anything different
  • 08:17: about running the model
  • 08:19: uh you just pass in the inputs as you
  • 08:21: were before you get the output as you
  • 08:23: were before
  • 08:24: and now it has sensitivity analysis
  • 08:26: running within it
  • 08:28: whereas with the external now you're
  • 08:30: talking about running the model multiple
  • 08:32: times
  • 08:33: with each of these different sets of
  • 08:35: inputs and collecting the output
  • 08:37: and associating that together so it
  • 08:39: becomes a little more complicated to
  • 08:41: run the model with external scenario
  • 08:45: analysis
  • 08:47: [Music]
  • 08:48: and then the next one is an advantage to
  • 08:51: external where
  • 08:52: the base model is completely unchanged
  • 08:55: it's exactly as complex as it was before
  • 08:59: whereas adding sensitivity analysis into
  • 09:01: the base model
  • 09:02: is making it more complex there's more
  • 09:04: things going on
  • 09:06: within the model and that can make it
  • 09:07: more difficult to work on the base model
  • 09:10: going forward
  • 09:13: um and then the last is an advantage to
  • 09:18: internal um where
  • 09:21: this you know pretty much is um very
  • 09:24: similar to this point it's more complex
  • 09:26: to run the model
  • 09:27: uh with external and exactly the same to
  • 09:31: run it as before
  • 09:32: with internal and so
  • 09:37: kind of my main recommendations here
  • 09:39: you're gonna go
  • 09:40: and build scenario analysis in your
  • 09:42: model should it be internal should it be
  • 09:44: external
  • 09:46: the main considerations to me are if
  • 09:48: you've already built out the full model
  • 09:51: that's already like a big push towards
  • 09:53: doing external because your
  • 09:54: original model works you don't want to
  • 09:56: go and have to rework the whole thing
  • 09:59: it's much easier to add external on top
  • 10:01: of
  • 10:02: your existing model
  • 10:05: um and then where i would say you should
  • 10:09: use internal
  • 10:10: is um well you should go more in that
  • 10:13: direction if you're starting the model
  • 10:15: from scratch and you know you want to
  • 10:16: have scenario analysis
  • 10:18: it could make sense to put it into the
  • 10:19: base model
  • 10:21: um but i would also only do that
  • 10:24: if you think that scenario analysis is
  • 10:26: very core
  • 10:28: to the problem that you're trying to
  • 10:29: solve you know if uh
  • 10:32: thinking about states of the economy is
  • 10:34: very important for the outcomes of your
  • 10:36: model
  • 10:37: maybe it makes sense to build that in
  • 10:38: from the get go whereas
  • 10:40: for a standard model it's probably fine
  • 10:43: to just have that externally as kind of
  • 10:46: a check on things and looking at it in
  • 10:48: different situations
  • 10:54: so that gives an overview of scenario
  • 10:57: analysis
  • 10:58: and we'll come back next time to look at
  • 11:00: implementing
  • 11:01: scenario analysis in excel so thanks for
  • 11:05: listening
  • 11:05: and see you next time

Scenario Analysis in Excel


Notes

  • We will focus on external scenario analysis for the purpose of this exercise

  • Typically if the model has already been created, you should opt for external rather than internal

  • Unfortunately without some hacks, in Excel we are limited to examining two inputs changing at once with external scenario analysis, as a data table is used to run the model repeatedly

  • We will see that we do not have this limitation in Python, and later in the course we will see that you can use Python to run external scenario analysis on your Excel model with any number of inputs

Transcript

  • 00:03: hey everyone
  • 00:03: nick dearborn is here teaching you
  • 00:05: financial modeling today
  • 00:07: we're going to be looking at
  • 00:08: implementing scenario analysis
  • 00:10: in excel this is part of our lecture
  • 00:13: series
  • 00:14: on probabilistic modeling so
  • 00:17: we gave an introduction to scenario
  • 00:19: modeling last time
  • 00:21: now we're going to come in and look at
  • 00:23: how to specifically
  • 00:24: implement that in excel
  • 00:28: so when doing internal scenario analysis
  • 00:31: um you're setting up a table of the
  • 00:34: cases
  • 00:35: and the probabilities and then you're
  • 00:37: going to calculate the expected value
  • 00:40: across the cases for each one of the
  • 00:42: inputs
  • 00:43: and then that expected value is going to
  • 00:45: become the new
  • 00:47: input into the model uh rather than what
  • 00:50: was there
  • 00:52: whereas external scenario analysis we've
  • 00:55: got the existing model we're going to
  • 00:57: leave that untouched
  • 01:00: and then we'll extend it by using a data
  • 01:03: table
  • 01:06: so the data table you would
  • 01:09: look at the different possibilities of
  • 01:12: each of the inputs
  • 01:14: and get the outcomes for all of those
  • 01:18: and then you create a separate table
  • 01:19: which has the cases and the
  • 01:21: probabilities
  • 01:22: and references the information from the
  • 01:25: data table
  • 01:26: to fill out the outcomes um
  • 01:31: now the big drawback there with the way
  • 01:34: that
  • 01:35: you have to implement this in excel with
  • 01:37: the data table is that you can only
  • 01:39: change two inputs at once
  • 01:41: with a data table um
  • 01:45: and so if you want to look at more than
  • 01:46: two inputs then you have to get to some
  • 01:49: pretty hacky
  • 01:49: kind of approaches um
  • 01:53: you know some kind of vlookup kind of
  • 01:55: approach where you have a case number
  • 01:57: and then case number corresponds to a
  • 01:58: bunch of different values of inputs
  • 02:00: something like that um
  • 02:04: but uh not very straightforward to do
  • 02:08: that
  • 02:09: we'll see later that we do not have the
  • 02:11: same restriction in python we can do it
  • 02:13: with as many
  • 02:15: different inputs as we want in python
  • 02:17: without any issues
  • 02:19: and we'll also see later in the course
  • 02:21: as we get into combining
  • 02:23: excel in python that you can take your
  • 02:27: existing excel model
  • 02:28: and you can use python to run the
  • 02:30: scenario analysis
  • 02:31: on it with any number of inputs
  • 02:35: so that will be a pretty good option for
  • 02:38: running this in excel with more than two
  • 02:40: inputs
  • 02:44: so now let's look at the existing
  • 02:46: dynamic salary retirement model and how
  • 02:49: we can add
  • 02:50: scenario analysis to that
  • 02:57: so we've got our existing dynamic salary
  • 03:00: retirement model
  • 03:03: and you can find the completed example
  • 03:05: here on the course site
  • 03:07: as well uh with scenario analysis
  • 03:09: already implemented and all the
  • 03:10: formatting just right and everything
  • 03:14: um so the first thing that i'm going to
  • 03:16: do is i'm going to add
  • 03:18: some additional inputs here
  • 03:22: so we're going to have scenario analysis
  • 03:26: inputs and those are going to be the
  • 03:30: economic condition probabilities here
  • 03:32: we're going to look at
  • 03:34: [Music]
  • 03:35: a bad neutral and good economy
  • 03:39: [Music]
  • 03:43: bad neutral good economy
  • 03:46: um but we don't need to define all three
  • 03:49: probabilities because they have sum up
  • 03:51: to 100
  • 03:52: so i'm gonna just define the bad and
  • 03:55: good
  • 03:57: probabilities um
  • 04:00: and then you know you would want to
  • 04:01: update the formatting so that all of
  • 04:03: this is included in a table the
  • 04:04: formatting of these matches the
  • 04:06: formatting of this
  • 04:07: you can find all that in the completed
  • 04:09: example on the course site
  • 04:11: but in interest of time i'm just going
  • 04:13: to leave it like this
  • 04:16: um so then the next thing we want to do
  • 04:19: is we want to start
  • 04:20: creating our table which has the
  • 04:24: different cases and the probabilities
  • 04:27: and
  • 04:28: the different values of the inputs we
  • 04:29: want to look at in those cases
  • 04:33: so this would be a scenario analysis
  • 04:36: table
  • 04:37: um and we're going to be looking at the
  • 04:40: economic condition
  • 04:43: as bad normal good
  • 04:46: and we can get the expected as well
  • 04:51: um and then we're going to have the
  • 04:54: probability next
  • 04:56: and we can reference the bad economy
  • 04:59: probability
  • 05:00: the good economy probability and the
  • 05:03: normal
  • 05:04: can be uh one minus each of those
  • 05:08: two probabilities
  • 05:11: whoops minus each of those probabilities
  • 05:17: um that way we can change the
  • 05:19: probabilities and everything updates
  • 05:22: appropriately
  • 05:25: then we want to look at a few different
  • 05:28: inputs here
  • 05:28: let's say the savings rate
  • 05:35: and promotions
  • 05:38: every n years
  • 05:42: uh and ultimately we want to get the
  • 05:44: years to retirement
  • 05:48: as a result um
  • 05:52: so now the next part is where we come up
  • 05:54: with the values of the inputs
  • 05:56: that make sense in each of these
  • 05:59: scenarios
  • 06:00: um and so this time i'm going to go for
  • 06:03: more of the
  • 06:05: financially constrained individual case
  • 06:08: and so we're going to say that they
  • 06:10: won't be able to save as much
  • 06:11: in recessions because they are not
  • 06:15: earning as much and so their savings are
  • 06:19: lower so let's say 15
  • 06:21: savings rate and a bad economy 25
  • 06:24: in normal and 35 and the good
  • 06:28: and then we'll also say that promotions
  • 06:31: come less often
  • 06:32: in recessions so every eight years in
  • 06:34: the recession
  • 06:35: every five years in a normal economy and
  • 06:37: every four years in the good economy
  • 06:40: um so now we have the basic setup
  • 06:44: to start doing the actual calculations
  • 06:48: um and the calculations are going to be
  • 06:53: through a data table so you may already
  • 06:56: have a data table
  • 06:57: if you've done a sensitivity analysis on
  • 06:59: the same variables
  • 07:01: um but i'm going to go ahead and create
  • 07:04: one here
  • 07:05: so in our it's going to be a two-way
  • 07:06: data table with these two different
  • 07:08: inputs and so in the top left cell i've
  • 07:10: got to have
  • 07:11: the outcome variable years to retirement
  • 07:14: and then around that i've got to put the
  • 07:17: values i want to look at so
  • 07:19: on the top here i can do savings rate 15
  • 07:23: uh 25 35 just like we have
  • 07:27: for our different cases here and then i
  • 07:30: can do
  • 07:32: four or five eight
  • 07:35: years for how often the promotion is
  • 07:37: coming
  • 07:41: then i can highlight all this and do the
  • 07:44: data table
  • 07:48: and for the data table uh row input cell
  • 07:52: that's the savings rate so i'm going to
  • 07:55: grab the savings rate from the inputs
  • 07:57: and column input cell that's promotions
  • 07:59: every n years so i'm going to grab that
  • 08:01: input cell for the column input cell and
  • 08:04: then you see we've gotten the years to
  • 08:05: retirement
  • 08:08: so then here we just go and reference
  • 08:11: the case which aligns with the inputs
  • 08:14: so here the 15 8 case
  • 08:17: here it's 5 and 25
  • 08:21: and here it's 35 and 4.
  • 08:27: so now we've got the different years to
  • 08:29: retirement for a bad economy normal
  • 08:31: economy
  • 08:32: and good economy
  • 08:36: and now we can calculate the expected
  • 08:38: value
  • 08:39: of these and the expected value is just
  • 08:42: going to be each of the probabilities
  • 08:44: times each of the values and summing
  • 08:46: them up
  • 08:49: and so we can do equals the probability
  • 08:53: and here i'm going to
  • 08:55: fix that times
  • 08:59: the savings rate
  • 09:02: plus probability fix that
  • 09:05: times savings rate plus
  • 09:08: probability fix that times savings rate
  • 09:12: and that will get us the expected
  • 09:15: savings rate there
  • 09:18: so then we can just drag that over
  • 09:23: and and you switch it to your general
  • 09:25: formatting
  • 09:26: and we'll get the expected values of
  • 09:28: these as well because we use the
  • 09:30: fixed and relative references
  • 09:32: appropriately
  • 09:34: so then we can see based off of our
  • 09:37: economic scenarios that we also get a
  • 09:40: similar expected
  • 09:42: uh year to retirement as we did from the
  • 09:44: baseline model
  • 09:45: um and we can also be thinking about
  • 09:49: well if we were in a bad economy the
  • 09:51: whole time it would be up towards 37 if
  • 09:53: we were in a good economy the whole time
  • 09:54: it would be down towards 23
  • 09:56: so it helps you think about these
  • 09:58: different situations and how they apply
  • 10:00: in your model um
  • 10:04: and you definitely want to add
  • 10:05: formatting to all this stuff
  • 10:07: please take a look at the completed
  • 10:10: example on the course site
  • 10:11: for the kind of formatting that you can
  • 10:13: do for these tables
  • 10:17: and i'm just not doing that here in the
  • 10:19: interest of
  • 10:20: time so that was adding
  • 10:23: external uh scenario analysis
  • 10:27: to an excel model the internal would be
  • 10:31: very similar
  • 10:32: um only you would not use a data table
  • 10:36: you would just be using these expected
  • 10:38: values as the inputs
  • 10:40: into your model so
  • 10:44: that covers um adding synthetic
  • 10:48: adding scenario analysis to an excel
  • 10:49: model so
  • 10:51: thanks for listening and see you next
  • 10:56: time

Lab Exercise - Adding Scenario Analysis to Project 1 - Excel


Notes

  • Here we are adding external scenario analysis to the Project 1 Excel model

  • The process should be basically identical to what was shown in extending the Dynamic Salary Retirement Model in Excel

Transcript

  • 00:02: hey everyone
  • 00:03: nick dierbert is here teaching you
  • 00:05: financial modeling today
  • 00:07: we're going to be talking about the lab
  • 00:09: exercise
  • 00:10: for scenario modeling in excel
  • 00:13: so this exercise is in the scenario
  • 00:16: modeling section
  • 00:17: um here we're adding scenario analysis
  • 00:21: to our project 1
  • 00:22: excel models so this is going to be
  • 00:25: adding
  • 00:25: external scenario analysis so just
  • 00:27: taking the
  • 00:29: existing model and extending it with
  • 00:31: scenario analysis
  • 00:32: using a data table
  • 00:36: and creating the table of the different
  • 00:38: scenarios
  • 00:39: kind of exactly like we just looked at
  • 00:42: doing it with a dynamic salary
  • 00:44: retirement model
  • 00:45: so if you follow the same steps from
  • 00:47: that video then you should be able to
  • 00:49: complete this lab
  • 00:51: just only here it's with project one
  • 00:53: model and we're looking at initial
  • 00:55: demand
  • 00:56: and price for phone as the two inputs
  • 01:00: that we are considering
  • 01:03: um so that's the idea behind the lab
  • 01:06: exercise
  • 01:07: so thanks for listening and see you next
  • 01:10: time

Scenario Analysis in Python


Notes

  • Just as with sensitivity analysis and any other extension to the base model, your model needs to be set up appropriately to add scenario analysis. All the main logic should be in functions, and the functions should not access variables which were defined outside a function unless they are passed in as arguments.

  • Dictionaries are a helpful data structure for scenario analysis as you can put the name of the scenario as the key and have the input values as the value

  • The process is very similar to other methods of exploring the parameter space. Run the model with each set of inputs and keep the outputs associated with the inputs. In scenario analysis we often also assign probabilities to the cases and take the expected value of the results

  • Before you complete the lab, ensure that your Python sensitivity analysis lab is working properly, or else this and any other future extensions to the model will probably also not work properly

Transcript

  • 00:03: hey everyone
  • 00:04: nick deird is here teaching you
  • 00:05: financial modeling today we're going to
  • 00:08: be covering
  • 00:09: scenario analysis in python
  • 00:12: this is part of our lecture series on
  • 00:14: probabilistic
  • 00:15: modeling so previously we already
  • 00:19: covered the intro to scenario modeling
  • 00:22: and we also covered how to complete that
  • 00:25: in excel
  • 00:26: so now we're moving on to just the
  • 00:28: python side
  • 00:29: of the implementation and for that
  • 00:34: when looking at internal scenario
  • 00:36: analysis
  • 00:37: uh you're mainly just setting it up
  • 00:39: within the core model
  • 00:41: so that you can have these different
  • 00:44: cases
  • 00:45: for the inputs and then you're going to
  • 00:47: take the expected value
  • 00:49: across those cases to come up with the
  • 00:51: new
  • 00:52: inputs for your model so uh
  • 00:56: same kind of process as excel
  • 00:58: conceptually
  • 01:00: just here we would be completing that
  • 01:02: using a
  • 01:03: dictionary and some looping over the
  • 01:05: dictionary and summing
  • 01:07: uh the different values to take the
  • 01:09: expected value
  • 01:10: or we could do that in a data frame as
  • 01:13: well
  • 01:15: and then looking at external scenario
  • 01:17: analysis
  • 01:18: so assuming with the external setup
  • 01:22: that uh we have one function that we can
  • 01:25: use to
  • 01:26: run the entire model then you just
  • 01:29: set up your different cases and you loop
  • 01:32: through the different cases
  • 01:33: you call the model function each time
  • 01:36: with that input case
  • 01:38: keep the outputs associated with those
  • 01:41: inputs
  • 01:42: uh and then you'll have the results for
  • 01:44: each case and you can go a step further
  • 01:46: to also
  • 01:47: assign probabilities to those cases so
  • 01:50: that you can take an expected value
  • 01:52: and get an expected result from the
  • 01:54: scenario analysis
  • 01:58: so the important thing to note for
  • 02:00: external scenario analysis
  • 02:02: just like uh sensitivity analysis and
  • 02:05: any other
  • 02:07: extension we're making to the core
  • 02:09: python model
  • 02:11: you do have to set your model up in a
  • 02:14: way that it's going to be able to be
  • 02:15: extended
  • 02:17: so that means that basically everything
  • 02:20: should be in functions
  • 02:22: and the functions should call each other
  • 02:24: in order to
  • 02:25: get the various pieces of information
  • 02:27: and you shouldn't
  • 02:28: have calculations going on outside in
  • 02:32: the cells
  • 02:32: outside of functions because those are
  • 02:35: not going to be able to properly adapt
  • 02:37: when you pass in the new data or the
  • 02:41: scenario or sensitivity analysis monte
  • 02:43: carlo simulation any of these other
  • 02:46: any of the extensions we're looking at
  • 02:47: for our models
  • 02:50: so if you were able to get your scenario
  • 02:53: or sorry sensitivity analysis python
  • 02:57: lab working appropriately extending the
  • 02:59: project one model
  • 03:00: then it should be set up appropriately
  • 03:02: to do all the future extensions as well
  • 03:04: so make sure
  • 03:06: that you have that project one
  • 03:10: sensitivity analysis python exercise
  • 03:12: correct before you keep moving on with
  • 03:14: the material
  • 03:18: so let's look at an example of how we
  • 03:21: can add
  • 03:22: this scenario analysis external scenario
  • 03:25: analysis
  • 03:26: to an existing python model so we'll
  • 03:29: work with the
  • 03:31: dynamic salary retirement model as we
  • 03:33: have been
  • 03:35: and uh we'll work here from the one that
  • 03:38: already has the sensitivity analysis
  • 03:41: incorporated in it and
  • 03:44: we'll go after the end of that um
  • 03:48: so first i'm just going to restart the
  • 03:50: kernel and run all the cells
  • 03:52: so that we have everything defined to be
  • 03:55: able to
  • 03:56: work with it
  • 04:00: as that runs um
  • 04:04: then we're going to
  • 04:07: start building out the
  • 04:12: scenario analysis section oh it looks
  • 04:14: like
  • 04:15: um i need to upgrade my sensitivity
  • 04:18: package here um if you get an error like
  • 04:21: this
  • 04:22: that's indicative that you need to
  • 04:24: update the sensitivity package
  • 04:27: so i'm just going to quickly
  • 04:30: upgrade that
  • 04:34: and that should take a few seconds and
  • 04:36: then it should be
  • 04:38: upgraded yep looks good
  • 04:43: successfully installed i got the upgrade
  • 04:46: now i can delete that cell
  • 04:47: i'm just going to restart and run
  • 04:49: everything again so that
  • 04:51: we'll be all set up to add the scenario
  • 04:54: analysis
  • 04:57: so now everything seems to be running
  • 04:59: appropriately here
  • 05:01: so i'm going to go ahead and start
  • 05:02: adding the scenario analysis now
  • 05:10: um so with the scenario analysis
  • 05:14: um we basically want to set up
  • 05:17: these different input cases and we want
  • 05:20: to have those cases associated with the
  • 05:22: scenarios
  • 05:24: so a dictionary is a natural
  • 05:27: data structure where we can have the
  • 05:29: keys
  • 05:30: be the names of the cases the the
  • 05:33: scenarios that we're looking at
  • 05:35: and the values can be the
  • 05:38: values of the inputs so the first thing
  • 05:42: that we want to do
  • 05:43: is create these different cases of the
  • 05:46: inputs so i can create bad economy
  • 05:51: data here we're just going to look at
  • 05:53: bad normal good
  • 05:54: economy and how that affects the model
  • 05:57: and that is a very standard thing to
  • 05:59: look at in scenario analysis
  • 06:03: [Music]
  • 06:04: so in order to set up all the inputs i'm
  • 06:07: going to create
  • 06:08: a new instance of the model inputs class
  • 06:12: um which will contain all of our input
  • 06:16: data
  • 06:17: um so i can set the starting salary to a
  • 06:20: lower rate
  • 06:21: forty thousand um i can set the
  • 06:24: promotions to occur less frequently
  • 06:26: every eight years
  • 06:28: uh i can set the cost of living raise
  • 06:31: to be only one percent
  • 06:35: the promotion raise i can take to
  • 06:39: um seven percent down from 15
  • 06:42: um the savings rate then
  • 06:46: we can bring that down to 15 we're
  • 06:49: saying this is a more financially
  • 06:50: constrained person
  • 06:51: not able to save as much in the
  • 06:53: recession
  • 06:55: um and the interest rate we can
  • 06:58: put at three percent
  • 07:01: and then we can assume that our
  • 07:04: um normal inputs that we have
  • 07:09: as the defaults here at the top
  • 07:12: we can assume that those are
  • 07:14: representative of a normal economy
  • 07:16: so we don't have to separately create
  • 07:18: the
  • 07:19: normal economy case we can just go on to
  • 07:21: the good economy
  • 07:22: case so again
  • 07:26: creating an instance of model inputs
  • 07:28: just here
  • 07:29: now giving values which are going to
  • 07:34: line up with a good economy an
  • 07:37: expansionary economy
  • 07:39: so typically you know more salary
  • 07:43: promotions are going to occur quicker
  • 07:45: there's going to be bigger
  • 07:46: raises for both the cost of living and
  • 07:49: the
  • 07:50: promotions uh the savings rate is going
  • 07:53: to be more because they're bringing in
  • 07:54: more they can save more
  • 07:56: and the interest rate is going to be
  • 07:58: higher
  • 07:59: as well so
  • 08:03: then this is where the dictionary comes
  • 08:05: in uh
  • 08:06: we can use that to keep all these things
  • 08:09: associated together
  • 08:10: so we can
  • 08:13: do the recession case
  • 08:17: and that's going to be bad economy data
  • 08:20: we can do the
  • 08:21: normal case and that is going to be
  • 08:24: our model data and we can have the
  • 08:28: expansion case which will be the good
  • 08:32: economy data
  • 08:34: so then we have all the data set up
  • 08:38: so that we can uh go and do these
  • 08:42: these scenario analysis
  • 08:45: so then um we want to look at
  • 08:49: what is the main output
  • 08:52: in each of these different scenarios so
  • 08:54: that's years to retirement for this
  • 08:56: model um so we can loop through the
  • 08:59: dictionary
  • 09:00: and if you recall from our uh lecture
  • 09:03: on dictionaries and using them
  • 09:07: more in python i'm going to loop through
  • 09:10: both the keys and values at the same
  • 09:12: time
  • 09:12: using the dot items method of the
  • 09:16: dictionary
  • 09:17: so i'm going to do for case type
  • 09:22: case inputs in cases dot items
  • 09:29: so let me quickly just print that to see
  • 09:32: what i'm getting
  • 09:35: and you can see i get the name of the
  • 09:37: case and then i get
  • 09:38: the inputs which align with that name of
  • 09:40: the case inputs which align with that so
  • 09:42: that's what i'm expecting to get
  • 09:45: now we want to actually do the
  • 09:46: calculation so i'm going to
  • 09:50: call the years retirement function
  • 09:54: with the case inputs and i'm going to
  • 09:57: make sure that it's not
  • 09:59: printing a whole bunch of output
  • 10:03: and then i'm going to have a print
  • 10:05: statement so i can have the nicely
  • 10:07: formatted string containing the result
  • 10:10: uh
  • 10:10: so it would take uh ytr
  • 10:14: years to retire
  • 10:18: in a case type
  • 10:22: economy
  • 10:26: i run that and we can see for these
  • 10:29: three different cases we can see the
  • 10:32: years to retirement
  • 10:34: in each of those cases so that's already
  • 10:39: one of the main outputs from the
  • 10:41: scenario analysis is just the results in
  • 10:43: each case
  • 10:44: now you can use that to guide your
  • 10:46: thinking in that
  • 10:48: um you know it's going to be much faster
  • 10:51: if everything
  • 10:51: lines up with an expansionary economy
  • 10:54: and much slower
  • 10:56: for the recession economy and you can
  • 10:58: frame your thinking about
  • 11:00: you know maybe this is the normal case
  • 11:01: but it could trend in either direction
  • 11:03: based on the state of the economy
  • 11:08: so then the last thing that we can
  • 11:12: do with scenario analysis is also to
  • 11:14: take an expected value
  • 11:16: across the different
  • 11:19: uh scenarios and their results so we
  • 11:22: have to assign
  • 11:24: probabilities to each of those scenarios
  • 11:27: and then we can get an expected value
  • 11:31: so i'm going to create here another
  • 11:33: dictionary
  • 11:36: which is going to associate the same
  • 11:39: names
  • 11:39: of the cases now with probabilities as
  • 11:42: well
  • 11:43: um so the recession i'm going to say 20
  • 11:47: the normal i'm going to say 50
  • 11:51: and the good economy i'm going to put at
  • 11:54: 30
  • 11:55: of course with probabilities you would
  • 11:57: want them to sum up to one
  • 11:59: which these do um
  • 12:02: and now i'm going to take the expected
  • 12:04: value
  • 12:05: based on these probabilities and those
  • 12:07: results
  • 12:08: um so i can start from this loop which
  • 12:12: is already
  • 12:14: um getting the user timing for each
  • 12:20: i don't need to print that out anymore
  • 12:21: i'm just going to take that years
  • 12:22: retirement
  • 12:25: and now we want to calculate the
  • 12:26: expected value so the expected value
  • 12:30: we multiply each of the probabilities by
  • 12:32: the
  • 12:33: outputs and we sum them all up
  • 12:36: so the easy way to do that in python
  • 12:39: with a loop is you want to create a
  • 12:40: running total type of variable so you
  • 12:43: can keep adding to that
  • 12:45: with each case multiplied by its
  • 12:47: probability so
  • 12:48: we're going to start with the expected
  • 12:51: years to retirement
  • 12:53: is going to be zero representing that
  • 12:56: uh this is just a number we're going to
  • 12:58: keep adding to over time and so
  • 13:00: it starts at zero
  • 13:04: so then we want to take the probability
  • 13:07: and multiply it by the
  • 13:11: um years to retirement for that case
  • 13:14: and so we can call that the weighted
  • 13:17: years to retirement
  • 13:19: and for that we're going to multiply the
  • 13:21: years to retirement that we just
  • 13:23: calculated
  • 13:24: by the appropriate
  • 13:27: case probability
  • 13:31: so case probabilities and remember that
  • 13:34: case type here
  • 13:35: is the same key and so i'm able to look
  • 13:39: up
  • 13:40: the appropriate probability
  • 13:43: in the other dictionary by passing it
  • 13:45: the case type
  • 13:49: so we can look at what we're getting
  • 13:51: there
  • 13:55: and here you can definitely see a
  • 13:57: pitfall with this approach you do have
  • 13:58: to make sure
  • 14:00: that your keys match up across the two
  • 14:03: dictionaries or you're going to hit a
  • 14:04: key error
  • 14:05: here i called it expansion in these
  • 14:08: cases and here i called it good
  • 14:10: in these cases and so i get a key error
  • 14:12: about expansion
  • 14:13: so i just need to make sure that those
  • 14:15: match
  • 14:16: and now it's able to calculate
  • 14:18: appropriately
  • 14:21: so these are weighted numbers they're
  • 14:23: not going to mean a lot until we
  • 14:24: actually add them
  • 14:26: to the expected user retirement running
  • 14:29: some variable
  • 14:31: so then um
  • 14:34: we're just going to do expected ytr
  • 14:36: equals expected
  • 14:38: ytr plus weighted ytr
  • 14:44: and then i can add a print statement at
  • 14:46: the end
  • 14:47: it would take expected ytr
  • 14:52: um decimal places
  • 14:56: years to retire
  • 15:03: and we can also put in this sentence the
  • 15:06: probabilities as well considering
  • 15:10: a
  • 15:13: case probabilities
  • 15:16: [Music]
  • 15:20: recession
  • 15:23: answer assassin
  • 15:29: and uh and i can format this
  • 15:34: as a percent
  • 15:40: and
  • 15:43: then the same thing over here with the
  • 15:52: expansion
  • 15:55: change of an expansionary economy
  • 16:02: so it would take 32 years to retire
  • 16:04: considering a 20 chance of recession and
  • 16:06: 30
  • 16:07: chance of an expansionary economy
  • 16:10: um and a couple things to note in what i
  • 16:13: just did there
  • 16:15: notice that my outer string was single
  • 16:19: quotes and now when i'm looking up the
  • 16:20: keys i'm using double quotes
  • 16:22: i did that intentionally because if you
  • 16:26: try and use single quotes here
  • 16:28: um but that may actually no yeah
  • 16:32: it uh it gets confused it basically
  • 16:34: thinks that the string
  • 16:36: ends uh the string that started here now
  • 16:38: ends here
  • 16:39: and so it gets messed up and so if you
  • 16:41: just make sure that
  • 16:43: uh you use the opposite quotes whatever
  • 16:45: you used on the outside
  • 16:47: uh for the inside then you won't run
  • 16:49: into any conflict
  • 16:52: the other thing is that this line is now
  • 16:55: quite long
  • 16:56: so for readability purposes it makes
  • 16:59: sense to
  • 17:00: actually split that onto multiple lines
  • 17:06: and with strings if it's somewhere
  • 17:08: within parentheses
  • 17:10: uh then you can just combine them like
  • 17:13: this
  • 17:14: where strings on multiple lines will
  • 17:16: just automatically get combined
  • 17:20: so now that is definitely more readable
  • 17:22: because you don't have to
  • 17:23: scroll over to see all the contents of
  • 17:26: that print statement
  • 17:32: um so that is how to implement
  • 17:36: scenario analysis in python so thanks
  • 17:39: for listening
  • 17:40: and see you next time

Introduction to Internal Randomness


Notes

  • Internal randomness can be very powerful but also has one major drawback: your model is no longer deterministic, so the same inputs will produce different outputs each time. While this is the goal of internal randomness, it also makes it difficult to know if the model is working correctly.

  • You should only use internal randomness in cases where the randomness is so integral to the model that it wouldn’t make sense to have the model without it

  • The external counterpart to internal randomness is Monte Carlo simulation, which will be the next extension we examine for our models. In most cases, Monte Carlo simulation will achieve your goals and you don’t need internal randomness

  • Pick distributions which make sense for your inputs, but usually just pick a normal distribution with reasonable mean and standard deviation

  • For the mean, use the historical mean or your best estimate of the expected value of the input. For the standard deviation, a rule of thumb is that you should pick a standard deviation such that +/- 1x stdev changes from the mean are common, 2x occur occasionally, 3x are rare, and 4x will almost never occur.

Transcript

  • 00:03: hey everyone
  • 00:04: this is nick dierbertus teaching you
  • 00:05: financial modeling today we're going to
  • 00:08: be doing an
  • 00:08: introduction to internal randomness
  • 00:12: this is part of our lecture series on
  • 00:14: probabilistic modeling
  • 00:17: so we already talked about scenario
  • 00:20: modeling and some math
  • 00:21: math tools to work with probability in
  • 00:23: general in our models
  • 00:25: now let's move to internal randomness
  • 00:29: so internal randomness is
  • 00:32: just like the name sounds there is
  • 00:35: something
  • 00:36: internal to the model which is random
  • 00:40: and so that means that you might have
  • 00:43: something like a portfolio model
  • 00:47: um where each of the returns on each of
  • 00:51: the assets in your portfolio
  • 00:53: uh is random by some some measure
  • 00:59: so it's something that
  • 01:02: is within your model that is going to
  • 01:05: change
  • 01:06: to some other value each time that you
  • 01:09: run the model
  • 01:11: so this is not anymore taking just a
  • 01:14: single number
  • 01:15: for some input it's picking a random
  • 01:17: number
  • 01:18: each time and that doesn't mean
  • 01:20: necessarily totally random
  • 01:22: uh it usually means random from some
  • 01:25: kind of
  • 01:26: distribution um which we'll dig into
  • 01:29: in a little bit
  • 01:32: and that distribution
  • 01:36: can be for a discrete or continuous
  • 01:38: variable
  • 01:40: as we covered in the math review
  • 01:41: variable a continuous
  • 01:43: distribution is going to be defined by a
  • 01:45: function and a curve
  • 01:47: where as a discrete uh is going to be
  • 01:50: defined
  • 01:51: by a table of the probabilities
  • 01:56: so here's a quick graphic
  • 01:59: which uh visualizes internal randomness
  • 02:04: and the biggest change
  • 02:08: to the way that you work with your model
  • 02:09: relating to internal randomness
  • 02:12: so with internal randomness you
  • 02:16: have the same exact inputs to the model
  • 02:19: um you run it but each time that you run
  • 02:23: it
  • 02:23: you get different outputs so that is
  • 02:27: very different
  • 02:28: from everything we've done so far where
  • 02:31: the same inputs
  • 02:32: are always going to give the same
  • 02:34: outputs the outputs only
  • 02:36: change when you change the inputs that's
  • 02:38: a deterministic model
  • 02:40: our model is no longer deterministic
  • 02:42: here
  • 02:43: we keep running with the same inputs and
  • 02:45: we get different outputs
  • 02:47: every time so that's
  • 02:50: usually what you're going for when
  • 02:52: you're building internal randomness
  • 02:54: model but it's also something you have
  • 02:56: to carefully consider
  • 02:58: and be cautious of if you're thinking
  • 03:01: about building an internal randomness
  • 03:03: model
  • 03:04: because this concept does make it quite
  • 03:07: a bit more difficult to understand
  • 03:09: whether your model is working
  • 03:11: appropriately
  • 03:13: especially if you're you're going and
  • 03:14: making some changes to an existing model
  • 03:17: you now get a different result than you
  • 03:19: did before
  • 03:20: substantially is that difference just
  • 03:23: due to the randomness
  • 03:24: or is it due to a mistake that you made
  • 03:26: in your change
  • 03:27: and it can be difficult to determine
  • 03:29: that and there are ways uh
  • 03:32: to be able to get towards more
  • 03:35: consistent results out of an internal
  • 03:36: randomness model
  • 03:38: basically by running it a bunch of times
  • 03:40: and aggregating the output
  • 03:42: and we'll get into all of that within
  • 03:45: the examples
  • 03:47: but it is something to carefully
  • 03:49: consider that
  • 03:50: your model is going to become more
  • 03:52: complex
  • 03:53: just on the nature of you're not going
  • 03:56: to know necessarily what outputs to
  • 03:58: expect from your model
  • 04:00: it's going to be random within some kind
  • 04:01: of range
  • 04:05: so considering those kinds of drawbacks
  • 04:09: with internal randomness you really only
  • 04:12: want to use this technique
  • 04:14: when this randomness is very
  • 04:17: important and core within your model
  • 04:23: there are other ways you can add this
  • 04:25: kind of randomness to your model uh
  • 04:29: monte carlo simulation which will be our
  • 04:31: next
  • 04:32: main topic of exploring the parameter
  • 04:34: space
  • 04:35: is uh basically the external
  • 04:39: counterpart to internal randomness
  • 04:43: where internal randomness you're drawing
  • 04:46: inputs from some kind of distribution
  • 04:47: within the model
  • 04:49: monte carlo simulation you take a
  • 04:50: deterministic model and you extend it
  • 04:53: by drawing random values for the inputs
  • 04:56: uh
  • 04:57: so they can both accomplish
  • 05:00: a lot of the same goals but going with
  • 05:03: monte carlo simulation means that your
  • 05:05: original
  • 05:05: core model is still deterministic and so
  • 05:08: it's still easy to evaluate
  • 05:10: and check and understand
  • 05:12: [Music]
  • 05:14: and so for most situations
  • 05:17: i would recommend going towards monte
  • 05:19: carlo simulation
  • 05:21: but if it's really important for your
  • 05:23: model
  • 05:24: then internal randomness can make sense
  • 05:29: so a couple examples there
  • 05:33: for the retirement model an external
  • 05:37: method makes sense to vary the
  • 05:39: investment return in the model
  • 05:42: because we've already built out the core
  • 05:44: model it's already deterministic
  • 05:46: and so it's much easier to extend it by
  • 05:49: adding monte carlo simulation then to go
  • 05:52: and kind of rebuild it
  • 05:53: by using internal randomness
  • 05:58: and that that brings up another point
  • 06:00: which is generally
  • 06:02: if you want to go with internal
  • 06:03: randomness you should think about this
  • 06:05: before you build the model and
  • 06:07: build it in as you create the model it's
  • 06:10: typically
  • 06:10: more difficult to add internal
  • 06:13: randomness to an existing model than it
  • 06:15: is to build it
  • 06:17: uh from scratch the first time
  • 06:21: but as i mentioned a good example where
  • 06:23: you might want to use
  • 06:24: internal randomness is in a portfolio
  • 06:26: model because you're
  • 06:29: you know you can never know what to
  • 06:30: expect on investment returns of
  • 06:32: individual assets they may as well be
  • 06:34: random
  • 06:35: for modeling purposes and so building
  • 06:38: that randomness right into the model
  • 06:40: that means you'll be able to get you
  • 06:43: know different
  • 06:44: statistics relating to the variation
  • 06:48: in the portfolio returns within
  • 06:51: the core model
  • 06:57: so when you use internal randomness
  • 07:02: you can think of internal randomness
  • 07:04: versus monte carlo simulation
  • 07:07: in a lot of the same ways as internal
  • 07:10: versus external
  • 07:11: sensitivity analysis
  • 07:14: when we build it internally to the model
  • 07:17: the model itself becomes more complex
  • 07:19: the core model
  • 07:21: is more complicated than it was before
  • 07:23: but running the model is just as easy as
  • 07:25: it was before
  • 07:27: whereas when we add it externally
  • 07:30: then it becomes more complicated to run
  • 07:32: the model you might have to run the
  • 07:33: model
  • 07:34: multiple times associate the inputs with
  • 07:36: the outputs aggregate that in some way
  • 07:39: but the core model itself remains just
  • 07:41: as simple and so it's just
  • 07:43: as easy to make changes on the core
  • 07:45: model going forward
  • 07:49: um and as i've highlighted uh
  • 07:52: while this is typically the goal of
  • 07:54: internal randomness it's also the
  • 07:56: drawback
  • 07:57: which is that your model is not
  • 07:59: deterministic
  • 08:00: you run it multiple times with the same
  • 08:02: inputs you're going to get multiple
  • 08:03: different outputs
  • 08:08: and then looking at how we would
  • 08:10: implement internal randomness with
  • 08:12: continuous
  • 08:13: variables so again whether it's discrete
  • 08:16: or continuous you're going to be drawing
  • 08:18: that
  • 08:19: value from a distribution just here with
  • 08:21: continuous
  • 08:22: that distribution is defined by a
  • 08:24: function or a curve
  • 08:28: so then for whatever input you're
  • 08:30: thinking about you need to determine
  • 08:33: which distribution makes the most sense
  • 08:36: for
  • 08:36: your input and if you're not sure
  • 08:40: it will be the right choice in most of
  • 08:43: the cases for your inputs
  • 08:44: just use the normal distribution um
  • 08:48: as we discussed in the math review the
  • 08:51: central limit theorem
  • 08:52: makes it such that most of the things we
  • 08:55: observe
  • 08:56: are going to be normally distributed
  • 09:01: but it is important that you pick
  • 09:04: an appropriate mean and standard
  • 09:06: deviation
  • 09:08: for your normal distribution
  • 09:11: it can be very different
  • 09:14: values coming out as a result from two
  • 09:17: normal distributions if they have
  • 09:19: different means or standard deviations
  • 09:22: so when thinking about how should i pick
  • 09:26: the mean and standard deviation or the
  • 09:29: mean
  • 09:30: if you have historical data then
  • 09:34: use that historical data to take an
  • 09:36: average
  • 09:37: of the historical and use that as your
  • 09:39: estimate for
  • 09:40: the the mean of the normal distribution
  • 09:45: um if you don't have any historical data
  • 09:48: then just think of what a reasonable
  • 09:50: normal typical kind of value for this
  • 09:53: input would be
  • 09:56: as far as the standard deviation the way
  • 09:59: that you can
  • 10:00: think about it is in terms of how likely
  • 10:04: is it for this input to be that far
  • 10:08: from the mean so you want to think about
  • 10:11: it in terms of
  • 10:12: multiples of the standard deviation one
  • 10:15: two three
  • 10:16: four times the standard deviation
  • 10:20: so one times the standard deviation in
  • 10:23: either direction
  • 10:24: from the mean should be a common
  • 10:27: deviation so let's
  • 10:31: put an example that to this to make a
  • 10:32: little more concrete
  • 10:34: if you're thinking about an investment
  • 10:35: return say just an overall
  • 10:37: market return uh you might say seven
  • 10:40: percent
  • 10:41: is a reasonable average just based on
  • 10:44: historical data seven percent
  • 10:46: is a fairly reasonable estimate of an
  • 10:48: overall market return
  • 10:51: then we need to determine the standard
  • 10:52: deviation uh
  • 10:54: let's maybe pick uh three percent
  • 10:58: as an initial value to think about for
  • 11:01: the standard deviation
  • 11:02: and let's go through this logic of
  • 11:05: thinking about multiples of the standard
  • 11:06: deviation and how they relate
  • 11:10: so 1 times the standard deviation
  • 11:12: difference
  • 11:14: should be a common occurrence so that
  • 11:17: means that take that seven percent
  • 11:19: go up up to ten percent down to four
  • 11:22: percent
  • 11:22: that ten to four percent range should be
  • 11:25: common
  • 11:26: for uh the investment rate for that to
  • 11:29: be a valid standard deviation which four
  • 11:30: to ten percent
  • 11:31: definitely common kinds of market
  • 11:34: returns so we're already
  • 11:36: sounding reasonable two times the
  • 11:39: standard deviation
  • 11:40: in either direction should not happen
  • 11:43: often
  • 11:44: it should be relatively rare but
  • 11:47: still happens uh you know a substantial
  • 11:51: portion of the time
  • 11:54: so that would be with seven percent mean
  • 11:57: three percent standard deviation now
  • 11:58: two times the standard deviation is six
  • 12:00: percent so that would be going down to
  • 12:02: one percent
  • 12:03: and up to thirteen percent uh that
  • 12:06: should be
  • 12:07: a range of the
  • 12:10: investment return falls in here most of
  • 12:14: the time
  • 12:14: sometimes it'll go outside of that which
  • 12:16: one to eleven percent that sounds
  • 12:18: reasonable
  • 12:20: three times the standard deviation
  • 12:22: should be rare um
  • 12:24: so that's not to say it won't happen
  • 12:26: it's just
  • 12:27: uh very uncommon so um
  • 12:31: then we're looking at nine percent in
  • 12:33: either direction of that seven percent
  • 12:35: mean so that's negative two
  • 12:38: up until 16 um
  • 12:42: so that seems fairly appropriate
  • 12:45: we might be a little bit small on the
  • 12:47: standard deviation because
  • 12:49: certainly returns go lower than negative
  • 12:52: two
  • 12:53: with a decent uh degree of frequency
  • 12:56: so based on that we might want to
  • 12:59: increase
  • 13:00: uh the standard deviation maybe four
  • 13:02: percent is going to be more appropriate
  • 13:04: and then we're looking at four times
  • 13:06: three twelve percent down
  • 13:08: from the seven percent uh so that's down
  • 13:11: to negative five percent
  • 13:12: uh so that seems like a more reasonable
  • 13:16: range
  • 13:16: um for an annual market return
  • 13:20: and then a four times standard deviation
  • 13:23: change should be very very rare
  • 13:27: um almost never occur
  • 13:29: [Music]
  • 13:30: and so that is maybe where
  • 13:34: this gets a little bit weird with
  • 13:35: investment returns
  • 13:37: typically we use
  • 13:40: like a log normal distribution or
  • 13:42: something with heavier tails than a
  • 13:44: normal distribution
  • 13:46: for investment returns because
  • 13:49: we do have those extreme events like you
  • 13:51: know big recessions all of a sudden
  • 13:53: negative 40
  • 13:54: return on the market uh hopefully it
  • 13:57: recovers within the year
  • 13:58: but you do have these very negative
  • 14:01: market returns occasionally
  • 14:03: and more than you would expect from
  • 14:06: a normal distribution so
  • 14:10: you know if you really want to be more
  • 14:11: accurate you should probably pick a
  • 14:13: different distribution than normal for
  • 14:15: investment returns
  • 14:16: specifically but just thinking about the
  • 14:18: normal distribution
  • 14:19: and trying to get something that's going
  • 14:21: to be pretty close most the time
  • 14:24: that example we just talked through will
  • 14:27: give you
  • 14:28: a good way to think about it and for
  • 14:30: most inputs
  • 14:31: the normal distribution is going to be
  • 14:33: the right choice and so that's the
  • 14:34: kind of thinking that you would want to
  • 14:36: do to pick your standard deviation
  • 14:41: so that's the basic introduction to
  • 14:44: internal randomness
  • 14:45: we're going to come back next time to
  • 14:47: implement it in
  • 14:48: excel so thanks for listening
  • 14:51: and see you next time

Intro to Randomness in Excel


Notes

  • Excel has the functions to get most of the kinds of random numbers that you would want, but often multiple have to be combined such as NORM.INV(RAND()) for randomly drawing numbers from a normal distribution

Transcript

  • 00:02: hey everyone
  • 00:03: nick dearbird is here teaching you
  • 00:05: financial modeling so today i'm going to
  • 00:07: be giving you an introduction
  • 00:09: on internal randomness in excel
  • 00:12: as part of our lecture series on
  • 00:14: probabilistic modeling
  • 00:16: so last time we had already done an
  • 00:19: introduction to
  • 00:20: internal randomness and now we're coming
  • 00:23: to implementing that
  • 00:24: in excel so in excel we have
  • 00:28: two main functions which generate
  • 00:30: randomness
  • 00:31: for us that is the brand and the rand
  • 00:34: between
  • 00:35: functions so rand will generate
  • 00:39: a number between zero and one anywhere
  • 00:42: in that range a continuous number while
  • 00:45: randbetween
  • 00:46: will give you a random integer between
  • 00:49: two integers that you pass to it
  • 00:53: so both of these are drawing from
  • 00:56: a uniform distribution which just
  • 00:59: means that each number in the range is
  • 01:03: equally likely
  • 01:06: then if we want to draw from any other
  • 01:08: distribution
  • 01:10: as we often will want to draw from
  • 01:13: normal distributions
  • 01:14: in our models uh we need to
  • 01:18: uh combine a couple different functions
  • 01:21: to make that happen in excel
  • 01:24: the tools for randomness in excel
  • 01:26: generally are a little bit
  • 01:28: primitive we kind of had to do some
  • 01:30: manual work
  • 01:31: to be able to get continuous numbers in
  • 01:35: some range draw from normal
  • 01:36: distributions
  • 01:37: work with discrete random variables et
  • 01:40: cetera
  • 01:42: and so we'll learn some patterns that
  • 01:44: you can apply
  • 01:46: to make that happen in python it tends
  • 01:50: to be
  • 01:50: more straightforward they're just
  • 01:52: functions directly made
  • 01:54: for each kind of randomness that we
  • 01:55: would want to do
  • 01:58: so in order to draw a number from
  • 02:02: a normal distribution in excel we can
  • 02:05: combine
  • 02:06: two different functions so we're going
  • 02:09: to bring in this
  • 02:10: norm.inv which is normal distribution
  • 02:13: inverse
  • 02:14: function which gives us
  • 02:17: the value on the normal distribution
  • 02:21: corresponding to a certain probability
  • 02:25: um and you have to give it the mean and
  • 02:27: the standard deviation of the
  • 02:28: distribution
  • 02:29: as well and this is not a random
  • 02:32: function
  • 02:34: if you say um give me
  • 02:37: uh the 50th percentile of the normal
  • 02:40: distribution with mean 10 and standard
  • 02:42: deviation 3
  • 02:43: it's going to give you 10 every single
  • 02:45: time no randomness
  • 02:47: you give it 0.6 it's going to give you a
  • 02:49: number higher than 10
  • 02:51: and it's going to give you that same
  • 02:52: number every time
  • 02:54: so we need to combine it with a source
  • 02:57: of randomness
  • 02:58: to be able to draw random numbers from
  • 03:00: the normal distribution
  • 03:01: in excel so we can use the
  • 03:05: the normal inverse function along with
  • 03:08: the rand function
  • 03:09: to make that happen so in this spot in
  • 03:13: the normal inverse function where we
  • 03:14: would
  • 03:15: be passing that probability we're going
  • 03:18: to put the rand
  • 03:18: function there because a probability has
  • 03:22: to be
  • 03:22: between 0 and 1 and the rand function
  • 03:25: generates a random number between 0 and
  • 03:28: 1 so basically it's giving us a random
  • 03:30: probability and so then we can just put
  • 03:33: that in
  • 03:34: to the normal inverse function and now
  • 03:36: we have created this
  • 03:38: composite function which is able to
  • 03:41: generate
  • 03:42: random numbers from a normal
  • 03:44: distribution with whatever mean and
  • 03:46: standard deviation that you specify
  • 03:51: so let's look at a quick example of how
  • 03:54: we can implement this
  • 03:55: in excel
  • 03:58: um so
  • 04:04: here we've got a new excel workbook and
  • 04:07: this completed example is on the course
  • 04:09: site
  • 04:10: as well uh the continuous sheet of the
  • 04:13: generating random numbers
  • 04:14: example so first thing we want to do
  • 04:17: is get some numbers from the uniform
  • 04:19: distribution
  • 04:23: and all that we have to do there is rand
  • 04:26: that will give us a random number
  • 04:28: between zero and one
  • 04:30: and f9 is going to recalculate on
  • 04:33: windows and so if i keep pressing that
  • 04:36: f9 to recalculate we keep getting a
  • 04:38: different
  • 04:39: random number coming out as a result
  • 04:41: always between 0 and 1.
  • 04:44: and you want multiple you can simply
  • 04:46: just drag it
  • 04:47: and you'll have multiple of them
  • 04:51: but then you might say well how do i get
  • 04:54: a random number
  • 04:56: between zero and five
  • 04:59: well you just take rand and you multiply
  • 05:02: it by five
  • 05:03: now that's going to be pulling random
  • 05:06: numbers
  • 05:07: between uh zero and five
  • 05:11: well what if you want those random
  • 05:12: numbers to be between
  • 05:14: uh 10 and 15 well then just add
  • 05:17: 10 on to the end of it and
  • 05:20: now this is going to be random numbers
  • 05:23: between 5
  • 05:24: and 15. so
  • 05:27: they are not the most straightforward
  • 05:29: how you have to do the math with it to
  • 05:30: make it happen
  • 05:32: but still not too difficult to
  • 05:36: draw random numbers from a uniform
  • 05:39: distribution
  • 05:40: in any range
  • 05:43: so that covers the uniform distributions
  • 05:48: now what if we want to draw numbers from
  • 05:50: a normal distribution
  • 05:55: so before we
  • 05:58: do that i'm going to define the mean and
  • 06:00: standard deviation
  • 06:02: of the distribution so the mean let's
  • 06:05: just
  • 06:05: say is 10 and the standard deviation is
  • 06:08: 5.
  • 06:10: so now we can generate some random
  • 06:12: numbers
  • 06:14: but first before we do that let's just
  • 06:17: look at the plane
  • 06:18: norm.inv function and
  • 06:22: we're going to just put in for example
  • 06:25: purses the
  • 06:26: purposes the 0.5 probability and grab
  • 06:29: that mean
  • 06:30: grab that standard deviation you'll see
  • 06:32: we get 10 the mean coming back
  • 06:34: and no matter how many times i
  • 06:36: recalculate it it's always 10.
  • 06:38: um go and put 0.6 in there we've got a
  • 06:41: number higher
  • 06:42: which doesn't change 0.4 we've got a
  • 06:46: number that's lower
  • 06:47: and again does not change it's once we
  • 06:50: then
  • 06:51: put the rand into that spot
  • 06:54: that now we've got a random number
  • 06:57: generator
  • 06:58: from a normal distribution
  • 07:01: so to make it more clear um
  • 07:04: what's going on with these numbers i'm
  • 07:06: going to fix both of those
  • 07:08: and then i can generate a bunch of them
  • 07:14: so now when you see all these different
  • 07:15: numbers you can see that most of them
  • 07:17: are generally around 10. um
  • 07:21: and as we recalculate them you know
  • 07:24: occasionally they go negative that's
  • 07:26: uh you know two standard deviations more
  • 07:28: than two standard deviations
  • 07:30: below the mean occasionally they go
  • 07:33: above 20. sometimes here this one is
  • 07:37: even a little bit more than three
  • 07:38: standard deviations above the mean so
  • 07:41: uh you do observe that occasionally but
  • 07:44: it's rather rare
  • 07:46: most the time they're in this like 5 to
  • 07:48: 15
  • 07:49: kind of range
  • 07:51: [Music]
  • 07:52: so that's how we can generate
  • 07:56: random numbers uh continuous random
  • 07:58: numbers from both uniform
  • 08:00: and normal distributions in excel um
  • 08:03: of course you can just change around
  • 08:04: these parameters to get different
  • 08:07: means on the distributions
  • 08:10: or different standard deviations
  • 08:13: can create quite a bit different results
  • 08:17: even though it's still a normal
  • 08:18: distribution
  • 08:20: so that's generating uniform and normal
  • 08:24: continuous random numbers in excel
  • 08:27: next time we're going to come back to
  • 08:29: look at how to do the same in python
  • 08:31: so thanks for listening and see you next
  • 08:35: time

Intro to Randomness in Python


Notes

  • Python has far more and more convenient features around randomness than Excel

  • A single function, random.normalvariate, can be used for generating random numbers from a normal distribution

  • There is a lot better support for other conveniently using other distributions in Python

  • You can also generate many random numbers at once using numpy

Transcript

  • 00:03: hey everyone
  • 00:04: nick dear birds here teaching you
  • 00:05: financial modeling today
  • 00:07: we're going to be doing an introduction
  • 00:10: on randomness
  • 00:11: in python it's part of our lecture
  • 00:14: series on probabilistic
  • 00:16: modeling so last time
  • 00:19: we had already covered the intro to
  • 00:21: internal randomness and then we looked
  • 00:23: at
  • 00:23: how to implement that in excel as well
  • 00:28: and now we're coming to the python side
  • 00:30: of the implementation
  • 00:33: so in python we
  • 00:36: have a built-in module so this module
  • 00:39: our package is built into every python
  • 00:43: installation
  • 00:44: you do have to import it but it's there
  • 00:46: with every python
  • 00:47: and it's the random module and the
  • 00:49: random module
  • 00:51: gives us pretty much everything that we
  • 00:53: would want
  • 00:54: for generating random numbers
  • 00:58: we'll also look at numpy has its own
  • 01:01: random
  • 01:02: module which is able to do all the same
  • 01:05: things but
  • 01:06: produce entire arrays of random numbers
  • 01:08: rather than
  • 01:10: just one random number at a time but
  • 01:12: primarily
  • 01:13: we're gonna be looking at using the
  • 01:14: random module
  • 01:17: so we have functions in that module
  • 01:20: which work just like the ones we've
  • 01:22: already covered in excel
  • 01:24: um so we have
  • 01:28: random.random
  • 01:30: is just like the rand function
  • 01:33: random.uniform
  • 01:34: allows you to get a random number
  • 01:38: in any range and there's also a rand int
  • 01:42: which allows you to pick just integers
  • 01:44: in that particular
  • 01:45: range and then
  • 01:49: uh where it starts to get a lot nicer
  • 01:51: than working excel
  • 01:53: is for the normal distribution and
  • 01:56: for quite a few other distributions as
  • 01:58: well we have functions which
  • 02:00: directly generate random numbers from
  • 02:02: those distributions
  • 02:04: so random.normal variant we just give it
  • 02:06: the mean and the standard deviation
  • 02:08: and it draws a random number from a
  • 02:10: normal distribution with those
  • 02:12: parameters
  • 02:12: nice and simple and straightforward and
  • 02:16: you'll find this kind of syntax
  • 02:18: typically for
  • 02:18: every type of randomness that you would
  • 02:21: want to do in python
  • 02:24: so let's look at a quick example of how
  • 02:27: we can generate
  • 02:28: continuous random numbers in python
  • 02:31: and this uh jupiter notebook is on
  • 02:34: the course site as well
  • 02:38: so we're starting here
  • 02:42: with generating a single continuous
  • 02:44: random number
  • 02:47: and using the random module so we can
  • 02:50: specify a mean
  • 02:51: specify a standard deviation
  • 02:54: and with that we can generate random
  • 02:58: random numbers from a normal
  • 02:59: distribution right away
  • 03:02: we can also uh do the
  • 03:06: the random function
  • 03:08: [Music]
  • 03:09: which just gets us you know just like
  • 03:12: rand and excel
  • 03:14: we can do that random.uniform
  • 03:18: to give us random numbers in some range
  • 03:23: and we have random.rand in
  • 03:26: which is able to get us random integers
  • 03:29: in some range so that's analogous to
  • 03:32: the random between function in excel
  • 03:35: um so we have those and we have plenty
  • 03:38: of other functions here available in the
  • 03:41: random module
  • 03:42: uh you know gamma variant we gamma
  • 03:45: distribution log normal distribution
  • 03:48: uh pareto distribution whatever uh
  • 03:51: you know the common distributions that
  • 03:52: you would expect to see are all here
  • 03:55: um and so it's really nice to have
  • 03:59: all of that just there out of the box
  • 04:04: and then if we want to generate multiple
  • 04:06: of these random numbers
  • 04:08: either we could do with just the random
  • 04:11: module and we can
  • 04:13: go with a list comprehension so i can
  • 04:16: just
  • 04:17: uh whoops other way around it would be
  • 04:22: random
  • 04:23: normal variant on this side rye and
  • 04:26: range
  • 04:27: however many you want to generate and
  • 04:29: they're going to be able to generate
  • 04:30: that many
  • 04:31: uh random numbers so still possible in
  • 04:34: one line
  • 04:35: with the random module
  • 04:37: [Music]
  • 04:38: but you can also do it with numpy
  • 04:41: directly
  • 04:44: so with numpy dot random
  • 04:47: dot normal we can draw a number from a
  • 04:50: normal distribution
  • 04:51: and then if you add a third parameter of
  • 04:54: how many numbers that you want then it's
  • 04:56: going to give you
  • 04:57: an array with that many
  • 05:01: random numbers and we can still loop
  • 05:03: through that
  • 05:05: just like a list you can index it just
  • 05:08: like a list
  • 05:09: and you can even convert it to a list by
  • 05:12: wrapping it
  • 05:13: in list
  • 05:14: [Music]
  • 05:16: so then the one liner you can copy paste
  • 05:20: to get a list of random numbers
  • 05:24: would be here numpy random normal
  • 05:27: however many random numbers that you
  • 05:29: want and wrapping that
  • 05:30: in list to convert it to a list
  • 05:35: so that's really all it takes for doing
  • 05:38: randomness in python it's very
  • 05:40: straightforward this is
  • 05:42: definitely one of the areas where it
  • 05:43: shines over excel
  • 05:47: so that's a quick overview of that we'll
  • 05:49: come back
  • 05:50: next time to look at discrete
  • 05:53: random numbers and generating that them
  • 05:56: in
  • 05:57: both excel and python so thanks for
  • 06:00: listening
  • 06:00: and see you next time

Lab Exercise - Generating Continuous Random Numbers in Excel and Python


Notes

  • The exercise is the same for Excel and Python

  • Make sure to do the entire exercise with n=10 and n=1000 so you can see the differences that number of iterations makes

Transcript

  • 00:02: hey everyone this is nick dear verdict
  • 00:04: teaching you financial modeling
  • 00:06: so today we're going to be introducing
  • 00:08: the lab exercise
  • 00:09: on generating continuous random numbers
  • 00:12: in
  • 00:13: both excel and python so we've already
  • 00:17: covered
  • 00:17: how to generate those and random numbers
  • 00:21: in excel and python and now
  • 00:24: we're doing a lab to test your
  • 00:27: understanding of those concepts
  • 00:30: so the exercise is to
  • 00:33: generate random numbers from a uniform
  • 00:37: distribution
  • 00:38: from a normal distribution
  • 00:41: and then you're going to visualize those
  • 00:44: outputs with each of them being on a
  • 00:47: histogram
  • 00:49: and then you want to calculate the mean
  • 00:51: and standard deviation
  • 00:53: of those generated numbers and you want
  • 00:56: to recalculate it
  • 00:58: a few times and notice how much
  • 01:01: the values are changing around each time
  • 01:03: that you recalculated the
  • 01:04: the calculated mean and standard
  • 01:06: deviation
  • 01:09: um and you want to do this whole
  • 01:11: exercise
  • 01:12: for 10 iterations uh
  • 01:16: 10 random numbers and for 1 000
  • 01:19: iterations thousand random numbers
  • 01:21: and notice what happens in the
  • 01:25: 10 iteration versus the thousand
  • 01:27: iteration case
  • 01:28: when you rerun it multiple times you
  • 01:31: should see that the thousand
  • 01:33: case is going to be much more stable in
  • 01:36: its estimates
  • 01:37: of the mean and standard deviation
  • 01:40: and you want to complete this entire
  • 01:43: exercise in excel
  • 01:44: for 10 and thousand iterations and then
  • 01:47: you also want to complete that exercise
  • 01:50: in python
  • 01:51: as well for the 10 000 iterations
  • 01:55: so you should have two separate
  • 01:57: submissions for this
  • 01:58: um and each one one in excel one in
  • 02:02: python each one is going to show
  • 02:04: 10 and thousand iterations of this same
  • 02:07: exercise so
  • 02:10: that's what's involved in the lab
  • 02:13: exercise
  • 02:14: we're going to come back next time to
  • 02:17: look at how we can generate discrete
  • 02:21: random numbers in both excel and python
  • 02:24: so thanks for listening
  • 02:25: and see you next time

Discrete Randomness


Notes

  • The story around generating random discrete values in Excel is relatively complicated. In Python, it is just as straightforward as working with continuous numbers

  • We can hack our way into a discrete random value function in Excel by using uniform random numbers and the probability distribution. It is a manual effort to set this up in your model

  • In Python, just pass your discrete values and probabilities to the random.choices function and you are done. This function can even give you multiple choices

Transcript

  • 00:03: hey everyone this is nick dear burtis
  • 00:05: teaching you financial modeling
  • 00:07: today we're going to be talking about
  • 00:09: random discrete
  • 00:11: variables and this is part of our
  • 00:14: lecture series
  • 00:15: on probabilistic modeling so
  • 00:18: we've been talking about internal
  • 00:20: randomness in our models
  • 00:21: and we've already covered continuous
  • 00:24: random variables and how to implement
  • 00:26: them in excel in python
  • 00:30: we've talked kind of generally about
  • 00:32: discrete variables
  • 00:33: and now we're going to look at how we
  • 00:36: can
  • 00:37: implement them in our models as well in
  • 00:39: both excel and python
  • 00:43: so when we think about discrete
  • 00:46: variables again that's
  • 00:48: a variable that can take on a fixed set
  • 00:50: of values not
  • 00:51: just a number in some range but certain
  • 00:54: values
  • 00:56: uh we can also build random discrete
  • 00:59: variables into our models
  • 01:01: so unlike the continuous variable where
  • 01:03: the distribution is defined by a
  • 01:05: function or
  • 01:06: curve the discrete random variable
  • 01:09: we only have fixed numbers a fixed set
  • 01:12: of values
  • 01:12: it can take the value of and so just
  • 01:16: each one of those values has an assigned
  • 01:18: probability
  • 01:19: and that is our distribution for a
  • 01:21: discrete variable
  • 01:23: so um the general process
  • 01:27: uh that you're going to have to follow
  • 01:31: in excel to be able to pick a random
  • 01:34: discrete variable
  • 01:36: is you have this table of the different
  • 01:40: values of the variable and the
  • 01:41: probabilities then you want to add a new
  • 01:44: column to that table
  • 01:46: which is going to be the cumulative sum
  • 01:49: of the probabilities um
  • 01:52: and based off that as well as
  • 01:55: using the rand function you're going to
  • 01:58: be able to combine those
  • 02:00: into an approach that can pick a random
  • 02:03: discrete variable
  • 02:06: um you pull this random number from zero
  • 02:09: to one
  • 02:10: the rand function in excel and
  • 02:13: that is going to tell you the
  • 02:16: uh which range of probabilities
  • 02:20: that we should draw from
  • 02:23: so this will become more concrete
  • 02:26: looking at an example here
  • 02:28: here we have uh three different states
  • 02:31: of the economy
  • 02:32: that we want to choose from and we have
  • 02:34: three different probabilities
  • 02:36: associated with those states of the
  • 02:38: economy
  • 02:40: um so you can think of if we have 30
  • 02:43: recession 50 normal and 20
  • 02:45: expansion we can form ranges based off
  • 02:48: those probabilities
  • 02:50: zero to thirty percent we're going to be
  • 02:52: in the recession range
  • 02:53: then add the fifty thirty to eighty
  • 02:55: percent we're going to be in the normal
  • 02:57: uh range and with the
  • 03:00: expansion economy additional twenty
  • 03:02: percent the top 20 percent
  • 03:04: of the range 80 to 100 is going to
  • 03:07: correspond
  • 03:08: to an expansion economy uh and when you
  • 03:11: build this out
  • 03:12: you don't actually have to build both
  • 03:14: the begin and in range you can base it
  • 03:16: off of just one of the two
  • 03:18: but for sake of example i think this
  • 03:20: makes it a little more clear
  • 03:21: that um basically
  • 03:25: we're going to pick this random number
  • 03:26: between zero and one
  • 03:28: and whichever range it falls in is the
  • 03:30: case
  • 03:31: that we're going to pick for the
  • 03:33: discrete
  • 03:34: random variable um
  • 03:38: so just you know we
  • 03:41: we pull a random number let's say that
  • 03:44: it's
  • 03:45: 0.15 uh well that's between zero and 30
  • 03:48: percent
  • 03:49: and so we're going to have a recession
  • 03:51: as the case
  • 03:53: if it's 0.45 that's between 30 and 80
  • 03:57: and so it's going to be the normal state
  • 03:59: of the economy and 0.94
  • 04:01: that's between 80 and 100 percent so
  • 04:03: that's going to be an expansionary
  • 04:05: period um and excel
  • 04:09: we do have to build that out manually
  • 04:13: um it's not very straightforward to do
  • 04:15: discrete random numbers
  • 04:17: in excel um whereas
  • 04:21: in python it is quite straightforward to
  • 04:24: do it
  • 04:25: we have the random choices function the
  • 04:28: choices
  • 04:29: function of the random module which you
  • 04:32: just directly pass it
  • 04:34: the different cases that you want to
  • 04:36: pick from
  • 04:38: and you pass it the probabilities of
  • 04:40: each of those
  • 04:41: and it's just going to pick the random
  • 04:43: values for us
  • 04:44: so you don't have to do any of this
  • 04:48: forming of the ranges and checking which
  • 04:49: range it falls in
  • 04:51: all that is going on in the background
  • 04:53: automatically for you
  • 04:54: in this random.choices function so
  • 04:58: we will now look at an example of
  • 05:02: implementing this in both excel and
  • 05:04: python
  • 05:08: and the complete examples of both of
  • 05:10: these are on the course site
  • 05:12: as well
  • 05:15: um so we're going to build out
  • 05:18: this discrete random variables
  • 05:23: and i'm going to look at this in the
  • 05:26: context of we have a few different
  • 05:28: scenarios and we want to pick a scenario
  • 05:30: at random so we can do that based on the
  • 05:34: state of the economy
  • 05:36: recession normal expansion economy
  • 05:41: um and then we want to assign
  • 05:44: a probability to
  • 05:48: each of those so we can go with that
  • 05:50: same 30
  • 05:51: 50 20 probabilities
  • 05:56: and then we want to just get some
  • 05:59: inputs which are going to align
  • 06:03: with those cases so two percent interest
  • 06:06: rate in recession
  • 06:07: five in normal economy seven and
  • 06:09: expansion
  • 06:10: and um here we can go with the less
  • 06:14: financially constrained individual
  • 06:16: they're able to save more in the
  • 06:18: recession because they're not spending
  • 06:20: as much
  • 06:23: and now we have those inputs aligned
  • 06:25: with each of the cases
  • 06:28: then we can create our cumulative
  • 06:31: probability measure which we will use
  • 06:36: for picking the random discrete variable
  • 06:39: um so that we're going to do our
  • 06:42: cumulative sum pattern that we've seen
  • 06:44: before
  • 06:44: we're going to sum uh from
  • 06:48: the beginning of the range fixed up
  • 06:50: until
  • 06:52: uh the same and it unfixed me there
  • 06:55: so yeah fix just the first one not the
  • 06:58: second one
  • 06:59: and that allows it to expand the range
  • 07:02: as you go down each one is going to be
  • 07:05: picking up
  • 07:06: additional values
  • 07:10: so now we have you can think of this as
  • 07:14: the end range
  • 07:15: column we had seen in the example like i
  • 07:17: said you only need one of the two to
  • 07:19: actually
  • 07:20: be able to do this
  • 07:24: um so now comes actually drawing
  • 07:28: the um
  • 07:32: random states of the economy um
  • 07:35: so the first thing we need to do is
  • 07:39: draw a probability
  • 07:44: and so all that is is just equals
  • 07:47: and um so let's just
  • 07:51: get a few different random numbers here
  • 07:54: um and next we're going to figure out
  • 07:57: what is
  • 07:58: the economic state um
  • 08:01: so to determine the economic state
  • 08:06: we're going to do exactly what we just
  • 08:08: talked through a moment ago of just
  • 08:10: checking
  • 08:10: [Music]
  • 08:11: which range this drawn probability lies
  • 08:15: in
  • 08:16: so it's going to be a series of nested
  • 08:18: if statements
  • 08:20: determining which range this probability
  • 08:23: lies in
  • 08:25: so if the probability is less than
  • 08:28: or equal to this first cumulative
  • 08:31: probability i'm going to
  • 08:33: fix that then
  • 08:36: we're in the recession range the 0 to 30
  • 08:39: range so we're going to get recession
  • 08:43: fix as a result otherwise
  • 08:47: we are not in that 0 to 30 range
  • 08:50: and so now we need to check again what
  • 08:52: range we're in
  • 08:54: if we are
  • 08:57: again the drawn probability is less than
  • 09:00: or equal to the
  • 09:03: next cumulative probability so now this
  • 09:06: means because we're already not in the
  • 09:08: 0-30 range this means we're now
  • 09:10: in the 30 to 80 range fixed
  • 09:15: which corresponds to the normal state of
  • 09:18: the economy
  • 09:20: otherwise now we know we're not 0 to 30
  • 09:23: we know we're not 30 to 80
  • 09:24: and so we're in this last range of 80 to
  • 09:28: 100
  • 09:29: um so for the last one you don't need to
  • 09:33: do another if
  • 09:34: we know since we're not 0 to 30 we're
  • 09:36: not
  • 09:37: a 30 to 80 we must be in 80 to 100
  • 09:40: so otherwise it's the expansion economy
  • 09:43: and then we can close both those ifs
  • 09:48: and we can drag this down
  • 09:49: [Music]
  • 09:52: and we'll see the ones that are falling
  • 09:54: in this mid-range
  • 09:55: normal economy the ones that are falling
  • 09:58: in
  • 09:58: the upper range expansion economy let's
  • 10:01: calculate again
  • 10:02: the ones that are low values are falling
  • 10:04: as the recession economy
  • 10:07: so now you know just looking at these
  • 10:10: now we're getting random discrete
  • 10:11: variables after
  • 10:13: building out this whole setup
  • 10:16: um so then the other part of this
  • 10:20: would then be to get the
  • 10:25: variables that correspond to that
  • 10:29: economic case and there's a couple
  • 10:30: different ways you can go about this
  • 10:32: you could use a vlookup to be able to
  • 10:36: do this a little more generally but i'm
  • 10:38: just going to show again
  • 10:39: here with some simple if statements so
  • 10:43: if this economic state
  • 10:46: is equal to recession
  • 10:50: then um i'm going to get the
  • 10:54: interest rate value of the recession
  • 10:58: and here i'm going to fix only
  • 11:01: on the row and not on the column
  • 11:04: because i'm going to want to be able to
  • 11:05: drag over to be able to get the savings
  • 11:08: rate as well
  • 11:10: so now it's not
  • 11:13: recession so it's something other than
  • 11:16: recession
  • 11:17: so again we need to do another if
  • 11:19: statement
  • 11:20: if the economic state now
  • 11:23: is equal to normal fix that
  • 11:27: then grab the normal interest rate again
  • 11:31: fixed on the row but not on the column
  • 11:34: and then similar to when we picked the
  • 11:37: economic state
  • 11:39: because it's not recession or normal it
  • 11:41: has to be expansion
  • 11:42: and so now we don't need another if
  • 11:46: statement
  • 11:46: it can just be otherwise it's the other
  • 11:49: interest rate
  • 11:50: again fixing the row but not the column
  • 11:58: and then i need one additional
  • 12:00: parenthesis i forgot that
  • 12:01: excel was able to pick that up um
  • 12:06: and then this is a percentage and we can
  • 12:09: see normal we got the five percent so
  • 12:11: that's working appropriately and this is
  • 12:12: the interest rate
  • 12:15: and now we can get the savings rate as
  • 12:17: well
  • 12:19: um drag this over
  • 12:22: drag this down and
  • 12:25: let's see if this is working
  • 12:27: appropriately something is
  • 12:30: seems to not be working appropriately
  • 12:34: yeah you can see it didn't pick the
  • 12:35: correct savings rate corresponding to
  • 12:37: the interest rate
  • 12:38: and that's because i forgot to fix
  • 12:42: this on the column um
  • 12:46: or so you can see that it should stay
  • 12:48: over here on normal but it went
  • 12:49: over to the interest rate so i'm going
  • 12:53: to go in and modify that
  • 12:54: any references to the normal
  • 12:59: and now that should be fixed on the
  • 13:04: column we don't want the column to move
  • 13:05: but we do want to allow the row to move
  • 13:09: so here fixing on the column
  • 13:12: again over here fixing on the column
  • 13:15: and then we can re-drag into that range
  • 13:20: to now apply this everywhere and now it
  • 13:23: is appropriately staying
  • 13:25: in that column let's just check over our
  • 13:28: work
  • 13:29: normal we get five percent and 25
  • 13:31: percent recession we get
  • 13:33: two percent and thirty five percent
  • 13:34: expansion we get seven percent and
  • 13:36: fifteen percent so it's all working
  • 13:39: appropriately now
  • 13:42: um so that's a quick overview of how to
  • 13:44: do discrete
  • 13:45: random variables in excel
  • 13:49: and when you format this you may want to
  • 13:52: hide some areas of this like this
  • 13:54: is not important this is not important
  • 13:56: you could potentially hide those
  • 13:58: those areas of the sheet or otherwise
  • 14:01: change the formatting to make them uh
  • 14:03: de-emphasize
  • 14:04: something that the consumer of the model
  • 14:07: shouldn't really care about
  • 14:10: um so fairly involved manual process to
  • 14:15: do that in excel and you can only
  • 14:16: imagine you add additional cases you're
  • 14:18: just adding more and more
  • 14:19: nested if statements which becomes a
  • 14:21: little bit of a mess
  • 14:24: so let's look at how we can do that in
  • 14:26: python now
  • 14:30: um so here you know thinking about the
  • 14:32: same
  • 14:33: kind of thing choosing between recession
  • 14:35: normal expansion
  • 14:37: um and we want to just pick a case
  • 14:41: well we just uh take the cases and we
  • 14:44: take the probabilities of those cases
  • 14:46: and we pass those to random dot choices
  • 14:48: and that will be able to pick
  • 14:50: a random discrete value for us it really
  • 14:52: is that simple
  • 14:54: um there is one thing you'll notice with
  • 14:56: this random.choices function
  • 14:58: is it always returns a list that's why
  • 15:01: you see the brackets
  • 15:02: around the output in the result so if
  • 15:05: you just want a single value
  • 15:06: you can just put bracket 0 on the end
  • 15:10: that is going to pull the first value
  • 15:13: out of the list
  • 15:14: and now we have just the random value
  • 15:17: itself um
  • 15:21: and the random.choices function directly
  • 15:24: already supports
  • 15:25: picking uh random just multiple random
  • 15:29: discrete numbers you pass it this k
  • 15:31: parameter k
  • 15:32: equals however many you want to generate
  • 15:35: here k
  • 15:36: equals five we get five random numbers
  • 15:39: we can change it to 10.
  • 15:40: sorry not random numbers random cases um
  • 15:44: now we've got 10 different cases and it
  • 15:47: is really that simple to work with
  • 15:50: discrete
  • 15:51: uh random values in python
  • 15:57: so then there's also a lab exercise
  • 16:00: on the discrete random numbers in both
  • 16:03: excel and python
  • 16:05: and so this lab exercise we're building
  • 16:08: out a
  • 16:09: simple model of stock returns
  • 16:12: and basically the stock starts at a
  • 16:14: hundred dollars
  • 16:16: and then it goes through a number of
  • 16:17: different periods
  • 16:19: and a hundred periods here
  • 16:22: and each period it can either go up or
  • 16:25: down
  • 16:26: and it's going to go up or down by a
  • 16:28: fixed uh percentage
  • 16:29: one percent here so
  • 16:33: you're picking between these two
  • 16:34: different random discrete cases
  • 16:37: up and down and the uh one percent or
  • 16:40: negative one percent
  • 16:42: that goes along with that and we have
  • 16:45: probabilities here of the stock going up
  • 16:47: and down sixty percent forty percent
  • 16:51: and you want to visualize what happens
  • 16:53: to that stock price
  • 16:54: over time and we want to complete this
  • 16:57: entire exercise
  • 16:59: in both excel and python
  • 17:04: so that's uh generating discrete random
  • 17:07: numbers
  • 17:08: in both excel and python
  • 17:11: um thanks for listening uh next time
  • 17:14: we're going to come back
  • 17:15: and look at adding internal randomness
  • 17:18: to an
  • 17:19: existing excel model so thanks for
  • 17:21: listening
  • 17:22: and see you next time

Adding Internal Randomness to an Excel Model


Notes

  • Typically you would add internal randomness as you build the model, not afterwards. It can require substantial changes to the original logic to add it afterwards

  • In most cases Monte Carlo simulation should be used when the model is already built

  • Here we will be randomly picking for each year whether it is a recession, normal, or expansion economy

  • In this case, as we want to add different behavior year by year based on the randomness, it is not possible via an external method such as Monte Carlo simulation

  • Here I am treating interest rate and savings rate as discrete random variables since they are tied to the state of the economy which is a discrete random variable. I could have assigned the quality of the economy to a normal distribution to make it continuous and then the other variables could be continuous as well

  • There are no special tricks here in Excel, we are just applying the previous approach for discrete random variables and hooking it into the model

Transcript

  • 00:02: hey everyone
  • 00:03: this is nick dear burtis teaching you
  • 00:05: financial modeling
  • 00:06: today we're going to be talking about
  • 00:08: how to add internal randomness
  • 00:10: to an existing excel model this is part
  • 00:14: of our lecture series on probabilistic
  • 00:16: modeling
  • 00:18: so we've covered what internal
  • 00:21: randomness
  • 00:22: is basically just including some kind of
  • 00:25: random component
  • 00:26: in your model and now we're looking at
  • 00:29: how we
  • 00:30: can apply that within an existing
  • 00:33: model so in this video we're going to be
  • 00:36: looking at adding it
  • 00:37: to the dynamic salary retirement model
  • 00:39: in excel
  • 00:40: and in the next video we're going to do
  • 00:42: the same thing with the python
  • 00:44: version of the dynamic salary retirement
  • 00:46: model
  • 00:48: so let's go ahead and jump over to that
  • 00:51: model
  • 00:51: so we can start adding this
  • 00:55: so what we're going to add here is
  • 00:58: uh that each year
  • 01:02: we currently um you know save a certain
  • 01:06: fixed amount
  • 01:08: and we invest that at a fixed amount
  • 01:13: a fixed rate as well and that happens
  • 01:16: every year
  • 01:18: but that's not very realistic some years
  • 01:21: there's going to be recessions
  • 01:23: some years there's going to be expansion
  • 01:25: periods in the economy
  • 01:26: and so we can expect different interest
  • 01:28: rates to prevail over time
  • 01:30: each year and same thing for the savings
  • 01:33: rate
  • 01:34: and so that's what we're going to build
  • 01:36: in here is
  • 01:37: each year it's going to randomly choose
  • 01:40: whether we're in
  • 01:42: a recession normal or expansion economy
  • 01:46: and that randomness is going to be based
  • 01:48: on probabilities which we're going to
  • 01:50: add as
  • 01:50: inputs to the model
  • 01:54: so the first thing we want to do is add
  • 01:57: those
  • 01:57: additional inputs so i'm going to move
  • 02:00: these outputs
  • 02:01: down so that we have additional room to
  • 02:04: have the inputs
  • 02:06: and then i'm going to go and start
  • 02:09: adding inputs
  • 02:11: so um we're now going to have
  • 02:15: economic condition inputs
  • 02:19: and that's going to be the economic
  • 02:22: probabilities
  • 02:26: and so we have three states of the
  • 02:30: economy
  • 02:30: recession normal and expansion and we
  • 02:33: only have to
  • 02:34: define two of those probabilities
  • 02:37: because the rest is just going to be
  • 02:39: one minus the others the normal uh
  • 02:42: economic chance is going to be one minus
  • 02:45: the recession and expansion chances
  • 02:47: so let's just start with 20 recession
  • 02:51: 30 expansion
  • 02:54: and now we have our probabilities set up
  • 02:57: the next is that
  • 02:58: we have a single savings rate and
  • 03:01: interest rate here which is
  • 03:02: for the entire model but now we're going
  • 03:05: to have
  • 03:06: different savings and interest rates
  • 03:09: depending
  • 03:09: on the economic condition
  • 03:12: so i'm just going to cut all of this to
  • 03:15: make some
  • 03:16: additional space
  • 03:22: and then i'm going to have the economic
  • 03:24: condition
  • 03:29: and then i'm going to have the interest
  • 03:30: rate
  • 03:34: for that economic condition and the
  • 03:36: savings rate
  • 03:39: for the same so then we're going to have
  • 03:41: recession
  • 03:43: uh normal and expansion come here
  • 03:50: so just so that nothing in the model
  • 03:52: breaks while we're moving things around
  • 03:54: i'm going to also
  • 03:56: cut this savings rate to the normal
  • 04:00: savings rate and
  • 04:01: cut this interest rate to the normal
  • 04:05: interest rate and that way because i use
  • 04:07: cut
  • 04:08: rather than copy or just moving in some
  • 04:10: other way
  • 04:11: everything still stays linked to
  • 04:14: that you can see now it's going to c11
  • 04:17: which is correct for the savings rate
  • 04:21: so now we want to add in the additional
  • 04:24: inputs
  • 04:24: of the recession and expansion interests
  • 04:27: and savings rates so let's put
  • 04:29: three percent in recessions uh six
  • 04:32: percent
  • 04:33: an expansion and we'll put
  • 04:36: say this as someone who's not
  • 04:38: financially constrained they're going to
  • 04:39: be
  • 04:41: not spending as much in the recession
  • 04:44: and so they're going to save more
  • 04:47: and of course you would want to reformat
  • 04:49: this so that all these inputs are neatly
  • 04:51: contained in there but i will
  • 04:53: skip that in this video for the sake of
  • 04:55: time the complete example with all
  • 04:56: formatting
  • 04:57: is there on the course site so
  • 05:02: now that we have our inputs set up we
  • 05:04: want to go ahead and bring those
  • 05:06: over to the wealth tab where we're doing
  • 05:09: our calculations
  • 05:11: with the savings and the wealth
  • 05:15: so now we're no longer just going to
  • 05:19: have
  • 05:20: this single normal
  • 05:24: single interest rate and savings rate
  • 05:26: now we're going to have
  • 05:28: all three of those depending
  • 05:31: on the economic conditions
  • 05:35: and we need to
  • 05:38: build out the table that we can use in
  • 05:42: excel
  • 05:43: to pick a random discrete variable
  • 05:45: because we're picking between these
  • 05:46: three different
  • 05:47: economic states and there's three
  • 05:50: possible values for that input
  • 05:53: recession normal or expansion and so
  • 05:54: that's a discrete variable
  • 05:57: so in order to build that out
  • 06:00: in excel
  • 06:03: so we're going to have the economic
  • 06:04: condition
  • 06:06: and we're going to have the probability
  • 06:11: and we can reference a couple of these
  • 06:16: from here the
  • 06:19: recession and twenty percent
  • 06:23: expansion and thirty percent i'm just
  • 06:25: going to cut that down
  • 06:26: so that we then have normal
  • 06:30: and this is going to be one minus the
  • 06:32: other two
  • 06:33: probabilities and i can format these all
  • 06:36: as a percentage
  • 06:39: so in order to pick our random discrete
  • 06:43: variables
  • 06:44: we need to create the cumulative
  • 06:46: probability
  • 06:48: so that's just going to be the
  • 06:50: cumulative sum
  • 06:51: of the probabilities some from the first
  • 06:55: cell
  • 06:56: to ex itself fixing the first part of
  • 06:59: that range but not the second
  • 07:02: so we reach 100 percent by the end
  • 07:07: um and then
  • 07:10: we also need to go ahead and
  • 07:13: bring the other inputs over to here so
  • 07:16: now i am going to go ahead and
  • 07:18: break this part of the model um because
  • 07:21: it's going to have to be reworked
  • 07:22: anyway so i delete those and of course
  • 07:26: now
  • 07:27: nothing works um and
  • 07:30: i'm going to bring this whole thing down
  • 07:34: cut it down a few cells to make some
  • 07:36: extra space
  • 07:38: and i'm going to reference over
  • 07:41: all the relevant inputs
  • 07:44: so the economic condition
  • 07:49: normal recession expansion
  • 07:55: and get the interest rate and savings
  • 07:57: rate for both of those
  • 08:01: so we're picking year over year every
  • 08:05: year
  • 08:06: whether we're in a recession normal or
  • 08:08: expansion
  • 08:10: economy
  • 08:13: so we want to go ahead
  • 08:17: and insert some additional
  • 08:22: columns here
  • 08:25: because now we're going to need to
  • 08:31: have a few extra calculations one to
  • 08:33: draw the probability
  • 08:35: one to pick the economic case based off
  • 08:38: that probability
  • 08:40: and then additional two to grab each of
  • 08:43: the inputs
  • 08:45: which are corresponding to that economic
  • 08:48: case
  • 08:52: so now i've made enough space um so
  • 08:54: we're going to have the
  • 08:57: probability uh the economic
  • 09:01: pace the interest rate
  • 09:05: and the savings rate
  • 09:12: and so for the drawn probability as
  • 09:16: we've seen
  • 09:17: previously on how to draw random
  • 09:20: discrete variables we're just going
  • 09:22: to use the rand
  • 09:25: function which is going to give us a
  • 09:27: random number between
  • 09:28: 0 and 1.
  • 09:35: and then we want to pick the economic
  • 09:37: case based upon that probability
  • 09:40: so if the drawn probability
  • 09:45: is um
  • 09:49: yeah if the drawn probability is
  • 09:54: um less than
  • 09:57: 20
  • 10:00: then we're going to get the recession
  • 10:05: case otherwise we're going to do another
  • 10:09: check
  • 10:09: if the drawn probability
  • 10:13: is less than the normal cumulative
  • 10:17: probability
  • 10:18: then it's going to be the
  • 10:21: expansion case or normal case
  • 10:25: and otherwise it's going to be the
  • 10:27: expansion case
  • 10:28: and then before we finish up with this
  • 10:31: formula
  • 10:32: let's carefully review and adjust the
  • 10:34: fixed references
  • 10:35: because ultimately um
  • 10:39: we want to set this up so that as we
  • 10:41: drag it over it's able to pull the
  • 10:42: interest rate and the savings rate
  • 10:44: um based off that drawn probability as
  • 10:48: well
  • 10:50: um so for the drawn probability
  • 10:54: we're going to want to have that fixed
  • 10:56: on the column
  • 10:58: but not fix on the row so
  • 11:01: um that the dollar sign comes before the
  • 11:05: letter then
  • 11:06: clicks on the dollar fixed on the column
  • 11:08: not on the row
  • 11:10: uh both of these cumulative
  • 11:12: probabilities totally fixed we don't
  • 11:14: want them to move
  • 11:16: and then each of these we don't want
  • 11:19: them to go up or down but we do want
  • 11:20: them to go to the right
  • 11:21: and so they're going to be fixed on the
  • 11:23: row but not on the column
  • 11:27: so again fix on the row not on the
  • 11:30: column
  • 11:32: so then i should be able to drag over
  • 11:36: and see the
  • 11:39: corresponding interest rate and savings
  • 11:42: rate
  • 11:43: and then complete this all the way down
  • 11:45: and
  • 11:46: now we see that
  • 11:49: when it's a low probability we're
  • 11:51: getting a recession when it's high we're
  • 11:52: getting expansion
  • 11:53: when it's middle grading normal and we
  • 11:56: are getting
  • 11:57: indeed the inputs which correspond
  • 12:00: to the expansion recession and normal
  • 12:04: case as well so everything we've done so
  • 12:06: far
  • 12:06: is working appropriately so now that's
  • 12:10: the discrete
  • 12:11: random variable part of this now we just
  • 12:13: need to
  • 12:14: reintegrate that into the model so
  • 12:18: this right now is doing the current
  • 12:21: salary times
  • 12:22: what was originally a single savings
  • 12:24: rate now it's going to be
  • 12:26: the savings rate given in the row
  • 12:32: so now the savings is working again
  • 12:35: and then initial wealth is just what you
  • 12:38: saved but after that
  • 12:39: you're going to be investing that prior
  • 12:41: wealth at the interest rate
  • 12:44: uh here it was just using a singular
  • 12:46: interest rate
  • 12:47: and now it's going to be the interest
  • 12:49: rate given in the row
  • 12:52: so also make that adjustment and carry
  • 12:55: that through
  • 12:56: and then we have it using the recession
  • 12:59: normal or expansion
  • 13:01: interest rate and savings rate and when
  • 13:04: we come back
  • 13:05: over to the entire model we can see that
  • 13:08: everything is
  • 13:08: flowing through properly the retirement
  • 13:11: tab is all still working
  • 13:13: uh salary and the
  • 13:16: input final inputs and outputs um
  • 13:20: and now we can see that if we
  • 13:21: recalculate the model then we get some
  • 13:24: different values of
  • 13:27: the results now that it is a
  • 13:30: internal randomness model with any
  • 13:34: internal randomness model
  • 13:36: you're going to get a different result
  • 13:37: each time that you run the model even
  • 13:39: with the same inputs
  • 13:42: and of course this was a fairly lengthy
  • 13:45: process to rework this
  • 13:47: section of the model to add this in
  • 13:49: generally if you're going to go with
  • 13:50: internal randomness
  • 13:52: you should decide that from the
  • 13:53: beginning so that you don't have to
  • 13:55: rework
  • 13:56: these portions of the model and
  • 13:59: oftentimes if you already have the model
  • 14:01: built then you can use monte carlo
  • 14:03: simulation
  • 14:04: as another way to add randomness to your
  • 14:07: model without having to change the
  • 14:09: internal workings of it
  • 14:12: but that's a quick run through of how we
  • 14:14: can add
  • 14:15: internal randomness to an existing excel
  • 14:18: model
  • 14:19: so thanks for listening and see you next
  • 14:22: time

Adding Internal Randomness to a Python Model


Notes

  • See the notes for Adding Internal Randomness to an Excel Model as the conclusions are the same here

  • It is quite an effort to add internal randomness which is this integral to the model after it has already been built

  • Similarly to in Excel, there are not any new concepts in this lecture, but we are just applying the discrete random variables concepts and integrating into the model

Transcript

  • 00:02: hey everyone
  • 00:03: nick dear burtis here teaching you
  • 00:05: financial modeling
  • 00:06: today we're going to be adding internal
  • 00:09: randomness
  • 00:10: to a python model this is part of our
  • 00:13: lecture series
  • 00:14: on probabilistic modeling
  • 00:17: so we've already covered the internal
  • 00:21: randomness material
  • 00:22: just adding randomness somewhere within
  • 00:24: the core of your model
  • 00:26: and we also already looked at an example
  • 00:29: of how we can
  • 00:30: add that to an excel model so in this
  • 00:32: video
  • 00:33: we're going to explore the python side
  • 00:35: of working
  • 00:36: internal randomness into an existing
  • 00:38: model
  • 00:40: and i just want to preface this with
  • 00:43: when you use internal randomness
  • 00:45: it definitely makes a lot of sense to
  • 00:46: plan for it at the outset of the model
  • 00:50: if you have to go back and rework a
  • 00:52: model to add internal randomness
  • 00:53: it can require having to redo a lot of
  • 00:56: the logic
  • 00:57: so try to plan for if you're going to
  • 01:00: use internal randomness and add it from
  • 01:02: the beginning
  • 01:03: but we're going to show how you can kind
  • 01:06: of rework
  • 01:07: a model to add it in those cases where
  • 01:10: you didn't plan for that
  • 01:12: in a lot of cases you can just use monte
  • 01:14: carlo simulation
  • 01:16: to do the same thing without
  • 01:19: having to completely rework the logic of
  • 01:22: the model
  • 01:23: but let's go ahead and look at this
  • 01:26: example
  • 01:27: with internal randomness for python
  • 01:32: so we can go over to our existing
  • 01:34: dynamic salary retirement model
  • 01:37: we've built out in prior videos and i'm
  • 01:40: just going to quickly
  • 01:41: uh restart kernel run all cells so that
  • 01:44: we have
  • 01:44: everything defined
  • 01:48: and we're going to build this out at the
  • 01:51: bottom
  • 01:52: of the model
  • 01:53: [Music]
  • 01:55: so this does require a substantial
  • 01:58: rework
  • 01:59: of what we already have
  • 02:02: and so you know normally i would
  • 02:06: recommend just
  • 02:07: saving a separate copy of the model and
  • 02:09: then just going in
  • 02:10: and modifying the code which is already
  • 02:13: there
  • 02:15: or even better use version control
  • 02:19: but here just to have one
  • 02:23: uh comprehensive example i'm adding it
  • 02:25: on the ends and i'm going to
  • 02:26: copy paste some of the uh prior logic
  • 02:31: to help rebuild it with internal
  • 02:34: randomness
  • 02:36: so for this uh exercise i'm going to
  • 02:40: consider
  • 02:41: the same situation that we had in excel
  • 02:46: where we have three different states of
  • 02:49: the economy
  • 02:50: recession normal and expansion and each
  • 02:53: year
  • 02:53: we're randomly put into one of these
  • 02:56: states of the world based on the
  • 02:57: probabilities of those states
  • 03:00: and the inputs are going to align with
  • 03:03: that state of the world
  • 03:07: we're going to go a little bit further
  • 03:08: than the
  • 03:11: excel exercise which just looked at
  • 03:16: the the interest rate and the savings
  • 03:18: rate we're going to go ahead and do it
  • 03:20: with all the different inputs
  • 03:24: aligning them in the recession normal
  • 03:26: and expansion
  • 03:27: cases um
  • 03:31: so the first thing that we want to do is
  • 03:33: set up
  • 03:34: the new inputs for our model because now
  • 03:38: we're going to have different inputs for
  • 03:40: each possible case
  • 03:43: um and uh
  • 03:46: we have to have a new structure for that
  • 03:48: as well
  • 03:50: so i'm going to copy this again you know
  • 03:52: if you were going to do this
  • 03:54: probably just modify your existing
  • 03:57: with it being backed up and
  • 04:00: then now we're not going to just have a
  • 04:03: single number for each of these
  • 04:05: we're going to have multiple numbers
  • 04:07: corresponding to the different states of
  • 04:08: the world
  • 04:11: but let me add
  • 04:14: the recession probability
  • 04:19: let's say that's 20 by default and let's
  • 04:22: add the expansion probability
  • 04:29: and um
  • 04:33: one additional input we can add as well
  • 04:36: is the names of the different cases that
  • 04:40: we're looking at
  • 04:42: so we can have a recession
  • 04:46: normal expansion economy
  • 04:51: so we'll go ahead and modify the
  • 04:54: existing inputs now so that we have
  • 04:58: one for the recession one for the normal
  • 04:59: and one for the expansion
  • 05:02: and you'll notice here i used a tuple
  • 05:05: for the inputs not a list
  • 05:07: the reason that i'm using a tuple over a
  • 05:10: list
  • 05:11: starts to get a little bit outside of
  • 05:13: the scope of this class it
  • 05:14: has to do with the mutability of a list
  • 05:18: the fact that it can be modified
  • 05:20: in place and that can actually change
  • 05:23: the default values of your inputs
  • 05:25: after you've defined them
  • 05:29: but we're not going to really discuss
  • 05:30: that in detail just know that if you
  • 05:32: want to put
  • 05:33: multiple values of something in your
  • 05:36: data class
  • 05:37: defaults then use a tuple rather than a
  • 05:39: list
  • 05:42: so i'm going to convert all these tubals
  • 05:44: and
  • 05:45: here let's say 40 000 and the bad
  • 05:49: 70 000 and the good um
  • 05:54: and then for promotions let's do uh
  • 05:58: or it takes longer when we're in the
  • 06:01: recession every eight years
  • 06:02: four years in the expansion economy
  • 06:06: we're going to convert the cost of
  • 06:08: living raise let's just do
  • 06:10: one percent for the bad economy three
  • 06:13: percent
  • 06:14: for the good economy uh
  • 06:17: for the promotion raise
  • 06:20: again that's going to be lower here in
  • 06:23: the
  • 06:23: recession and higher in the expansion
  • 06:28: um and for the savings rate
  • 06:32: um let's do here go with the
  • 06:36: uh individual who is financially
  • 06:38: constrained so they're not able to save
  • 06:40: as much
  • 06:41: in the recession and then
  • 06:45: for the interest rate
  • 06:48: we can go with um
  • 06:53: three percent lower interest rate for
  • 06:55: the
  • 06:56: recession uh and a higher interest rate
  • 06:59: for the expansion
  • 07:00: desired cash i'm going to leave as is
  • 07:02: because um
  • 07:04: the the amount of cash you need to
  • 07:06: retire shouldn't really be affected by
  • 07:08: whether you're in a recession or
  • 07:10: expansion period
  • 07:13: so now we have our new model data which
  • 07:16: has tuples
  • 07:17: for most of the inputs rather than
  • 07:20: single values
  • 07:24: so most of the rest of the work is just
  • 07:27: going to be taking
  • 07:28: the existing model and adapting it to
  • 07:30: work with these tuples and
  • 07:32: and pick the correct input from the
  • 07:35: tuples
  • 07:39: but first we need to be able to
  • 07:43: randomly pick whether we're in the
  • 07:46: recession normal or expansion
  • 07:47: case um so
  • 07:52: i'm going to write a function to do that
  • 07:55: and for picking recession normal or
  • 07:57: expansion
  • 07:58: i'm going to use zero to represent a
  • 08:01: recession
  • 08:02: one to represent normal and two to
  • 08:04: represent expansion
  • 08:05: because then we can just directly use
  • 08:07: that number to index
  • 08:09: these tuples and certainly you would
  • 08:11: want to write that up in the docs string
  • 08:13: of the function
  • 08:15: and include that in the jupyter
  • 08:16: description as well
  • 08:18: and you can see all that in the
  • 08:19: completed example on the course site
  • 08:25: we're going to need to use the random
  • 08:27: module uh
  • 08:29: to pick these random discrete variables
  • 08:32: so i'm going to go back to the top
  • 08:33: and i'm going to import random
  • 08:40: and come back to the bottom
  • 08:43: so first thing we can do is calculate
  • 08:46: the normal probability
  • 08:49: which is just going to be one minus uh
  • 08:53: right here let me do data equals model
  • 08:55: data so we can write our logic with data
  • 08:58: um data dot uh
  • 09:02: the recession probability minus data dot
  • 09:05: the expansion probability
  • 09:08: and now we want to get that 0 1 2 um so
  • 09:12: we can call that the case number
  • 09:14: and we're going to use the
  • 09:15: random.choices function
  • 09:18: in order to pick that so um
  • 09:22: zero one and two is what we're picking
  • 09:24: from
  • 09:25: and the weights for that are going to be
  • 09:29: um first the uh recession probability
  • 09:34: and then this normal probability that we
  • 09:36: just calculated and finally
  • 09:38: the expansion probability and we just
  • 09:41: want a single
  • 09:42: case number so i'm going to extract that
  • 09:45: from the list
  • 09:45: by indexing it with zero and then we can
  • 09:49: take a look at what we got
  • 09:51: um and as i run this we can see that
  • 09:54: we're getting
  • 09:55: different cases zero one and two
  • 09:58: uh getting randomly picked so now we can
  • 10:02: convert this into a function
  • 10:04: def get economy base number
  • 10:10: that takes the data
  • 10:13: and then just end in this and return the
  • 10:16: case number
  • 10:20: and then
  • 10:24: this should still work the same way yep
  • 10:26: we're still getting
  • 10:28: random different economy case numbers
  • 10:32: so then we have to take this
  • 10:36: and our new inputs and kind of rework
  • 10:39: the model
  • 10:40: so i'm going to go and just grab all the
  • 10:44: main model functions uh the salary ear
  • 10:47: function
  • 10:47: [Music]
  • 10:50: um go and grab the
  • 10:54: um cash saved
  • 10:57: function cash saved during year
  • 11:01: again you know if you're doing this with
  • 11:03: your own model just
  • 11:04: back it up and then you can just
  • 11:06: directly modify things rather than
  • 11:09: having two copies of your code you
  • 11:11: generally do not want to have
  • 11:13: two copies of your code because that
  • 11:16: creates a big
  • 11:17: maintainability issue um
  • 11:22: but we're just
  • 11:25: you know doing this here for sake of
  • 11:27: example
  • 11:32: so now i've got all the main functions
  • 11:35: from the model
  • 11:38: so i'm going to look at reworking these
  • 11:41: um
  • 11:42: so i'm just going to you know take out
  • 11:45: the main logic here so i can
  • 11:48: try it out um
  • 11:52: so if i go and run that
  • 11:56: you can see that it already is not
  • 11:58: working appropriately right and that's
  • 11:59: because we've changed
  • 12:00: the structure of the inputs they don't
  • 12:03: work the same way
  • 12:04: anymore so um
  • 12:10: it's trying to do math with the tuple
  • 12:11: when it should have been an integer
  • 12:14: um or it should have been a number
  • 12:18: so um what we can do
  • 12:22: is can think of structuring this as
  • 12:25: you know basically we're going to have
  • 12:28: in this
  • 12:29: final loop where we uh go over each year
  • 12:33: we're going to be picking the case
  • 12:35: number within that year
  • 12:36: and then we can pass that case number
  • 12:39: into the other functions
  • 12:40: so that they can work with that same
  • 12:44: economic case so i'm just going to go
  • 12:47: ahead and
  • 12:48: call case equals get economy case number
  • 12:53: uh on the data and now i just have case
  • 12:57: defined
  • 12:58: later i'm going to remove that it'll be
  • 13:00: built into only the function
  • 13:02: but this will help us build out this
  • 13:04: logic initially in the cell
  • 13:06: so the problem now you can see it's
  • 13:10: pointing to this line with data promos
  • 13:12: every n years
  • 13:14: because now that's a tuple and not a
  • 13:16: single number you can't divide a number
  • 13:18: by a tuple
  • 13:20: but if we pull out the
  • 13:24: the case right now is the expansion
  • 13:27: economy
  • 13:28: and if we pull out the
  • 13:33: expansion economy
  • 13:36: um
  • 13:39: then yeah that's getting the input from
  • 13:41: the expansion economy
  • 13:43: um having the permissions every four
  • 13:46: years rather than five
  • 13:48: so all we've got to do to fix this part
  • 13:50: is
  • 13:52: put the case there and now we run this
  • 13:55: again
  • 13:55: it still doesn't work but now we can see
  • 13:58: it's complaining
  • 13:59: about the next line again
  • 14:03: another error about using a tuple uh
  • 14:06: because again we want to be using
  • 14:08: numbers here
  • 14:10: but it's these are all tuples so we can
  • 14:13: do the same thing
  • 14:14: with starting salary with cost of living
  • 14:18: raise
  • 14:22: and the promotion raise
  • 14:27: and now let's try this again and now we
  • 14:30: can see
  • 14:31: that we do indeed get the salary
  • 14:33: appropriately now
  • 14:35: so i'm going to take this logic
  • 14:38: and i'm going to now bring it into this
  • 14:41: function
  • 14:43: um make sure to return that salary
  • 14:47: and let's move on to the next function
  • 14:51: so well let me run this so that
  • 14:54: the new salary is defined oh and there's
  • 14:57: one more thing we need to do we need to
  • 14:59: pass the case
  • 15:00: into this function as well so it's not
  • 15:02: just using
  • 15:03: this specific case that we pulled one
  • 15:05: time we wanted to be able to take
  • 15:07: whatever case that we want to use
  • 15:10: so um
  • 15:14: now we can come to the next function
  • 15:16: cash saved during year
  • 15:18: take a look at that logic um
  • 15:21: and let's try to run that so
  • 15:24: we'll see the first error here coming up
  • 15:26: on the first line the salary airline
  • 15:29: now we're missing the case argument we
  • 15:31: want to
  • 15:32: pass the case there as well so then we
  • 15:36: run it again
  • 15:36: and now it's failing at second line and
  • 15:40: that's because here
  • 15:41: we need to look at the case as well and
  • 15:44: now
  • 15:44: it works just fine now we can take this
  • 15:47: logic
  • 15:48: we can bring it over to cash saved
  • 15:51: during year we want to make sure that we
  • 15:54: return it
  • 15:55: and we want to add case as an additional
  • 15:57: input
  • 15:59: rerun this so that this function is
  • 16:02: redefined
  • 16:04: and now let's work on the next one we're
  • 16:06: getting close
  • 16:09: so um
  • 16:13: now run that we can see same pattern
  • 16:16: as we saw before we're not passing the
  • 16:18: case here so let's do that
  • 16:20: and now it's failing on the second line
  • 16:22: where we're not pulling
  • 16:24: the case interest rate uh so now this
  • 16:27: is working appropriately as well we can
  • 16:30: go and bring that
  • 16:32: into wealthy ear and return that
  • 16:37: and add the case as an additional
  • 16:39: argument
  • 16:41: and so now we come to our final function
  • 16:45: the year's retirement function make sure
  • 16:48: we rerun this to define it
  • 16:51: and now bring this logic out here
  • 16:57: so when we try running this um
  • 17:00: so first thing for an output is not
  • 17:02: defined
  • 17:04: um so i'm just going to add that print
  • 17:07: output
  • 17:08: let's make it true
  • 17:11: um and then we see
  • 17:14: same pattern well the year we're not
  • 17:16: passing the case
  • 17:18: but here now we've gotten to the main
  • 17:20: loop
  • 17:21: we don't just want to use the existing
  • 17:25: case which we had as an example case
  • 17:27: we want to actually
  • 17:30: get the case in each year so the case
  • 17:33: here
  • 17:34: we're getting within every year and we
  • 17:37: want to pass that
  • 17:38: here to the wealth function now we run
  • 17:41: this
  • 17:43: and it did finish appropriately
  • 17:47: uh because the only other input that
  • 17:48: we're using here is desired cash
  • 17:51: and that one we only have a single value
  • 17:54: for it so we should be able to run this
  • 17:56: multiple times yep and see different
  • 17:58: years for retirement each
  • 18:00: time corresponding to the
  • 18:04: different economic conditions which are
  • 18:06: going on
  • 18:08: in this front of the model so
  • 18:11: the last adjustment that we would want
  • 18:13: to make here is
  • 18:14: right now it's not clear which years are
  • 18:17: recessions which user expansion
  • 18:19: which year are uh normal
  • 18:22: so we can add that into the print output
  • 18:25: as well
  • 18:26: um so we can
  • 18:30: get the case type we had that
  • 18:34: in the data the case inputs we're going
  • 18:38: to look that up by the case
  • 18:40: and then we can say uh case type
  • 18:45: economy in the output
  • 18:48: and now we see normal expansion
  • 18:51: recession
  • 18:52: it's showing what type of economy is
  • 18:55: occurring
  • 18:56: in each year and we can see that it
  • 18:58: changes its time
  • 19:02: and when there's more normal expansion
  • 19:06: we've got a short due to retirement when
  • 19:10: we've got more recessions less expansion
  • 19:14: then it's going to take longer to retire
  • 19:18: so then we can take this logic
  • 19:22: we don't want the print output part take
  • 19:24: this logic and we can put it back
  • 19:26: into the function
  • 19:33: and we want to make sure that we return
  • 19:35: the year then
  • 19:39: and now we should be able to run
  • 19:42: the full model and
  • 19:45: it is indeed working
  • 19:50: so now we have it working for basic
  • 19:53: model
  • 19:54: but whenever you have randomness built
  • 19:57: into a model
  • 19:58: the internal randomness or adding it
  • 20:00: externally via monte carlo simulation
  • 20:05: now your model will give different
  • 20:07: outputs for the same inputs
  • 20:09: each time that you run it so you
  • 20:11: generally want to
  • 20:12: run the model numerous times
  • 20:15: and summarize the outputs from it in
  • 20:18: some way
  • 20:21: so what we're going to do is we're going
  • 20:24: to make a loop
  • 20:25: where we run the model multiple times
  • 20:32: so um
  • 20:35: and here i'm going to do a little bit ad
  • 20:37: hoc we could also
  • 20:39: let me go back and add the number of
  • 20:42: iterations into the model inputs as well
  • 20:46: so number of iterations um and let's
  • 20:50: make that a thousand
  • 20:53: um
  • 20:58: it looks gotta be uh integer equals
  • 21:01: thousand
  • 21:02: there we go
  • 21:06: and now um
  • 21:10: so we want to create a list which is
  • 21:13: going to store
  • 21:14: our user retirement uh we want to loop
  • 21:19: or gotta make sure to rerun that data
  • 21:24: cell give the new data
  • 21:28: um the number of iterations
  • 21:32: um we're going to
  • 21:35: calculate the used retirement
  • 21:39: um and real quickly
  • 21:42: i'm just going to make the number of
  • 21:45: iterations low just for
  • 21:47: testing purposes um
  • 21:51: and so we're running for that number of
  • 21:52: iterations and we're going to calculate
  • 21:55: the use for retirement with
  • 21:58: the data
  • 22:02: and we don't want to print the output
  • 22:04: because that would be a ton of output
  • 22:06: to be showing running the model multiple
  • 22:08: times
  • 22:11: and then we want to append the result uh
  • 22:14: to our list
  • 22:18: okay so there we should be getting yep
  • 22:21: now we have some different years for
  • 22:22: retirement
  • 22:24: um i already have pandas imported
  • 22:28: let's see
  • 22:33: i do okay cool um so then i can
  • 22:37: put those years to retirement in a data
  • 22:40: frame
  • 22:43: so that it's easy to summarize it
  • 22:47: so i want to get the average
  • 22:52: um
  • 22:56: i want to get
  • 22:59: let's see not just the average i want to
  • 23:00: get the standard deviation
  • 23:02: i want to get the max and i want to get
  • 23:04: them in so that's
  • 23:05: std max and min
  • 23:11: and let's print that out
  • 23:16: it will take
  • 23:19: the average ytr
  • 23:24: zero decimal place is fixed here's your
  • 23:27: tire
  • 23:29: on average with a standard
  • 23:32: deviation of uh fcd
  • 23:36: ytr let's let that have
  • 23:39: one decimal place
  • 23:43: max of max ytr
  • 23:50: and men of command ytr
  • 24:01: and we can break this onto multiple
  • 24:03: lines because it's really long
  • 24:14: i forgot my quote over here there we go
  • 24:19: okay um
  • 24:23: and so then
  • 24:26: now we can try this with the full number
  • 24:28: of iterations
  • 24:29: thousand iterations run this again
  • 24:33: um and we see on average
  • 24:36: 26 years to retire standard deviation of
  • 24:40: 1.6 max of 31 minimum
  • 24:43: of 22. so that gives us quite a bit more
  • 24:45: information about
  • 24:47: the retirement possibilities based on
  • 24:50: the different possible states of the
  • 24:52: economy
  • 24:55: and since we're making this part of the
  • 24:57: core model we can also
  • 24:59: bring all this into functions
  • 25:02: so we can make this
  • 25:07: here it's retirement
  • 25:11: uh let's call it kcf
  • 25:15: um and that takes the data
  • 25:20: and it's gonna return the data frame
  • 25:24: and then we can make a summarize
  • 25:29: here's your retirement df that's going
  • 25:31: to take the df
  • 25:33: um and it's going to do this stuff
  • 25:41: so then um we can have one more function
  • 25:45: that calls
  • 25:46: both so um
  • 25:52: here's retirement cases and summarize
  • 25:57: which calls this to get the data frame
  • 26:02: and then does the summarization
  • 26:08: so then we can directly call this here's
  • 26:11: to retirement cases and summarize on the
  • 26:13: data and we directly
  • 26:15: get to that string and we can try it
  • 26:18: uh with whatever other inputs we want
  • 26:21: say we want
  • 26:22: 2.5 million desired cash
  • 26:26: then it's going to take longer
  • 26:32: something seems to not be working there
  • 26:35: appropriately because it's
  • 26:37: not adjusting as i
  • 26:42: pass additional as i update the desired
  • 26:46: cache
  • 26:47: so let's go back
  • 26:50: and look um
  • 26:59: so aha
  • 27:03: i still have this this line that i had
  • 27:06: just for testing purposes
  • 27:08: uh where it's redefining the data and
  • 27:09: that means it's no longer taking the
  • 27:11: data as an input
  • 27:12: it's overwriting it so let's take that
  • 27:14: out
  • 27:16: rerun that rerun this yeah now it is
  • 27:20: working appropriately
  • 27:21: if you really needed um 250 million
  • 27:24: dollars to retire
  • 27:25: you want to have a really lavish
  • 27:27: lifestyle then
  • 27:28: you're probably going to die before you
  • 27:30: actually get to retirement
  • 27:34: so now everything is working
  • 27:36: appropriately
  • 27:38: so that's how we can add internal
  • 27:41: randomness
  • 27:42: to an existing python model again
  • 27:45: uh you generally would want to build
  • 27:47: this end from the start and then it
  • 27:49: would not be
  • 27:49: such a large effort to build it in um
  • 27:53: and in most cases you could use monte
  • 27:56: carlo simulation
  • 27:57: as an alternative to adding internal
  • 27:59: randomness to an existing model
  • 28:04: so thanks for listening and see you next
  • 28:07: time

Internal Randomness Lab Exercises Overview


Notes

  • Whereas I was adding internal discrete randomness in the examples, now you will add internal continuous randomness to your own model

  • I have selected the investment return as the random variable as it is only used in the NPV calculation. It should only require minimal changes to your model to integrate this

  • This is a case where we would normally use Monte Carlo simulation as we are just randomizing the existing inputs. Here we are just applying internal randomness to understand how to implement it

Transcript

  • 00:02: hey everyone
  • 00:03: nick dearborn is here teaching you
  • 00:05: financial modeling today we're going to
  • 00:07: be going over
  • 00:08: the lab exercise to wrap up the internal
  • 00:12: randomness material
  • 00:13: this is part of our lecture series on
  • 00:15: probabilistic modeling
  • 00:19: so we covered all the internal
  • 00:21: randomness material already including
  • 00:23: examples of how to add it to excel in
  • 00:26: python models
  • 00:27: so the way we are going to wrap it up is
  • 00:30: for you to
  • 00:31: do the same with your own project one
  • 00:34: excel and python models
  • 00:37: so here we're going to make the interest
  • 00:40: rate
  • 00:41: and the model a continuous
  • 00:44: random variable
  • 00:48: so i selected the interest rate because
  • 00:52: it's not going to require much of a
  • 00:54: change
  • 00:55: to your existing models so
  • 00:58: nowhere near as involved as the examples
  • 01:02: i just showed
  • 01:03: with adding uh internal randomness to
  • 01:06: excel and python
  • 01:09: so the interest rate is only used in the
  • 01:11: mpv calculation in this model and so
  • 01:14: that's
  • 01:14: all that has to change as a result of
  • 01:18: this
  • 01:20: so here now instead of just
  • 01:23: taking the interest rate as is instead
  • 01:26: we're going to have a mean and standard
  • 01:28: deviation of that interest rate
  • 01:30: as model inputs and the model is going
  • 01:33: to draw
  • 01:34: a random interest rate from a normal
  • 01:37: distribution
  • 01:38: each time that you run the model so you
  • 01:41: should be able to run the model
  • 01:42: repeatedly
  • 01:43: and see different mpvs coming out as a
  • 01:46: result
  • 01:48: and i would recommend making a copy of
  • 01:51: your models
  • 01:52: to add this extension because
  • 01:55: adding randomness into a model does make
  • 01:58: it
  • 01:59: harder to work with going forward and
  • 02:01: this is not the last extension that
  • 02:03: we're going to look at
  • 02:04: for the project 1 model
  • 02:08: so that's the idea behind this exercise
  • 02:12: and that wraps up our lecture series on
  • 02:15: probability modeling so thanks for
  • 02:18: listening
  • 02:18: and see you next time