Getting Started with Python and Excel

Discusses the basics of financial modeling in both Python and Excel. Explores a simple time-value of money problem and how to build a model for it in both Python and Excel.

Introduction and an Example Model


Notes

  • In the beginning of the course, we will do everything with both Excel and Python to understand the differences. Later we will focus on choosing the best tool for the task at hand and the ability to combine the two tools.

  • Everyone should know how to solve this simple time-value of money investment problem

  • Many would think to reach for a financial calculator and use the five keys

  • Or to directly type some values into the =NPER function in Excel

  • With either of these approaches, you are doing a calculation rather than building a model

  • If you realize you need to adjust the inputs, you need to do the calculation again

  • With a model, the calculations are linked from the inputs to the outputs, so changing the inputs changes the outputs. This increases reproducibility and efficiency.

Transcript

  • 00:03: hey everyone
  • 00:04: nick dear bird is here teaching you
  • 00:06: financial modeling and today we're going
  • 00:08: to talk about
  • 00:09: building a basic model in both excel and
  • 00:11: python
  • 00:12: in this first video in this series we're
  • 00:14: just going to introduce the basic
  • 00:16: model and talk about the structure
  • 00:19: before we dive into
  • 00:21: actually implementing that model in
  • 00:23: excel in python
  • 00:24: in the following videos so
  • 00:27: let's go ahead and look at what we're
  • 00:30: talking about with this basic model
  • 00:33: so really the focus here is that we want
  • 00:36: to get
  • 00:37: just familiar working in both excel and
  • 00:39: python
  • 00:40: and for the first part of the course
  • 00:42: we're going to just do
  • 00:44: everything the same things in both excel
  • 00:46: and python so you can get a good feel
  • 00:49: for both of the tools
  • 00:52: and then in the future we're going to go
  • 00:54: to actually
  • 00:55: combining excel in python and
  • 00:59: get more into you know how you should be
  • 01:01: choosing which of those tools you're
  • 01:02: using to solve a particular
  • 01:04: problem
  • 01:08: so the problem that we're going to look
  • 01:09: at to model
  • 01:11: is uh intentionally very simple
  • 01:14: it's basically the simplest finance
  • 01:17: problem out there just a time value of
  • 01:18: money problem
  • 01:20: and i've chosen this problem because it
  • 01:23: lets
  • 01:24: us not focus very much on the actual
  • 01:28: content of the model everyone should
  • 01:30: know basically what's involved
  • 01:32: with the calculations we're just going
  • 01:34: to focus on how you actually implement
  • 01:36: that
  • 01:37: in each of these two tools and how we
  • 01:40: make that a model rather than just doing
  • 01:42: a single calculation
  • 01:45: so you know for this kind of problem
  • 01:49: you may have used a calculator in the
  • 01:52: past
  • 01:53: thinking about a retirement problem
  • 01:56: how much how soon can someone
  • 02:00: retire given that they are earning a
  • 02:03: certain amount
  • 02:04: saving a certain amount and they
  • 02:08: have a certain amount of cash that they
  • 02:10: need to be able to retire
  • 02:12: um so this is kind of the traditional
  • 02:15: uh you know five keys on the financial
  • 02:17: calculator
  • 02:18: uh for those that are familiar with
  • 02:20: those
  • 02:22: you know that type of problem so
  • 02:24: certainly very easy to do on a
  • 02:25: calculator
  • 02:26: but we're going to look at how to
  • 02:28: actually build a model for this
  • 02:32: and so just to quickly break down what
  • 02:35: this model
  • 02:36: looks like so again going back to this
  • 02:40: idea that a model is just a
  • 02:43: representation
  • 02:44: of a real world process
  • 02:47: and the real world process here is that
  • 02:49: this individual
  • 02:50: is saving they have wages coming in and
  • 02:53: they save a certain amount of that
  • 02:55: and then they invest that money at a
  • 02:58: certain
  • 02:59: rate of return up until they reach
  • 03:02: however much cash they want to have
  • 03:05: and that's going to tell us what the
  • 03:07: number of years is
  • 03:09: um so in the model of this
  • 03:12: uh we're gonna bring in you know the the
  • 03:15: wages
  • 03:16: the cash coming from the wages um
  • 03:19: you know involving the savings rate we
  • 03:20: got to use the savings rate to determine
  • 03:22: how much
  • 03:23: actually um cash is going to be coming
  • 03:25: into the investment portfolio
  • 03:27: each year and of course we need the
  • 03:30: interest rates to determine
  • 03:31: how much is going to be earned on these
  • 03:33: investments
  • 03:34: and then the model is taking those
  • 03:37: inputs and converting that
  • 03:39: ultimately into the years
  • 03:42: until retirement so that's the basic
  • 03:45: model
  • 03:46: and in the next video we're going to
  • 03:48: look at how we can implement this basic
  • 03:51: model
  • 03:52: in excel thanks for listening

Building a Simple Excel Model


Notes

  • It is crucial that all your Excel calculations are linked together by cell references. If you hard-code values in your calculations you are just using Excel as a calculator.

  • It is important to visually separate the inputs from the outputs. This makes it much more clear for the consumer of your model, especially in more complex models

  • More complex models should be broken into multiple sheets with each sheet dedicated to a concept or calculation

  • Cell formatting can be used in combination with the layout to separate them

  • For small models, intermediate outputs/calculations may be kept in the outputs section, while for larger models it makes sense to have separate calculation sections

Transcript

  • 00:04: hey everyone
  • 00:05: nick dear burtis here teaching you
  • 00:06: financial modeling and today
  • 00:08: we're going to talk about implementing a
  • 00:10: basic financial model
  • 00:12: in excel so we left off last time just
  • 00:16: talking about
  • 00:17: uh you know the kind of model that we're
  • 00:18: gonna implement here a basic retirement
  • 00:20: model
  • 00:21: uh but here we're gonna just jump right
  • 00:23: into building this out in excel
  • 00:26: so uh you know it's easy to use excel
  • 00:29: and just kind of type the numbers right
  • 00:32: into
  • 00:33: your functions but if you use it that
  • 00:36: way you're basically just treating excel
  • 00:38: as a calculator rather than building a
  • 00:40: model with a model
  • 00:43: everything should flow from the inputs
  • 00:45: to the outputs
  • 00:46: so you change an input and you should
  • 00:48: see the change
  • 00:49: in the output uh of course if you just
  • 00:52: hard code the numbers
  • 00:53: into the formulas themselves
  • 00:56: then you're not going to have that
  • 00:58: flexibility of being able to
  • 01:01: look at a bunch of different inputs and
  • 01:02: understand the different
  • 01:04: outputs that come out as a result
  • 01:07: so the way that you can make sure that
  • 01:09: everything stays linked
  • 01:10: together in excel is to use cell
  • 01:13: references
  • 01:14: rather than just typing the numbers in
  • 01:16: for your formulas
  • 01:19: so you know those are like you know
  • 01:23: a2 or whatever is a cell reference
  • 01:27: and then we also have fixed versus
  • 01:30: relative
  • 01:30: references and that comes into play
  • 01:34: when you want to drag the formula
  • 01:37: to have it repeat iterate across
  • 01:40: multiple different cells when you do
  • 01:43: that drag
  • 01:44: for fixed references the reference is
  • 01:47: not going to move as you drag it
  • 01:49: and for relative references it is going
  • 01:51: to move as you drag it and relative
  • 01:53: references
  • 01:54: are the default so that should become a
  • 01:58: lot more clear
  • 01:59: as we get into the extension
  • 02:03: of the excel model with iteration
  • 02:06: that we'll do in a follow-on video
  • 02:10: um but for now we can just uh look at
  • 02:13: how to implement the basic model
  • 02:15: in excel of solving this retirement
  • 02:19: problem um so
  • 02:23: we can uh pull up excel here
  • 02:27: and so you know the first thing that you
  • 02:30: usually want to do
  • 02:31: with your model is you want to lay out
  • 02:34: all the different inputs that you have
  • 02:37: so in this problem we
  • 02:41: had the salary we had the savings rate
  • 02:46: we have the interest rate
  • 02:49: um and we have the desired cash
  • 02:54: and so um we can go ahead and put in
  • 02:57: those default numbers
  • 02:59: for those inputs from the problem so the
  • 03:01: salary
  • 03:02: was 60 000 the savings rate
  • 03:06: 25 the interest rate is
  • 03:09: 5 and the desired cash
  • 03:12: is 1.5 million
  • 03:16: um and when you're structuring your
  • 03:19: excel models
  • 03:20: you definitely want to keep your inputs
  • 03:23: separate from your outputs that way it
  • 03:26: becomes
  • 03:27: very clear as a user of the model what
  • 03:29: you can change around
  • 03:31: and what is going to be the result of
  • 03:34: changing those inputs around
  • 03:36: it makes it a lot easier to consume your
  • 03:38: model
  • 03:40: so here we'll make a separate outputs
  • 03:42: section
  • 03:43: and in that outputs section then we can
  • 03:46: do our actual
  • 03:47: calculations now if you're building a
  • 03:49: more complex model
  • 03:50: you can kind of break this out more and
  • 03:52: have different spots for calculations
  • 03:54: and
  • 03:54: and one spot for final outputs and and
  • 03:57: we'll get into that structure
  • 03:58: as we go on in the course but for now
  • 04:00: this is very simple
  • 04:02: let's just put all the uh calculations
  • 04:04: and outputs
  • 04:05: in the outputs section the biggest thing
  • 04:07: is just keeping your inputs
  • 04:09: separate from everything else so for our
  • 04:12: outputs um
  • 04:14: we could go directly to uh
  • 04:17: doing the actual main calculation of the
  • 04:19: model getting the number of years to
  • 04:21: retirement
  • 04:22: um but i'm going to do first an
  • 04:24: intermediate calculation
  • 04:25: and that intermediate calculation is
  • 04:28: going to be
  • 04:29: the annual cash saved
  • 04:32: which is simply going to be you know
  • 04:34: taking the salary
  • 04:36: and what percentage of that salary are
  • 04:38: we saving
  • 04:39: each year um and so
  • 04:43: you know you might uh people who are not
  • 04:46: experienced with excel might think to
  • 04:48: just you know type in
  • 04:50: uh 60 000 times you know 0.25 or
  • 04:54: something like that and that does get
  • 04:55: you to the right
  • 04:56: answer but the problem is if you change
  • 05:00: uh the salary here then that does not
  • 05:02: change the cash saved
  • 05:05: so what we want to do instead is we want
  • 05:08: to reference the cells
  • 05:10: that are used in the calculation never
  • 05:12: typing
  • 05:13: the actual values within the calculation
  • 05:16: part
  • 05:17: so we're going to reference the salary
  • 05:20: and we're going to take that salary and
  • 05:22: multiply it by
  • 05:23: this savings rate and then we get the
  • 05:26: same 15 000
  • 05:28: but if we change the salary then we see
  • 05:30: that the annual cash saved
  • 05:32: updates as well and then we're going to
  • 05:35: go ahead
  • 05:36: and do our actual main calculation next
  • 05:39: which is figuring out the
  • 05:41: years to retirement so for
  • 05:46: the years to retirement excel has you
  • 05:48: know all those
  • 05:49: uh functions corresponding to those
  • 05:52: typical five keys
  • 05:53: on the financial calculators uh so to
  • 05:56: figure out the number of
  • 05:58: periods for this standard uh problem
  • 06:01: there is an nper function number of
  • 06:05: periods
  • 06:06: um and so into that uh mper
  • 06:09: function you can see it pops up uh you
  • 06:12: know the things that we need to input
  • 06:13: so the first thing that we need to input
  • 06:15: is the rate uh so i'm going to reference
  • 06:18: the interest rate and then next
  • 06:21: it needs the payment so that would be
  • 06:24: the annual
  • 06:25: cash saved and then we need the
  • 06:31: present value and the present
  • 06:34: value is going to be zero we're not
  • 06:36: starting with any cash
  • 06:39: and then the future value uh is going to
  • 06:42: be
  • 06:43: our desired cash now
  • 06:46: this will give not an answer because you
  • 06:49: do need to be careful about the signs of
  • 06:51: things
  • 06:52: um that it should be a negative payment
  • 06:56: here
  • 06:57: because you're paying in to
  • 07:00: this investment and then you're gonna
  • 07:02: have a positive
  • 07:03: cash at the end as a result so once we
  • 07:07: have that negative in there
  • 07:08: then we indeed get to an answer here of
  • 07:11: 36.7
  • 07:12: years to retirement and because
  • 07:15: we linked everything together uh we have
  • 07:18: an actual model
  • 07:19: and not just a calculation and so then
  • 07:22: we go
  • 07:23: and we update the salary um that's a
  • 07:25: really low salary
  • 07:27: uh update the salary we can see if we
  • 07:29: earn ten thousand dollars less
  • 07:31: it takes us you know three years longer
  • 07:34: to retire
  • 07:36: um and we can play around with the
  • 07:38: savings rate as well
  • 07:40: um let's say we could save ten percent
  • 07:42: more that actually uh
  • 07:44: is able to bring up or bring down the
  • 07:46: years to retirement by about five years
  • 07:48: um so already we're getting a lot more
  • 07:51: insight
  • 07:52: than you know just doing a single
  • 07:54: calculation
  • 07:55: and it's very easy to change around the
  • 07:57: inputs and see the result
  • 08:00: so that's the implementation of the
  • 08:02: model the other thing
  • 08:03: you would want to generally do is add
  • 08:06: some formatting
  • 08:07: to the model and
  • 08:10: you know everything that i'm posting um
  • 08:13: as the examples
  • 08:14: on the site is going to have the full
  • 08:16: formatting
  • 08:17: i'll just quickly show you know some
  • 08:19: formatting for
  • 08:20: this top table but you can look
  • 08:23: take a look at the examples for
  • 08:26: how to do some of the formatting
  • 08:31: so here you know this inputs is
  • 08:34: you know really a header for both of
  • 08:37: these columns
  • 08:38: so i'm going to highlight both and merge
  • 08:41: and center
  • 08:41: now that inputs is over the entire thing
  • 08:44: there
  • 08:47: you might want to you know put some kind
  • 08:49: of color
  • 08:52: on that and might want to go
  • 08:56: and say you know put outside borders on
  • 08:59: all of it so it's really clear
  • 09:02: uh and then all borders on this and now
  • 09:05: you know we have a nice box uh
  • 09:07: containing all of the inputs it's very
  • 09:09: clear
  • 09:10: what's an input and what is not and you
  • 09:12: know you would want to do something
  • 09:13: similar
  • 09:14: for the outputs as well um
  • 09:18: and the other thing you want to pay
  • 09:19: attention to excel is the number
  • 09:20: formatting
  • 09:21: as well so for the number
  • 09:24: formatting um all that is
  • 09:27: up here and so for this we can use
  • 09:31: currency
  • 09:31: formatting for these and we can take it
  • 09:34: down to zero
  • 09:36: uh decimal places so
  • 09:39: you know this is kind of a level of
  • 09:41: formatting that you would probably want
  • 09:43: uh at a minimum you know you can always
  • 09:46: do more with the formatting but you want
  • 09:48: to have
  • 09:48: enough that is very clear uh you know
  • 09:52: what each of these values really mean is
  • 09:54: it a dollar amount is a percentage
  • 09:56: etc and be able to clearly separate the
  • 09:59: different
  • 10:00: sections of your model
  • 10:03: so we'll come back next time to then
  • 10:06: build
  • 10:06: out the basic python model thanks for
  • 10:12: listening

Building a Simple Python Model


Notes

  • In Python, we keep things linked together by using variables. If you hard-code values in your calculations, you are just using Python as a calculator

  • Basic math in Python is mostly what you might expect, it is the same as Excel only exponents are specified by ** and not ^

  • Jupyter allows us to create an interactive model complete with nicely formatted text, equations, tables, graphs, etc. with relative ease

  • Inputs should be kept at the top in a separate section, the main outputs should be kept at the bottom in a separate section.

  • More complex models should be broken into sections and subsections with sections dedicated to a concept or calculation

Transcript

  • 00:02: hey everyone
  • 00:03: nick dear bird is here teaching you
  • 00:05: financial modeling and today
  • 00:07: we're going to talk about implementing a
  • 00:09: basic model in
  • 00:10: python so from previous videos we've
  • 00:13: already been talking about this
  • 00:16: very basic retirement model we already
  • 00:18: implemented it
  • 00:19: in excel and now we're going to look at
  • 00:21: the analogous implementation
  • 00:23: in python so
  • 00:26: [Music]
  • 00:29: we've gotta um do a little bit of
  • 00:30: background on python before we can just
  • 00:33: jump right into actually building out
  • 00:36: the model
  • 00:37: um so you know from the introduction we
  • 00:40: talked about how
  • 00:41: python and other programming languages
  • 00:43: they basically live
  • 00:45: in the terminal they're text-based uh
  • 00:48: you input text
  • 00:49: you get text as the output um but of
  • 00:52: course you know we would like to have a
  • 00:54: little bit more than that
  • 00:56: and so there's been a whole ecosystem uh
  • 00:58: built around
  • 00:59: nicer ways to use python and other
  • 01:02: programming languages
  • 01:03: um and so we've got this very nice tool
  • 01:07: called jupiter that we can use and will
  • 01:10: use for the entire class
  • 01:13: and jupiter is a project that
  • 01:16: brings in all sorts of things
  • 01:19: along with the code so you can have
  • 01:22: nicely formatted text
  • 01:24: you can have equations you can have
  • 01:27: graphics
  • 01:28: you can have uh you know
  • 01:31: basically anything that you could have
  • 01:34: on a web page
  • 01:35: you can get into a jupiter notebook and
  • 01:38: control
  • 01:39: through your code even like interactive
  • 01:42: stuff like
  • 01:42: sliders and things that change how your
  • 01:45: model works
  • 01:46: um so tons of stuff you can do there
  • 01:49: and it's generally just a lot nicer to
  • 01:51: work with than just working in a
  • 01:53: terminal
  • 01:54: so we're just going to focus 100 percent
  • 01:56: on using jupiter
  • 01:58: to work with python in this class
  • 02:01: and jupiter was actually born out of
  • 02:04: python
  • 02:05: it was a python project originally it
  • 02:08: was actually called
  • 02:09: ipython notebook before it was called
  • 02:12: jupiter
  • 02:14: but the reason they kind of rebranded is
  • 02:16: they have expanded out into
  • 02:18: now more than 40 programming languages
  • 02:21: this has just become
  • 02:22: such a popular way to
  • 02:25: build things that so many people have
  • 02:27: jumped on this
  • 02:28: from so many different programming
  • 02:30: languages
  • 02:32: so we're going to keep our focus here
  • 02:36: now when you're using jupiter there's
  • 02:38: two main versions
  • 02:39: of jupiter that you can use jupiter
  • 02:41: notebook
  • 02:42: and jupiter lab so jupiter notebook is
  • 02:45: kind of the most basic
  • 02:47: interface uh and jupiter lab is
  • 02:51: taking the jupiter notebook and kind of
  • 02:53: expanding on it so
  • 02:54: um you can have multiple different
  • 02:57: uh notebooks open at once in lab as
  • 03:01: as different tabs uh you can view other
  • 03:04: kinds of files other than just
  • 03:05: jupyter notebooks so it has a lot of
  • 03:09: features
  • 03:10: and and jupiter lab is where
  • 03:13: the future of jupiter is all the new
  • 03:16: development
  • 03:17: and jupiter is going towards lab and not
  • 03:19: notebook
  • 03:21: and so we're going to focus on lab and
  • 03:24: the class
  • 03:25: so i would recommend you use lab but
  • 03:28: if you really don't like lab you really
  • 03:30: want something just a little bit simpler
  • 03:32: feel free to use jupiter notebook it's
  • 03:35: going to be
  • 03:36: you know essentially the same experience
  • 03:38: as far as
  • 03:39: just working within it it's really not
  • 03:42: going to be
  • 03:42: substantially different between jupiter
  • 03:44: notebook and jupiter lab
  • 03:49: so you should you know at this point
  • 03:53: pause the the video and try to get your
  • 03:56: jupiter
  • 03:57: environment set up so you can kind of
  • 03:58: follow along
  • 04:00: as i go and implement this model so
  • 04:03: we've got some instructions here
  • 04:05: on how to get uh
  • 04:08: jupiter lab started
  • 04:11: so we can look at that quickly how we
  • 04:15: would do that
  • 04:18: so the easiest way to do this
  • 04:21: is to search for anaconda navigator
  • 04:25: and you see this thing come up here as i
  • 04:28: search that
  • 04:30: you'll see a bit of a delay before the
  • 04:32: thing
  • 04:33: actually comes up
  • 04:36: and then once it comes up you can launch
  • 04:39: jupiter lab
  • 04:40: from that now if you don't have
  • 04:43: navigator
  • 04:44: or you don't want to use that you can
  • 04:46: just open a terminal and type
  • 04:48: jupiter lab that's also going to
  • 04:52: launch it for you but this is what
  • 04:56: um anaconda navigator looks like
  • 04:59: um and so from here you just click
  • 05:02: launch jupiter lab um and it's going to
  • 05:06: go ahead
  • 05:07: and launch that for you
  • 05:10: so then that will you know
  • 05:13: launch jupiter like
  • 05:16: this
  • 05:18: [Music]
  • 05:20: so let's go back and look at a couple
  • 05:23: more python
  • 05:24: basics before we actually start using
  • 05:27: this
  • 05:27: but that's basically how you would get
  • 05:30: jupiter
  • 05:31: launched on your system
  • 05:35: so you know most people are going to be
  • 05:38: you know fairly familiar with excel at
  • 05:40: this point so i think it's helpful to
  • 05:42: kind of compare and contrast to excel
  • 05:44: to understand how we can use python to
  • 05:48: do similar things
  • 05:49: so in excel everything is about the
  • 05:52: cells right you have these different
  • 05:54: cells
  • 05:55: you put the values in the cells you can
  • 05:57: make references
  • 05:58: to the cells so the basic unit is
  • 06:01: a cell or python the basic unit
  • 06:05: is an object and that's kind of an
  • 06:08: abstract thing that probably isn't going
  • 06:10: to have a lot of meaning for you yet
  • 06:13: um but it's just basically the way
  • 06:16: of thinking about things in python
  • 06:19: everything
  • 06:20: is an object um and we'll see
  • 06:23: more what that means as the course goes
  • 06:25: on
  • 06:27: so for excel you know you can have
  • 06:30: numbers
  • 06:31: in your cells or you can have you know
  • 06:34: characters letters that would be called
  • 06:36: a string
  • 06:37: so you can have numbers or strings as
  • 06:40: your data types
  • 06:41: for your excel cells
  • 06:45: and python we also have
  • 06:48: numbers we also have strings we also
  • 06:52: have other types
  • 06:54: and each object has a type
  • 06:58: so it might be an object which has a
  • 07:01: string
  • 07:02: type or it might be something else
  • 07:07: so each everything is an object and
  • 07:09: every object has a type
  • 07:11: and that tells you you know what kind of
  • 07:13: data is actually being represented
  • 07:16: within that object
  • 07:20: and then you know thinking about
  • 07:22: referencing
  • 07:23: uh our values so in excel we did
  • 07:26: cell references right you put the values
  • 07:28: and then you do equals you click on the
  • 07:30: cell
  • 07:31: equals a2 or whatever and that will
  • 07:34: reference
  • 07:34: the value contained within that cell so
  • 07:38: you know you have definitely a similar
  • 07:40: concept in python
  • 07:42: but instead of using cells we give a
  • 07:45: name
  • 07:46: to an object so you can uh whatever
  • 07:48: object you can give it a name
  • 07:50: and then you whenever you use that name
  • 07:52: that's going to reference back to that
  • 07:55: object um so
  • 07:58: you know here is the analogous um
  • 08:01: way of representing these things in
  • 08:03: python um
  • 08:05: so in excel you know you would type six
  • 08:07: in a cell and you would type abc another
  • 08:09: cell and then you would
  • 08:10: reference back to whatever those cell
  • 08:12: references are
  • 08:13: to be able to get that value to flow
  • 08:17: through
  • 08:18: whereas in python we just give a name
  • 08:22: and then equals and then whatever our
  • 08:25: object is
  • 08:26: so my number here the name is my
  • 08:30: underscore
  • 08:30: number and the value the object the
  • 08:34: object which has the type of a number
  • 08:36: is six here and then we have my string
  • 08:40: another name um equals
  • 08:43: here abc is string the the object with
  • 08:47: type
  • 08:48: string is this abc on the right hand
  • 08:51: side
  • 08:52: and then going forward after we've
  • 08:54: defined these we can then
  • 08:56: uh say my number or my string and be
  • 08:58: able to get back to six
  • 09:00: or abc so that's how everything can flow
  • 09:03: through
  • 09:06: and then thinking about uh how we do
  • 09:08: math
  • 09:09: and python um so the basic
  • 09:13: operations are going to be
  • 09:14: straightforward um
  • 09:17: you know two plus five equals seven you
  • 09:19: can literally just type two plus five
  • 09:21: and it will give you seven
  • 09:22: right six minus two it's going to give
  • 09:24: you four so all these
  • 09:26: uh kind of math basic math operations
  • 09:29: that you would expect
  • 09:30: uh just just work like you would think
  • 09:33: um and then beyond that
  • 09:36: um you know i mentioned a little bit in
  • 09:39: the introduction
  • 09:40: about how uh python is a very flexible
  • 09:44: language with a lot of
  • 09:46: potential add-on features right in the
  • 09:49: form of these open source
  • 09:51: packages so there are all these
  • 09:52: different uh you know more than 250 000
  • 09:55: different packages out there which add
  • 09:58: little bits of functionality
  • 09:59: to python and so numpy
  • 10:03: is one of those packages
  • 10:06: which add functionality to python
  • 10:09: and with numpy we can get all those
  • 10:12: kind of financial functions that we have
  • 10:15: out of the box in excel
  • 10:16: so you just bring numpy
  • 10:19: into your python session and then you
  • 10:22: can use
  • 10:22: all these functions and
  • 10:26: you you know i told you to download
  • 10:29: anaconda
  • 10:30: in order to get python and packaged
  • 10:33: along with
  • 10:33: anaconda you already have numpy numpy
  • 10:37: is one of the most popular python
  • 10:39: packages
  • 10:40: in the world um and so it comes out of
  • 10:43: the box with anaconda
  • 10:45: you just have to bring it into your
  • 10:47: session that's that'll be
  • 10:48: via an import we'll look at what that
  • 10:50: looks like in a moment here
  • 10:53: but you just you know one line of code
  • 10:55: to add it into your session and then
  • 10:56: you'll be able to use
  • 10:58: all these functions if it was some
  • 11:00: package
  • 11:01: where it wasn't already included in
  • 11:03: anaconda
  • 11:04: then you would have to install it before
  • 11:06: you could use it
  • 11:08: but we'll deal with that a little bit
  • 11:09: later in the course once we need to go
  • 11:11: to some things which are outside of
  • 11:13: anaconda
  • 11:15: and then i just have a note on here
  • 11:17: about a deprecation
  • 11:18: warning so this isn't really anything to
  • 11:22: worry about
  • 11:24: these financial functions in numpy are
  • 11:26: actually getting moved
  • 11:28: to a separate package in the future
  • 11:30: numpy financial
  • 11:32: um and so what happens right now if you
  • 11:34: use these functions
  • 11:35: it will show a warning which just says
  • 11:38: hey we're going to move these functions
  • 11:40: in the future it doesn't affect anything
  • 11:42: for right now
  • 11:43: it's just that you're going to see a
  • 11:44: warning when you use the functions so
  • 11:46: just don't worry
  • 11:48: about that warning
  • 11:51: so let's go ahead and look at what this
  • 11:54: implementation
  • 11:55: actually looks like
  • 12:01: so we're still talking about this simple
  • 12:04: retirement model
  • 12:05: where uh you know we had a few different
  • 12:10: inputs we have
  • 12:13: uh the salary savings rate investment
  • 12:16: rate desired cash
  • 12:18: so we would want to first
  • 12:22: you know kind of just like we did in
  • 12:24: excel right we made an input section and
  • 12:26: then we defined all the inputs
  • 12:28: we want to do a similar thing here in
  • 12:30: our jupyter model we want to maintain
  • 12:31: that same separation of inputs and
  • 12:33: outputs
  • 12:34: that we're talking about doing in excel
  • 12:36: so um in jupyter you can have
  • 12:39: uh you know a section at the top which
  • 12:41: has all your inputs
  • 12:43: and then at the bottom you should have
  • 12:45: another section which has your main
  • 12:47: outputs
  • 12:48: and then in between you can have other
  • 12:50: sections for uh you know any kind of
  • 12:52: intermediate calculations
  • 12:54: but here you know it's a very direct
  • 12:57: model
  • 12:59: so
  • 13:04: two so you see these uh cells here
  • 13:07: in jupiter and you can type code in any
  • 13:11: one of the cells
  • 13:12: and you can run cells individually
  • 13:15: um and there are also you know two main
  • 13:18: types of cells
  • 13:19: that we'll think about using in this
  • 13:21: class um
  • 13:23: so um
  • 13:26: we have the um
  • 13:30: the code cell and the markdown cell are
  • 13:33: the two
  • 13:34: main ways that we'll use it in the class
  • 13:37: um so the code cell you're you're typing
  • 13:40: code
  • 13:40: and then the markdown cell you're typing
  • 13:42: these this nicely formatted text
  • 13:46: so we'll get definitely more into what
  • 13:49: you can do with this text formatting
  • 13:51: uh as we dig more into this stuff
  • 13:54: but here you know just know if you put
  • 13:56: this uh
  • 13:57: hash then that can give you a header um
  • 14:00: so
  • 14:00: i'm going to say you know inputs here
  • 14:03: and then when i run that you can see it
  • 14:05: comes as this nice header
  • 14:07: and you know i can put some regular text
  • 14:11: uh here and you can see that comes in a
  • 14:15: regular size there
  • 14:17: and to run this i'm holding shift and
  • 14:20: pressing enter
  • 14:21: uh you can also uh do this play button
  • 14:25: that does the same thing and it's the
  • 14:28: same thing for
  • 14:29: these markdown cells as well as the code
  • 14:32: cells
  • 14:33: you run them the same way so
  • 14:36: now we have you know a nice header for
  • 14:38: our input
  • 14:39: section um now let's go ahead and type
  • 14:42: out our various
  • 14:44: inputs so first let's put the salary
  • 14:47: salary equals 60 000.
  • 14:51: then we have the savings rate um
  • 14:54: and you'll notice i didn't do saving
  • 14:57: space rate
  • 14:58: because variable names cannot have
  • 15:01: spaces
  • 15:02: in python so the convention is you know
  • 15:05: make them all lowercase and instead of
  • 15:07: spaces you use underscores
  • 15:09: and that's what you'll find in pretty
  • 15:11: much any python code
  • 15:14: and then we have also the investment
  • 15:16: rate
  • 15:17: equals 0.05 and the desired
  • 15:21: cash is going to be 1.5 million
  • 15:26: um and then you see i hit shift enter
  • 15:28: and now that it's a code cell
  • 15:30: you can see actually this execution
  • 15:32: count uh go up
  • 15:33: each time that i run it um
  • 15:37: and another thing you'll note is that
  • 15:40: unlike in excel
  • 15:42: i did not type a percentage sign in here
  • 15:44: i typed it in decibel format
  • 15:47: you cannot just put
  • 15:51: you know a percent like you can in excel
  • 15:54: you can see it actually gives a syntax
  • 15:56: error
  • 15:57: if we do that because that basically
  • 15:59: means syntax error means
  • 16:02: python doesn't understand what you're
  • 16:03: trying to do
  • 16:05: so percent has another special meaning
  • 16:07: in python we're we're not going to cover
  • 16:09: that
  • 16:10: um it's not important for what we're
  • 16:12: doing
  • 16:14: but just know that you can't just you
  • 16:16: know put a percent
  • 16:17: sign and expect it to know that you're
  • 16:19: talking about a percentage
  • 16:21: you have to just put it in decimal is
  • 16:23: the way that it's going to know
  • 16:26: so we have our inputs defined now
  • 16:30: and so then we can make the next section
  • 16:34: determining cash saved
  • 16:39: um and you'll notice you know whenever
  • 16:41: i'm in the last cell and i run it
  • 16:43: it does create another cell um also you
  • 16:47: can
  • 16:48: um you know insert cells above and below
  • 16:52: um
  • 16:57: the the here you know it's a
  • 17:01: a and b are able to insert cells above
  • 17:03: and below
  • 17:04: and d twice is able to
  • 17:07: delete cells and all of these things
  • 17:11: are in the menus as well
  • 17:16: so you can you know if you prefer to
  • 17:18: just
  • 17:19: use the menus you can find all the
  • 17:21: things in there
  • 17:22: uh but i always just use the hotkeys um
  • 17:26: so b for below a for above
  • 17:30: dd for delete um
  • 17:33: and you'll notice also one more thing is
  • 17:36: that
  • 17:36: uh we basically have two different
  • 17:40: modes here you can see that switching
  • 17:41: here command mode
  • 17:43: or edit mode and what i'm doing here is
  • 17:46: i'm hitting
  • 17:46: enter to go into edit mode and i'm
  • 17:48: hitting escape to go back out
  • 17:50: into command mode and when you're in
  • 17:52: command mode you can do these a
  • 17:54: b d d uh et cetera
  • 17:58: where as when you're in edit mode then
  • 18:00: those would be you know just typing
  • 18:02: characters into the cell
  • 18:05: so uh we have our next section
  • 18:09: determining cache saved
  • 18:10: and now we're going to do our actual
  • 18:13: calculation
  • 18:14: of what is the cash saved
  • 18:18: so let's call this variable annual cash
  • 18:23: and it's going to be salary times the
  • 18:26: savings rate
  • 18:28: and you'll see you know one nice feature
  • 18:30: of jupiter
  • 18:31: is we can get auto completion for our
  • 18:34: variables if you can't remember what it
  • 18:36: was called or you just don't want to go
  • 18:38: all the way through with typing it
  • 18:40: if you're in the middle of typing
  • 18:41: something you can hit tab
  • 18:43: and that's going to bring up the
  • 18:45: possibilities
  • 18:46: and then as you type it's going to
  • 18:48: narrow down the possibilities
  • 18:50: and you hit enter to pick the option or
  • 18:53: you can up and down to
  • 18:56: pick whichever option so here we want
  • 19:00: the
  • 19:00: savings rate um and so now we have our
  • 19:04: calculation
  • 19:05: the annual cash is the salary times the
  • 19:07: savings rate
  • 19:08: okay let's run it and now you might say
  • 19:11: where
  • 19:11: is the annual cache i just calculated it
  • 19:14: where is it
  • 19:15: right and that's uh you know one thing
  • 19:17: which is definitely difficult for people
  • 19:19: who are used to working in excel
  • 19:21: in excel you know you do your
  • 19:22: calculation and it shows you the result
  • 19:24: right away right
  • 19:25: with python and this is generally the
  • 19:28: case with any programming language
  • 19:30: it's not going to show you anything
  • 19:32: unless you tell it to show you
  • 19:34: something so the general way to
  • 19:37: show something in python is with the
  • 19:39: print command
  • 19:41: so if we print the annual cache then we
  • 19:44: can see it is indeed
  • 19:45: uh 15 000.
  • 19:49: but there is a nice shortcut in jupiter
  • 19:52: so
  • 19:52: in jupiter uh you can
  • 19:55: uh just put uh
  • 19:59: whatever you want to see as the last
  • 20:01: thing in the cell
  • 20:02: and then it's going to basically print
  • 20:04: it for you
  • 20:05: so it's just you know lets you save a
  • 20:07: little bit of typing whatever
  • 20:09: is on the last line of the cell it's
  • 20:11: going to print
  • 20:12: so if we just wanted to do our
  • 20:14: calculation and then see it right away
  • 20:16: in the same cell
  • 20:17: then you can do it like that just put
  • 20:19: whatever variable
  • 20:20: on the last line and then you're going
  • 20:22: to see it right away
  • 20:24: and you don't have to do all of that
  • 20:26: stuff
  • 20:30: so we have now the annual cash and so
  • 20:33: the last
  • 20:34: would then be calculating the
  • 20:37: years to retirement um
  • 20:41: and you know definitely take a look at
  • 20:42: the completed
  • 20:44: model for this because it you know shows
  • 20:47: you know how you can be you know putting
  • 20:49: more text and a little more formatting
  • 20:51: in this to really
  • 20:52: uh you know make it a more polished
  • 20:54: model
  • 20:55: but here you know we're just going kind
  • 20:57: of quickly
  • 20:59: uh it also explains a little bit more
  • 21:02: all the various steps
  • 21:03: that are going on um
  • 21:07: so we want to calculate the years to
  • 21:09: retirement and we talked about how the
  • 21:11: numpy
  • 21:12: library has the nper number of periods
  • 21:15: function
  • 21:16: which is going to allow us to do this
  • 21:20: but how do we use that so you don't have
  • 21:23: access to it immediately in your session
  • 21:25: you do have to actually import the
  • 21:28: package
  • 21:28: to get access to it um
  • 21:32: so if we import numpy
  • 21:36: uh then run that then all of a sudden
  • 21:40: we get access to everything which is in
  • 21:44: numpy so then we can do
  • 21:48: uh you know numpy dot mper
  • 21:53: and you might say well how do i actually
  • 21:56: use this thing
  • 21:59: so a nice another feature in jupiter
  • 22:03: is you can put a question mark after
  • 22:05: something and it will tell you about it
  • 22:08: so here we can get all the information
  • 22:10: about this
  • 22:11: function we can see that it takes the
  • 22:13: rate first then the payment then the
  • 22:14: present value
  • 22:16: then the future value which defaults to
  • 22:18: zero and then
  • 22:19: uh you know the the annuity part annuity
  • 22:22: due or not annuity due
  • 22:25: um another way you can go about this
  • 22:28: is you know uh after you type the
  • 22:31: parentheses here to call this function
  • 22:34: uh if you hold shift and press tab then
  • 22:36: you're gonna see
  • 22:37: the same thing just come up as a little
  • 22:39: pop-up here
  • 22:40: where you can take a look at that so i
  • 22:43: use this all the time shift tab
  • 22:46: to quickly look at how to use a function
  • 22:51: so we're going to then pass in
  • 22:54: our uh arguments uh for
  • 22:57: this um so
  • 23:01: our arguments are going to be um
  • 23:04: you know first we got to put the rate so
  • 23:06: that was the
  • 23:09: investment rate and the next
  • 23:13: we got to put the payment
  • 23:16: so the payment is
  • 23:20: the minus annual cash and then we've got
  • 23:24: to put
  • 23:25: the present value so the present value
  • 23:28: is zero we're not starting with any cash
  • 23:31: and then we've got to put the um
  • 23:34: desired cache
  • 23:39: and so we do that and we can see that we
  • 23:42: get the same result
  • 23:44: that we did in excel
  • 23:47: um now um
  • 23:50: this works just fine but there's a
  • 23:52: couple things that we want to do to
  • 23:54: clean this up a little bit um and you
  • 23:56: can see this
  • 23:57: this morning that i mentioned came up
  • 23:59: that's nothing to worry about just
  • 24:01: ignore this warning that comes up
  • 24:02: deprecation warning you can just ignore
  • 24:04: that
  • 24:06: um so there's a couple things we want to
  • 24:08: do to make this a little bit cleaner
  • 24:10: one is there is actually a convention
  • 24:14: that everyone uses for
  • 24:15: importing numpy if you google anything
  • 24:18: about
  • 24:19: numpy you'll see everyone using this
  • 24:22: same convention
  • 24:24: and that's to actually import numpy as
  • 24:27: np and that basically just renames numpy
  • 24:31: to np so that then we can do np
  • 24:34: number of periods and it does the same
  • 24:36: thing so functionally
  • 24:38: no difference but this is just the
  • 24:40: convention that everybody uses
  • 24:42: um then the other thing is
  • 24:46: that um you know the formatting of this
  • 24:49: is not very good we would like to get
  • 24:52: a better formatting of this result
  • 24:55: so we can go ahead and save that result
  • 24:57: to a variable
  • 24:59: so we can say years to retirement
  • 25:02: equals that right
  • 25:06: and so we look at years to retirement it
  • 25:08: is that
  • 25:09: um but now we want to add some
  • 25:12: formatting to it
  • 25:15: so the way that we can do easy
  • 25:17: formatting and also you know include it
  • 25:19: in a sentence or anything like that
  • 25:22: is with f strings and we'll dig more
  • 25:25: into f strings when we go
  • 25:26: into the python basics lecture
  • 25:29: but basically we can say you know martha
  • 25:32: has
  • 25:33: and then we can drop in our variable
  • 25:36: years to retirement and then we can
  • 25:39: specify
  • 25:40: uh the format of that um
  • 25:44: and then we finish the string and then
  • 25:47: we say uh you know that she has 3.67
  • 25:52: 36.7 years to retirement so this is a
  • 25:55: lot nicer way to see the result
  • 25:57: you know if someone just sees this at
  • 26:00: the end they don't necessarily know what
  • 26:02: you're talking about
  • 26:03: but putting it into a sentence here
  • 26:07: with you know nice number formatting it
  • 26:09: becomes very clear
  • 26:11: what you're talking about
  • 26:15: so we'll dig into a lot more of these
  • 26:18: python concepts as we go into the basics
  • 26:21: this was just a very quick run through
  • 26:22: on how to build a basic model
  • 26:26: and then you know there's a useful
  • 26:29: shortcut up here
  • 26:31: kernel restart kernel and run all cells
  • 26:35: so if we say change this to 40 000
  • 26:39: and then we restart kernel and run all
  • 26:41: cells
  • 26:42: then we'll see that it updates the
  • 26:45: year's retirement down here so that's
  • 26:47: the easy way that you can just rerun
  • 26:49: everything in the model
  • 26:50: in order to be able to
  • 26:53: get the new result for whatever change
  • 26:55: in the inputs
  • 26:58: so next time we'll come back and we'll
  • 27:00: look at
  • 27:01: how we can extend these basic excel and
  • 27:04: python models
  • 27:06: so thanks for listening and i'll see you
  • 27:08: next time

Basic Iteration


Notes

  • Iteration is a key concept in financial modeling (as well as programming)

  • Using iteration, we can complete the same process for multiple inputs to yield multiple outputs

  • As the same process is applied to each input, the process only needs to be created once and any updates to the process can flow through all the inputsIteration can be internal or external to the main model. You can use iteration within your model, or you can iterate the model itself

  • To iterate in Excel, drag formulas. To iterate in Python and other programming languages, use loops.

Transcript

  • 00:03: hey nick dear bird is here teaching you
  • 00:05: financial modeling
  • 00:06: today we're talking about basic
  • 00:08: iteration and how it applies to
  • 00:10: financial models
  • 00:11: this is part of the segment getting
  • 00:13: started with python and excel
  • 00:15: where we're exploring building a basic
  • 00:17: retirement model in both excel and
  • 00:19: python
  • 00:20: we've already built out the most basic
  • 00:22: excel and python models
  • 00:23: and now we're looking at how we can
  • 00:25: extend those models
  • 00:28: so we uh you know have the basic result
  • 00:32: how long is it going to take for martha
  • 00:35: to retire which was this you know 36.7
  • 00:38: years
  • 00:39: with our basic inputs that we decided on
  • 00:42: but there's a number of assumptions that
  • 00:44: went into that
  • 00:45: uh you know both in terms of the inputs
  • 00:48: values as well as the structure of the
  • 00:50: model
  • 00:51: um but one important key assumption here
  • 00:54: is that we assumed that martha's going
  • 00:56: gonna earn five percent
  • 00:58: on her investments uh but in reality we
  • 01:01: know
  • 01:02: that you know an investment rate is you
  • 01:04: know
  • 01:05: very rarely guaranteed uh most likely
  • 01:08: she's going to end up earning a
  • 01:10: different rate of return on her
  • 01:11: investment
  • 01:12: and so we really need to evaluate how
  • 01:15: long it's going to take to retire
  • 01:17: under a bunch of different scenarios for
  • 01:20: the investment rate now
  • 01:24: we want to do that but you know say we
  • 01:26: want to look at
  • 01:27: you know 10 different investment rates
  • 01:29: we don't want to go and
  • 01:30: implement everything that we just did 10
  • 01:32: separate times right that would be a lot
  • 01:34: of work
  • 01:36: even for you know such a basic model as
  • 01:39: we have built
  • 01:41: so we need to actually bring this
  • 01:44: concept of iteration
  • 01:46: into our models to be able to answer
  • 01:49: these kinds of questions without having
  • 01:51: to repeat
  • 01:53: what you've done so you know in both
  • 01:57: financial modeling as well as just in
  • 01:59: programming in general
  • 02:01: it's often the case that you have some
  • 02:03: process
  • 02:04: and you want to repeat that process on a
  • 02:07: bunch of different inputs
  • 02:09: to get a bunch of different outputs
  • 02:12: so that is what we refer to
  • 02:15: as iteration is just doing the same
  • 02:18: process
  • 02:19: on a bunch of different inputs
  • 02:23: so the way that you accomplish this in
  • 02:25: excel
  • 02:26: is once you've got your formula in the
  • 02:28: cell
  • 02:30: which you know has cell references
  • 02:33: then you click on the corner of the cell
  • 02:36: and you drag that uh in whichever
  • 02:39: direction
  • 02:40: and that's going to then uh
  • 02:43: repeat that formula over and over and
  • 02:46: it's going to take the cell references
  • 02:48: and if they're relative references it's
  • 02:50: going to move them
  • 02:51: by the same amount that you're moving
  • 02:54: the
  • 02:55: formula dragging the formula um whereas
  • 02:58: if it's a fixed reference then it's
  • 02:59: going to stay
  • 03:00: where it is and so that allows you to
  • 03:03: have you know say you have a column of a
  • 03:04: bunch of different inputs
  • 03:06: and you have a calculation over here you
  • 03:08: reference
  • 03:09: uh your number and the input over here
  • 03:11: well then you can drag it down and have
  • 03:13: it apply to all those different
  • 03:15: inputs and we'll look at a concrete
  • 03:18: example of that
  • 03:19: in the next video but that's the basic
  • 03:22: idea
  • 03:23: dragging formulas is your main way of
  • 03:26: doing iteration
  • 03:26: in excel without having to go to vba
  • 03:30: so then in python uh as well
  • 03:34: as you know other programming languages
  • 03:36: as well
  • 03:37: iteration is all about loops uh this
  • 03:40: this this construct that we call a loop
  • 03:43: um
  • 03:44: and we're going to explore you know one
  • 03:46: main kind of loop
  • 03:48: um in this class uh and that's a
  • 03:51: for loop there are other kinds of loops
  • 03:54: but uh you know that's going to be the
  • 03:56: primary one we're going to focus on
  • 03:58: and that just says you know for for each
  • 04:02: different input
  • 04:03: i want to do something um that's all
  • 04:06: that a for loop means is you know
  • 04:08: whatever code goes in the for loop
  • 04:10: i'm going to run that for each one of my
  • 04:12: different inputs
  • 04:14: so that's the basic concept
  • 04:18: so just doing doing whatever operation
  • 04:20: whatever code you have
  • 04:21: within that loop whatever process you're
  • 04:24: just going to repeat that
  • 04:26: for each one of your inputs
  • 04:30: so you know just uh you know bird's eye
  • 04:32: kind of view
  • 04:33: here's python iteration versus excel
  • 04:36: iteration doing the exact same
  • 04:40: calculation
  • 04:42: so you know made this a very simple
  • 04:44: calculation so that we can just try to
  • 04:46: understand
  • 04:47: the structure of the of the iteration
  • 04:51: that makes it apply to multiple inputs
  • 04:54: so this calculation here is just adding
  • 04:56: two to whatever the input is so if we
  • 04:59: put in five we should get seven
  • 05:00: if we put in 15 we should get 17.
  • 05:03: um and so you know the idea here is that
  • 05:07: our main calculation we should only have
  • 05:09: to type it once right it's not typing
  • 05:12: five plus seven
  • 05:13: and then ten plus twelve or sorry five
  • 05:15: plus two and then ten plus two and then
  • 05:17: fifteen plus two
  • 05:18: we just wanna type you know our
  • 05:21: reference
  • 05:22: plus two and then do our iteration to
  • 05:25: get it to apply
  • 05:26: to each one of these now of course in
  • 05:27: this very simple example
  • 05:29: it's you know probably even a little bit
  • 05:31: more work to do it this way
  • 05:32: but as you go to more complicated things
  • 05:35: you know it could be that your entire
  • 05:37: model
  • 05:38: runs with it within this loop right and
  • 05:40: then you're looking at your entire model
  • 05:42: for a bunch of different inputs
  • 05:44: uh or all sorts of different cases uh
  • 05:46: and so there's you know far more complex
  • 05:48: things
  • 05:49: we can do with these loops so we're just
  • 05:51: learning the structure here
  • 05:54: um so our three different inputs into
  • 05:57: this
  • 05:57: add to calculation are 5 10 and 15
  • 06:00: and we're expecting to get 7 12 and 17
  • 06:04: as our outputs here um so
  • 06:07: you know in excel it would be you know
  • 06:10: so these would be the hard-coded numbers
  • 06:13: here
  • 06:13: and then these would be where the
  • 06:15: calculations are and here i'm just
  • 06:17: showing
  • 06:17: you know what would have been typed into
  • 06:19: this into this cell
  • 06:21: to be able to uh produce the output
  • 06:25: so you know you would start here and you
  • 06:28: would type equals
  • 06:29: and you would click this uh input cell
  • 06:32: that would get the b4 and
  • 06:34: you do plus two and then you know from
  • 06:36: there you drag it down
  • 06:38: and this b5 this b6 those are
  • 06:41: automatically happening
  • 06:42: those were not typed uh you type this
  • 06:45: once and then you're able to drag it
  • 06:46: down
  • 06:47: and it's able to repeat this calculation
  • 06:49: this adding two calculation
  • 06:51: for each one of the inputs
  • 06:54: so uh in python it looks a little bit
  • 06:57: different but conceptually
  • 06:59: we're doing the exact same thing so
  • 07:02: here we've got our inputs 5 10 and 15.
  • 07:05: we have these three numbers in a list
  • 07:08: we're going to talk more about that as
  • 07:11: we get into the python basics
  • 07:13: but a list is a type of object which
  • 07:16: holds
  • 07:17: other objects so here we have a list of
  • 07:20: numbers it's just a container basically
  • 07:22: to hold these three different numbers
  • 07:25: in one single variable um
  • 07:28: so we've got our 5 10 15 all in one
  • 07:31: variable here
  • 07:32: and then uh we do our actual
  • 07:36: for loop so with the for loop we have
  • 07:39: four item and inputs so that's saying
  • 07:42: you know each time that this
  • 07:44: loop runs it's going to run three times
  • 07:46: because we have three inputs
  • 07:47: each time it's going to pull one
  • 07:51: of these out of the loop so the first
  • 07:54: time that it runs
  • 07:55: we're going to get five coming out the
  • 07:57: second time that it runs we're going to
  • 07:59: get 10
  • 08:00: coming out and the third time we're
  • 08:01: going to get 15.
  • 08:04: so you do this 4 item in inputs gotta
  • 08:07: have a colon at the end
  • 08:08: gotta have this indentation for
  • 08:12: everything within the for loop those are
  • 08:13: both very important
  • 08:16: and then once you're in the for loop we
  • 08:19: can do
  • 08:19: our calculation so then we're taking our
  • 08:22: item
  • 08:22: which the item here is our loop variable
  • 08:26: uh so the loop variable is just you call
  • 08:29: this whatever you want
  • 08:30: um and it represents each item that
  • 08:33: you're getting
  • 08:33: as you go through so the first time you
  • 08:36: run
  • 08:37: or so as it runs it's gonna execute
  • 08:39: three times in here
  • 08:40: first time it's going to be five so it's
  • 08:42: going to add five to two
  • 08:43: you're printing that out so that's why
  • 08:45: we get seven and then
  • 08:47: it's going to then you know come back
  • 08:48: around because we have more inputs
  • 08:51: and the next time it's going to give us
  • 08:52: 10 as item
  • 08:54: it's going to do 10 plus 2 12 put that
  • 08:57: in a new value
  • 08:58: print that new value and so we get 12.
  • 09:01: and you know final time again it goes
  • 09:04: gets 15 this time for the item
  • 09:06: adds 15 to 2 gets our new value is 17
  • 09:10: and prints that new value
  • 09:13: so that's the basic idea of uh
  • 09:16: iteration and you know basically how you
  • 09:19: implement it
  • 09:20: in both python and excel um in the next
  • 09:23: a couple of videos we're going to
  • 09:25: actually implement that
  • 09:26: on our existing basic retirement models
  • 09:30: uh to see a little bit more in detail
  • 09:33: how these things
  • 09:34: work so thanks for listening and see you
  • 09:37: next time

Extending a Simple Excel Model


Notes

  • Essentially the model with iteration is the same, we just drag the formula to cover multiple inputs

  • It is crucial to set up fixed and relative cell references appropriately before you drag formulas

Transcript

  • 00:04: hey everyone
  • 00:04: nick dierbert is here teaching you
  • 00:06: financial modeling today we're talking
  • 00:08: about how to extend a simple excel model
  • 00:11: to add
  • 00:12: basic iteration this is part of our
  • 00:15: segment on getting started
  • 00:16: on python and excel where we're building
  • 00:18: out basic retirement model
  • 00:20: with both tools so
  • 00:24: uh looking at how we would add this
  • 00:27: iteration so here i'm going to start
  • 00:30: from what we had from the prior video
  • 00:32: where we built out this basic
  • 00:33: excel model to get the years to
  • 00:36: retirement
  • 00:37: uh based off of these inputs but i'm
  • 00:40: going to go ahead and just
  • 00:42: copy it to a new sheet um
  • 00:48: and then we can call this uh you know
  • 00:51: model with iteration
  • 00:56: so uh here let's look at say three
  • 01:00: different interest rates and what's the
  • 01:02: years to retirement
  • 01:03: for each one of those rates um
  • 01:06: and we want to be sure to be able to do
  • 01:08: this without
  • 01:10: having to retype any formulas or copy
  • 01:14: paste or
  • 01:15: anything like that we want to be able to
  • 01:17: take the same formula that we've written
  • 01:19: and just apply it
  • 01:20: to multiple different inputs and
  • 01:24: you know with such a simple calculation
  • 01:26: it doesn't make a big difference
  • 01:27: but once you're you know running an
  • 01:29: entire complicated model here
  • 01:31: uh you're definitely not going to want
  • 01:33: to copy your model multiple times that
  • 01:35: becomes a huge maintenance nightmare
  • 01:38: and so iteration is important
  • 01:42: so we want to look at a couple other
  • 01:45: interest rates
  • 01:45: so let's say you know we want to also
  • 01:48: look at six and seven
  • 01:50: percent um of course you know you would
  • 01:53: want to update the formatting so it can
  • 01:54: capture
  • 01:55: all of this um but i'm just going to
  • 01:59: leave that as an exercise for you on
  • 02:01: your own so we don't have to spend time
  • 02:03: with it here
  • 02:05: um now we want to take this years to
  • 02:08: retirement calculation
  • 02:10: and apply that to not only the five
  • 02:13: percent rate
  • 02:14: but also the six and seven percent rate
  • 02:18: um so the first thing you might think to
  • 02:20: do uh you know i've already
  • 02:22: mentioned how uh iteration in excel you
  • 02:25: drag
  • 02:25: the formula right and so you can see you
  • 02:28: know on this box you can see that this
  • 02:30: bottom right corner that box there has
  • 02:34: uh you know a larger corner and you can
  • 02:36: see the cursor changes
  • 02:38: uh to this other one when i go over that
  • 02:41: and that's signifying that you're able
  • 02:42: to
  • 02:43: drag it um so you just click that and
  • 02:45: hold and drag it
  • 02:46: and then you can go in you know whatever
  • 02:49: direction
  • 02:50: you want from there so
  • 02:53: you know your your thought here might be
  • 02:54: just okay let's just drag it over
  • 02:56: and uh then we'll get the calculation
  • 02:59: again
  • 03:00: for the other inputs and to some extent
  • 03:02: that's true
  • 03:04: but you'll see the issue here right we
  • 03:06: can see that
  • 03:07: the reference for the interest rate
  • 03:10: indeed moved over
  • 03:11: as we wanted it to but the uh reference
  • 03:14: for desired cash and annual cash save
  • 03:17: also moved over even though we only have
  • 03:19: a single desired cash
  • 03:21: and annual cash saved and so one way you
  • 03:25: might think
  • 03:26: to solve this is okay well i'll just
  • 03:30: you know repeat these numbers uh you
  • 03:32: know
  • 03:33: in each one and then it should work
  • 03:35: right and
  • 03:37: uh
  • 03:40: and it's close to working you know if
  • 03:42: this was a hard-coded number that would
  • 03:43: have worked but again this
  • 03:45: face the same problem right this was
  • 03:46: actually a calculation
  • 03:49: uh and so that also dragged over well
  • 03:51: let's just say you know we had
  • 03:53: 15 000 in here okay now it is working
  • 03:56: uh but what if you want to update the
  • 03:58: desired cache now
  • 04:00: it's you know 1.6 million oh wait that
  • 04:02: only updated the one calculation that
  • 04:04: didn't update the others
  • 04:06: uh and so there's definitely issues with
  • 04:08: this approach
  • 04:09: plus it just looks repetitive um
  • 04:12: so the solution to this is uh
  • 04:16: to use fixed references so
  • 04:19: by uh you know carefully picking which
  • 04:22: references
  • 04:23: should be fixed which should be relative
  • 04:25: and
  • 04:26: you know if you're uh depending on the
  • 04:28: situation you can
  • 04:30: fix just in one direction on the row or
  • 04:32: the column uh
  • 04:33: we'll get into that more as the course
  • 04:35: goes on
  • 04:36: but uh for now we can just think about
  • 04:38: fixed or relative
  • 04:40: so the fixed reference is not going to
  • 04:42: move as you drag
  • 04:44: the calculation while the relative
  • 04:45: reference will
  • 04:47: um and so you want to make all those
  • 04:51: changes to your formula before
  • 04:53: you go and drag it so if we click into
  • 04:57: the formula we again
  • 04:58: you know see those three references here
  • 05:00: highlighted in the same colors
  • 05:02: in the formula bar here
  • 05:07: and we want to then not fix the interest
  • 05:11: rate
  • 05:11: but we do want to fix the desired cash
  • 05:14: and the annual cash saved
  • 05:17: so we're going to leave the interest
  • 05:18: rate alone and we're going to come over
  • 05:21: here
  • 05:21: to the annual cash saved and the way
  • 05:24: that you can
  • 05:25: fix the inputs so on windows it's the f4
  • 05:30: key and you'll see when i press that i
  • 05:32: now have dollar signs
  • 05:34: in front of the b and in front of the
  • 05:37: eight that means it is a completely
  • 05:39: fixed reference
  • 05:40: then if i hit f4 again you'll see now
  • 05:42: the dollar sign is just in front of the
  • 05:44: eight
  • 05:45: that means that it's fixed on the on the
  • 05:47: row
  • 05:48: but not on the column that means it will
  • 05:50: move right and left but it will not
  • 05:52: move up and down and then hit it again
  • 05:56: now we have fixed on the column
  • 05:59: uh oops we have fixed on the column
  • 06:03: uh but not on the row so now
  • 06:06: it would move up and down but it would
  • 06:08: not move left
  • 06:09: or right and then you hit f4 again and
  • 06:12: you're back to just the regular relative
  • 06:15: reference and for mac users
  • 06:18: uh it's command t gets you the same
  • 06:20: thing as
  • 06:21: f4 on windows um
  • 06:25: and if you forget the key or you can't
  • 06:27: figure it out or it doesn't work on your
  • 06:29: system or something
  • 06:30: you can always just type the dollar
  • 06:32: signs it's not
  • 06:33: you know quite as convenient but it does
  • 06:36: work it'll do the exact same thing as
  • 06:39: the f4 command t
  • 06:41: keys um so then coming over
  • 06:44: to the uh desired cache we're gonna also
  • 06:47: fix that as well
  • 06:49: and for both we're just doing completely
  • 06:50: fixed uh references
  • 06:53: you know fix just on the column would
  • 06:54: have worked as well
  • 06:56: uh but here uh it doesn't matter which
  • 06:58: one we choose for this purpose
  • 07:01: so now uh interest rate relative
  • 07:05: desired cash and annual cash saved are
  • 07:07: fixed
  • 07:08: so i hit enter you can see the original
  • 07:10: number did not change
  • 07:11: but now we can drag this over and we can
  • 07:14: see we get the actual results
  • 07:16: and when we click into what happened we
  • 07:18: can see the interest rate
  • 07:19: indeed moved over while the desired cash
  • 07:22: and annual cash save
  • 07:23: stayed where they are because those are
  • 07:26: fixed
  • 07:27: references so you know with this kind of
  • 07:30: technique
  • 07:31: we can repeat the same calculation uh
  • 07:34: for a bunch of different inputs in excel
  • 07:36: uh to be able to uh look at a bunch of
  • 07:39: different outcomes
  • 07:40: from our model and then next time we're
  • 07:43: going to come back
  • 07:44: to do the same thing with our python
  • 07:46: model
  • 07:47: so thanks for listening and see you next
  • 07:51: time

Extending a Simple Python Model


Notes

  • To add iteration to the Python model, just wrap the existing code in a loop

  • We must also collect or show the output in some way, as we can no longer take advantage of the Jupyter shortcut to show the output without printing.

Transcript

  • 00:03: hey everyone
  • 00:04: nick dear burtis here teaching you
  • 00:06: financial modeling today we're going to
  • 00:08: talk about
  • 00:09: extending a basic python model to add
  • 00:12: iteration
  • 00:12: this is part of our getting started with
  • 00:15: python and excel
  • 00:16: segment where we've already built out a
  • 00:19: basic retirement model
  • 00:20: in both excel and python in the last
  • 00:23: video we
  • 00:24: added iteration to the excel model
  • 00:28: so we are now looking at how we can add
  • 00:31: this iteration
  • 00:32: to the python model so
  • 00:35: from uh you know the the prior video
  • 00:38: which went over the basic iteration
  • 00:40: we kind of compared the python iteration
  • 00:43: to the excel iteration
  • 00:45: uh you know in python you're going to
  • 00:47: use loops here we're looking at a
  • 00:49: for loop um and in excel
  • 00:52: you are dragging formulas so ultimately
  • 00:55: accomplishing the same
  • 00:56: result
  • 01:00: now the the python version is quite a
  • 01:03: bit more flexible because you can
  • 01:05: do absolutely anything under that loop
  • 01:08: uh
  • 01:09: whatever whatever operations you want to
  • 01:11: do you can do them whereas excel you
  • 01:13: know it's just
  • 01:14: uh you know taking one formula and
  • 01:16: repeating it so
  • 01:18: you know excel is maybe a little bit
  • 01:20: easier to get into for the iteration
  • 01:22: but python ultimately is a lot more
  • 01:24: flexible and powerful
  • 01:25: and we'll see that over time as the
  • 01:27: course progresses
  • 01:29: let's dig a little bit more into uh this
  • 01:32: python iteration
  • 01:33: and what all this stuff actually means
  • 01:36: um
  • 01:37: so there's a few different parts in here
  • 01:39: the first we kind of you know glossed
  • 01:41: over this a little bit
  • 01:42: last time in that we had this first line
  • 01:45: inputs equals uh you know left square
  • 01:48: bracket
  • 01:49: 5 comma 10 comma 15 right square bracket
  • 01:54: so those square brackets there
  • 01:57: and putting commas in between things
  • 02:00: this is
  • 02:01: a new type of object that we hadn't
  • 02:03: worked with before
  • 02:05: it's not a string it's not a number this
  • 02:08: type of object is called a list
  • 02:11: so just by doing those brackets adding
  • 02:14: those
  • 02:14: commas potentially if there's multiple
  • 02:17: things in there
  • 02:18: you're making a list an object of type
  • 02:21: list
  • 02:23: so this inputs here we have as
  • 02:26: an objective type list and
  • 02:30: a list is one of the data types
  • 02:34: in python which can hold other objects
  • 02:37: within
  • 02:38: itself um so here
  • 02:41: this list is holding three different
  • 02:43: numbers five
  • 02:44: ten and fifteen um so certainly we're
  • 02:48: gonna dig
  • 02:49: a lot more in the list as we go on
  • 02:52: throughout the course
  • 02:54: but for now you can just know it's an
  • 02:56: object which holds other objects
  • 03:00: here we're using it to hold three
  • 03:01: different numbers
  • 03:03: and you can add or remove things from
  • 03:05: the list which we're not even going to
  • 03:07: do in this exercise
  • 03:09: but that's the basic idea behind a list
  • 03:12: you can
  • 03:12: hold multiple things you can add things
  • 03:14: you can remove things and you can look
  • 03:16: up
  • 03:16: specific uh items from the list
  • 03:20: or you can loop through and get each
  • 03:22: item one by one as we
  • 03:24: are doing here so
  • 03:27: we've got you know these three different
  • 03:30: numbers as our inputs 5 10 15 and we've
  • 03:32: stored those into a list
  • 03:35: now we come to the next line the second
  • 03:36: line here for item in
  • 03:38: inputs so this line is what defines the
  • 03:42: loop
  • 03:42: and this is a for loop so
  • 03:46: we know it's a for loop because the
  • 03:47: first word there is 4
  • 03:49: and it has this 4 in syntax
  • 03:52: so it's 4 and then
  • 03:55: whatever we want to call our loop
  • 03:58: variable so that could be
  • 03:59: whatever you want in uh
  • 04:02: and then whatever you want to iterate
  • 04:05: through so we want to iterate through
  • 04:06: this list of inputs
  • 04:08: so it's you know four item item is
  • 04:11: ultimately going to become each one of
  • 04:12: these as we go through
  • 04:15: in inputs that's referring back to this
  • 04:18: list of
  • 04:19: three numbers so
  • 04:22: then it's important that we end this
  • 04:24: line with a colon that's how
  • 04:26: python knows that we're going to start a
  • 04:29: new block here
  • 04:30: a block under the for loop the logic
  • 04:32: which should execute
  • 04:34: in each loop each iteration of the for
  • 04:37: loop
  • 04:39: and then we have the next important
  • 04:42: thing here is the indentation you need
  • 04:44: to have this indentation here
  • 04:46: for python to know we want this stuff to
  • 04:48: run
  • 04:49: under the for loop if we had another
  • 04:51: line of code out here
  • 04:53: that would not be under the loop that
  • 04:54: would run a single time
  • 04:56: after the loop has finished
  • 04:59: um so then you know within the loop
  • 05:02: we're doing two things
  • 05:03: one is we're doing our calculation here
  • 05:06: of adding two
  • 05:07: to whatever our item is either 5 10 or
  • 05:09: 15
  • 05:10: as we go through assigning that to a new
  • 05:14: variable name new value and then
  • 05:16: printing out
  • 05:17: uh that new value and so that's how we
  • 05:20: get
  • 05:21: 7 12 17 because first time it goes
  • 05:23: through with five as
  • 05:24: item five plus two is seven it prints
  • 05:27: that
  • 05:28: then ten comes through his item ten plus
  • 05:30: two is twelve it prints that
  • 05:32: then fifteen comes through on the last
  • 05:33: loop fifteen plus two is seventeen and
  • 05:36: then it will be done with this loop it
  • 05:37: would
  • 05:38: go on to any code which is beyond that
  • 05:41: uh or finish if that's the last code
  • 05:43: that you have
  • 05:47: so that's the basic idea let's go ahead
  • 05:50: and
  • 05:50: look at how we actually
  • 05:54: work with this in the context of our
  • 05:57: existing
  • 05:58: model so i have the python model that we
  • 06:01: built out
  • 06:03: in the last exercise here so
  • 06:06: we already have uh you know getting the
  • 06:09: years to retirement
  • 06:11: for martha based on this
  • 06:14: single uh investment rate of five
  • 06:16: percent here
  • 06:18: so now we want to look
  • 06:21: at multiple uh interest rates
  • 06:25: um and for that
  • 06:29: let's say we want to look at uh
  • 06:32: four or five or let's say five six and
  • 06:34: seven percent
  • 06:37: so we can say you know investment
  • 06:40: rates equals and then brackets and the
  • 06:43: brackets is how we're going to have a
  • 06:45: list here
  • 06:47: um so then we can do five percent six
  • 06:49: percent seven percent
  • 06:51: and you'll notice i'm putting commas uh
  • 06:53: in between
  • 06:54: each of the items the spaces are
  • 06:56: optional they just look nice and people
  • 06:58: normally do them
  • 06:59: um the important thing is that you have
  • 07:01: the commas to separate the items in the
  • 07:04: list
  • 07:05: so then you know we can look at our
  • 07:08: investment rates
  • 07:09: uh and you can see that we indeed get
  • 07:12: back that same list
  • 07:14: of these three numbers
  • 07:17: and so then that takes us to the for
  • 07:20: loop
  • 07:20: next um so we can say
  • 07:24: you know for i rate and investment rates
  • 07:29: let's just print out that um investment
  • 07:32: rate
  • 07:33: this is you know pretty much the
  • 07:36: simplest loop that you could have
  • 07:38: so we can see it prints five and then it
  • 07:41: prints six and then it prints seven
  • 07:43: and you know if we had some code out
  • 07:45: here
  • 07:46: uh then that's gonna run
  • 07:49: once at the end of the loop after it's
  • 07:52: done
  • 07:52: uh if we put that into the loop then
  • 07:55: it's going to run
  • 07:56: once per loop so that's you know where
  • 07:59: the importance of this indentation
  • 08:01: comes in anything which is indented is
  • 08:04: going to run as part of the loop so it's
  • 08:05: going to run over and over
  • 08:06: for as many inputs as you have that's
  • 08:08: why we have three dones here
  • 08:10: we move it back and we're back to one
  • 08:13: done
  • 08:13: because it does this print line three
  • 08:15: times and then this is not
  • 08:17: indented so then it does this after it
  • 08:20: has finished
  • 08:21: the for loop and if you try to have
  • 08:24: no indent at all it's going to give you
  • 08:26: an indentation error
  • 08:28: expected in indented block and that's
  • 08:31: because you know any time
  • 08:32: you're doing a colon like this in python
  • 08:35: it's expecting you to start a new
  • 08:37: indented block
  • 08:39: and so we need to have that for it to be
  • 08:42: valid python
  • 08:45: so that's the basic uh way to loop
  • 08:48: through these investment rates so now
  • 08:50: let's
  • 08:51: bring in the actual calculation that we
  • 08:53: want to do
  • 08:56: so we have our calculation here from
  • 08:58: before
  • 09:01: but we don't want to use the single
  • 09:03: investment rate
  • 09:05: from before we want to use this irate
  • 09:07: which is
  • 09:08: you know each uh investment rate so i
  • 09:11: run that
  • 09:12: and then you don't see any output right
  • 09:14: because again
  • 09:15: we have to actually tell python that we
  • 09:17: want to see what we calculated it is
  • 09:19: doing the calculations but
  • 09:21: it just doesn't show them by default so
  • 09:24: we're going to bring this
  • 09:24: print statement also into that loop
  • 09:29: and now you can see that we get the
  • 09:31: three different
  • 09:32: uh years to retirement here but uh
  • 09:36: it's you know not uh quite there yet
  • 09:40: because
  • 09:40: it's not clear which user retirement
  • 09:43: goes with which interest rate
  • 09:45: so let's include that into the message
  • 09:47: as well
  • 09:48: so if she earns a
  • 09:51: irate and then put the number formatting
  • 09:55: we'll go over more of what all this
  • 09:57: number formatting
  • 09:59: need means when we get into the python
  • 10:02: basics
  • 10:03: um but now we can see that that's
  • 10:05: included in the string as
  • 10:07: well so now we have you know same thing
  • 10:10: that we had in excel
  • 10:12: uh now we're using a loop we have the
  • 10:14: same code
  • 10:15: uh which which executes for all three
  • 10:17: iterations
  • 10:20: and we see the results for each one and
  • 10:23: again that
  • 10:25: indentation is important if we just put
  • 10:26: the print here it's only going to show
  • 10:28: us
  • 10:29: the last one because it finishes the
  • 10:31: loop and then it has everything set up
  • 10:32: from the last loop
  • 10:34: uh so make sure to pay a lot of
  • 10:36: attention to that indentation
  • 10:38: uh so that everything that you're
  • 10:40: executing as a part of the loop
  • 10:42: is indented and everything which you
  • 10:44: aren't is not
  • 10:48: so uh you know that's the uh
  • 10:51: way we can add iteration to our python
  • 10:54: models and functions we're going to come
  • 10:58: back
  • 10:59: next time to discuss the lab exercise
  • 11:03: for this material so thanks for
  • 11:05: listening
  • 11:06: and see you next time

Getting Started with Python and Excel Labs


Notes

  • This is our first real lab exercise (must be submitted). Be sure to complete the same exercise in both Python and Excel

  • We often want to iterate over more than one input. Here we want to look at the pairwise combinations of the savings rate and interest rate possibilities.

  • Excel hint: there is a nice way to lay this out so you only need to type the formula a single time

  • Python hint: It is possible to nest loops to loop over the combination of two different inputs

Transcript

  • 00:03: hey everyone
  • 00:04: nick dear british here teaching you
  • 00:06: financial modeling today we're going to
  • 00:08: talk about
  • 00:09: the lab exercise to go along with the
  • 00:11: getting started with python and excel
  • 00:13: segment of the course so
  • 00:17: the lab exercise and this is our first
  • 00:20: uh lab exercise where you actually have
  • 00:23: something to
  • 00:24: submit so the idea here is we're going
  • 00:27: to go a little bit further
  • 00:28: with this concept of adding iteration to
  • 00:31: our
  • 00:32: models so we already looked at you know
  • 00:34: how to vary the
  • 00:36: uh the interest rate uh
  • 00:40: for both our excel and python models
  • 00:43: so now this is about let's not only vary
  • 00:46: the interest rate
  • 00:47: but let's also vary the savings rate at
  • 00:50: the same time
  • 00:51: so not only are we going to look at
  • 00:53: these three different interest rate
  • 00:54: cases
  • 00:55: we're also going to look at three
  • 00:56: different savings rate cases
  • 00:58: and every pairwise combination of those
  • 01:00: two
  • 01:01: so there should ultimately be nine
  • 01:03: values uh
  • 01:04: for uh the model for you know ten
  • 01:08: percent savings rate with four percent
  • 01:09: interest rate
  • 01:10: ten percent savings rate with five
  • 01:12: percent interest rate uh ten percent
  • 01:14: with six percent
  • 01:15: then twenty five percent with four
  • 01:16: twenty five with five and so on
  • 01:18: um nine different cases and
  • 01:22: you're going to need to implement this
  • 01:24: entire thing
  • 01:25: and both excel and python
  • 01:30: so as far as implementing it you can go
  • 01:32: ahead and
  • 01:33: you know download the completed example
  • 01:36: model and start to work from that and
  • 01:39: then just go
  • 01:40: and add this additional iteration
  • 01:43: on the savings rate um
  • 01:47: and uh as far as giving you a little bit
  • 01:50: of help
  • 01:51: on getting started um so for excel
  • 01:54: hopefully things are fairly clear on
  • 01:57: what you need to do there
  • 01:59: but i will say there is a nice way that
  • 02:03: you
  • 02:03: can lay everything out
  • 02:06: where you still only need to type the
  • 02:09: formula once and you can drag it in both
  • 02:11: directions
  • 02:12: uh to get all nine different values uh
  • 02:15: and that's going to require
  • 02:16: using uh you know some fixed references
  • 02:19: which are fixed only on the column and
  • 02:22: some which are fixed only on the row
  • 02:26: then on the python side
  • 02:29: uh the uh you know one good way to go
  • 02:33: about this
  • 02:34: is to do a nested for loop
  • 02:37: so that uh definitely trips a lot of um
  • 02:41: beginners up so let's take a look at
  • 02:44: uh what that looks like um
  • 02:48: so let's say you know we have you know
  • 02:50: one
  • 02:51: uh list here and then we have
  • 02:54: another list here um
  • 02:58: one list of numbers one list of strings
  • 03:01: so you can
  • 03:02: uh right
  • 03:05: two loops
  • 03:11: inside of each other
  • 03:17: so um or sorry this would be print
  • 03:21: a item print the item to get the actual
  • 03:25: loop variable
  • 03:26: um so there you can see we get the same
  • 03:30: kind of effect that we're going for
  • 03:33: with this model right we get uh you know
  • 03:35: one
  • 03:36: with a and then we get one with b and
  • 03:39: then we get one with c
  • 03:40: and then we get two with a and then two
  • 03:42: of b two and so on
  • 03:44: so this is the same kind of you know
  • 03:46: pairwise combination
  • 03:48: that we're looking for with this model
  • 03:51: and then of course you know rather than
  • 03:52: just printing you would want to actually
  • 03:55: put your logic inside of that inner loop
  • 03:58: and you will notice you know each for
  • 04:01: loop needs its own
  • 04:02: indentation right so we write the
  • 04:04: original for loop
  • 04:06: and then we have that four loops ending
  • 04:09: and now we write another for loop and
  • 04:10: then we have that for loops indent on
  • 04:12: top of that so two
  • 04:14: levels of indentation here to ultimately
  • 04:17: write
  • 04:18: our main logic so hopefully
  • 04:21: with you know what we've covered as well
  • 04:23: as this information
  • 04:24: that should be everything you need to be
  • 04:26: able to complete these labs
  • 04:28: now they are meant to you know challenge
  • 04:30: you a little bit and going just a little
  • 04:31: bit farther
  • 04:33: than the material that we covered but
  • 04:36: that's why we also have
  • 04:37: the uh you know lab sessions where you
  • 04:40: know you can come and you can ask
  • 04:41: questions
  • 04:42: and get feedback on everything so you're
  • 04:44: not going this
  • 04:45: 100 alone so
  • 04:49: that's how we will wrap up this getting
  • 04:51: started with python and excel
  • 04:53: segment next time uh the whole next
  • 04:57: segment is going to be about
  • 04:59: uh you know building a more in-depth
  • 05:02: excel model and what that looks like
  • 05:06: so thanks for listening and see you next
  • 05:08: time