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. Resources ============ - :download:`Slides - Getting Started with Python and Excel ` - :download:`Lecture Notes - Getting Started with Python and Excel ` - :download:`Simple Retirement Model - Excel ` - :download:`Simple Retirement Model - Python ` Introduction and an Example Model ==================================== .. youtube:: KL48T_XGbzI :height: 315 :width: 80% :align: center | 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 ------------- .. raw:: html
| Building a Simple Excel Model ================================ .. youtube:: hySE7wOAlfc :height: 315 :width: 80% :align: center | 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 Resources ------------ - :download:`Simple Retirement Model - Excel ` Transcript ------------- .. raw:: html
| Building a Simple Python Model ================================= .. youtube:: syrwXU1wqps :height: 315 :width: 80% :align: center | 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 Resources ------------ - :download:`Simple Retirement Model - Python ` Transcript ------------- .. raw:: html
| Basic Iteration ================== .. youtube:: vAOrxaKnXaQ :height: 315 :width: 80% :align: center | 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 ------------- .. raw:: html
| Extending a Simple Excel Model ================================= .. youtube:: GD34LyjvMaE :height: 315 :width: 80% :align: center | 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 ------------- .. raw:: html
| Extending a Simple Python Model ================================== .. youtube:: Ejk6ektd21I :height: 315 :width: 80% :align: center | 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 ------------- .. raw:: html
| Getting Started with Python and Excel Labs ============================================= .. youtube:: 2J-GCwSNGBw :height: 315 :width: 80% :align: center | 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 ------------- .. raw:: html
|