Teaching Financial Calculations with Online Tools

Spreadsheets, Lightweight coding environments, and Notebooks

Matthew Frank
8 min readApr 27, 2021

What are good technologies for teaching financial calculations online?

Instructional context: I’ll use mortgage calculations as a example, in a context of teaching someone who is learning to calculate mortgage payments now, and how to divide them between principal and interest. They’ll be doing more sophisticated calculations later, perhaps simulating adjustable-rate mortgages, or measuring credit risk in mortgage derivatives, or modeling tax consequences from corporate debt. So they need to the learn the basic calculations well, more deeply than a scientific calculator will allow, to be tested on the calculations now and to use them in the future.

With that context, I’m evaluating tools that will let learners answer questions like:

  • Does the calculation shown here input annual or monthly interest rates, and where would you change it for the other option?
  • In a 30-year mortgage of $150,000 at 3%, when does a monthly payment start to go more to principal than interest?
  • Suppose that every week for the past three years, a bank has originated 30-year mortgages of $150,000 with interest rates that match Freddie Mac’s surveys. Can you create a graph showing the monthly payment required for each week’s originations?

I see three good online technologies for teaching them the calculations needed to answer these questions: online spreadsheets, lightweight coding environments, and notebooks. I’ll rule out some other options first, and then survey the advantages and disadvantages of these three good options — the takeaway may be this summary table:

summary table

For all of these technologies I found online examples already built with the calculations, and in most cases you can just click on them to try out the learning experience with that technology.

Some not so good options

Too Easy

Many websites will skip the calculations and just show how much a mortgage would cost. This won’t be enough to teach the calculations, but it will provide motivation and context for people learning the calculations elsewhere. Here is an example from Bank of America:

snippet from Bank of America

As an alternative, WolframAlpha also skips the calculations but stays more mathematically focused. For instance, if you give it the text “mortgage $150,000, 6.5%, 30 years”, it will quickly tell you that your monthly payment is $948, and how that breaks down into principal and interest by month:

WolframAlpha snippet

In a classroom setting, this acceptance of free-form input makes WolframAlpha especially useful for demonstrations or discussing new examples on the fly, for many financial topics. Outside of class, it’s useful for all of that exploration, or for checking work calculated in other ways.

So these websites are useful, but too easy for these instructional goals, since learners will have to see the calculations elsewhere.

Too Hard

One way to showcase calculations is to put them in an app, e.g. a Shiny app. The result can make it easy to enter data and see the numerical and graphical results.

Shiny snippet

Here the code is in R, and available in server-side and user-side parts. There are similar ways of creating apps with Python (e.g. Plotly and Dash) and Mathematica (e.g. WolframDemonstrations or WebMathematica).

These apps are too easy if learners just use the finished app, without looking at the code and calculations.

However, these apps make it difficult for learners to test or tinker with the calculations. E.g., the Shiny code spits the calculations into two pieces and often emphasizes formatting over numbers. So if those learners want to produce these apps to communicate with senior colleagues later, that’s a good reason for them to produce one or two such apps in their learning experience; but it’s too awkward for anyone to learn most calculations in this format.

Good option #1: Online spreadsheets

One familiar way to calculate mortgage payments is in Excel, and the most familiar way to put such spreadsheet calculations online is in a Google Sheet. Here is one such example, which calculates monthly payments and breaks them into interest vs principal payments:

Excel snippet

This approach has all the usual advantages and disadvantages of calculating in spreadsheets.

Advantages

Tinkering: Spreadsheets make it easy to tinker with calculations.

Ease of setup: Google Sheets works easily across many platforms and operating systems.

Transparency: Spreadsheets show all the calculations transparently.

New Calculations: Spreadsheets make it easy to create new calculations.

Formatting: Spreadsheets make it easy to format graphics, though they make it awkward to format text commentary.

Disadvantages

Clarity: Spreadsheets can hide the overarching idea of a calculation, especially since they show only one formula at a time.

Power: Spreadsheets are limited in speed, memory, and file size. They won’t work well for modeling adjustable rates, credit risk, or other more advanced calculations.

Model Control: It is possible but awkward to run tests of spreadsheets, and most people don’t. Similarly, it’s often awkward to comment on or write paragraphs of explanation for the code.

Good option #2: Lightweight coding environments

Another familiar way to do these calculations is in Python or R, and there are online coding environments which can run that code on the web. As an example, here are some mortgage calculations in a lightweight coding environment using Python on a webpage:

Python snippet in lightweight environment

This code is based on an online source, which I mildly adapted to work in this lightweight coding environment that lacks some libraries and some of their features. (This is the only code linked in this post that I had to tinker with at all.) There are similar online coding environments for R too.

Advantages

Tinkering: These lightweight setups may encourage tinkering with the calculations more than any other format. This is slightly balanced by tinkering being more likely to introduce syntax errors than in any other format.

Ease of setup: These lightweight setups are easy-to-use webpages, working across many platforms and operating systems.

Clarity: Good code is a good way to show or highlight the essential parts of a calculation, limited only by the fact that these setups display the code in small windows and can’t hide pieces of code well.

Power: These lightweight setups are more powerful than a spreadsheet, but still limited by the fact that the calculations are all run from some central server.

Model Control: It is easy to test code in these lightweight setups, and easy to provide bits of plain-text documentation, though they don’t allow nicer formatting for longer commentary.

Disadvantages

Formatting: It’s awkward to format graphics well in these lightweight setups: the layout may change from one screen to the next, and it won’t let you resize either text or graphics.

Transparency: These lightweight setups make it hard to track how each variable changes during the execution of the code.

New Calculations: Because these lightweight setups lack some transparency, it’s also hard to write new code in them.

Good option #3: Industrial-strength coding environments

A more industrial-strength coding environment is a Jupyter notebook, e.g.:

Python snippet in Jupyter notebook

(This shows a Jupyter notebook with Python, but Jupyter notebooks can now work with R too, and Mathematica has long had similar notebooks also.)

Such notebooks can be put on the web interactively in many ways. Or the notebooks can be made available for download from the web. Then learners might either install software on their other machines to use the notebooks, or use them on an appropriate virtual machine.

Advantages

Formatting: This has the greatest flexibility with formatting for both text and graphics.

Clarity: Good code is one of the best ways to show or highlight the essential parts of a calculation, and the formatting of a good notebook can do it even better.

Model Control: It is easy to run document code and run unit tests in a format like this, and financial firms use notebooks like this for that purpose.

Transparency: Notebooks like this are designed with systems for debugging and tracking the values of variables during execution, so they offer good transparency.

Creating: This is a good framework for writing new code.

Power: This is one of the ways that financial companies operate their code, so it probably has more than any learner would need in speed, memory and data capabilities.

Disadvantages

Tinkering: These notebooks don’t encourage casual tinkering with the calculations, because they don’t encourage causal use of the notebooks. It’s also awkward to compare notebooks running simultaneously in different parts of the screen, which would be easier with the other options.

Ease of setup: Of the three environments, the notebooks are the hardest to make work with a large number of learners. Either those learners will need to spend time accessing or setting up a machine that can operate the notebook, or whoever is teaching will need to spend time making the notebooks operable over the web. In particular, I can link to the notebook above, but I don’t see any free website which will run it live over the web.

Conclusion: Choosing between the three good options

These are three good options for teaching financial calculations with online tools. One class or unit of instruction could use any of them or a combination. For instance:

  • Simple calculations can be presented in a spreadsheet. E.g.: these mortgages, or the tax consequences of corporate debt.
  • Calculations that are simple but require a bit more computation, or a standard library of functions, can be presented in a lightweight coding environment. E.g.: adjustable-rate mortgages, or credit risk in mortgage derivatives.
  • The most complicated calculations, which require substantial time or memory or data transfers, can be presented with an industrial-strength notebook. E.g.: probably anything with data on individual mortgages.

I hope this post is useful, and feel free to contact me if you are looking to teach any material like this, implementing a new technology, or developing new instructional material.

--

--

Matthew Frank

I’m a trainer for data science and finance. I train clients and students on risk management, compliance, coding and statistics. (linkedin.com/in/mattfrank04)