Worked Example: A Mortgage Class Hierarchy closed by printing three mortgages' total costs as plain numbers — informative, but not nearly as illuminating as seeing how each mortgage's payments, balance, and cumulative cost evolve month by month. This capstone note adds four plotting methods directly to the
Mortgage class, extending the exact hierarchy already built, and produces a small suite of comparison charts across the fixed-rate, fixed-with-points, and two-rate mortgages. It closes this unit's entire eight-topic arc — every idea used here (classes, inheritance, loops, functions, and now plotting) was built somewhere earlier in this unit, and the point of this final lesson is to see them combined on one genuinely useful, quant-flavoured problem.Learning objectives. By the end of this note you should be able to:
- add plotting methods to an existing class, keeping the plotting logic inside the class (uniform for every subclass) while letting each subclass's own state drive what actually gets plotted;
- use a
styleslist indexed in parallel with a list of objects to keep visual encoding (e.g. line style) consistent across multiple separate figures; - write a small local helper function (
label_plot) to avoid repeating the same title/label/legend boilerplate across several figures; - read a small multi-figure comparison and draw a genuine financial conclusion from it — which mortgage type is cheapest under which view (monthly payment vs. total cost vs. remaining balance).
In this lesson
- Adding plotting methods to
Mortgage - Comparing three mortgages across four views
Before you start
The full lesson, with worked examples and exercise solutions, is for members.
Read the full lessonNew to SelfMadeQuant.com? See membership options or browse the Python for Quantitative Finance syllabus.