Chapter 7. Object-Oriented Programming
The purpose of software engineering is to control complexity, not to create it.
Pamela Zave
Object-oriented programming (OOP) helps you structure code around the concepts you work with every day in finance: positions, portfolios, data loaders, and models. This chapter introduces Python’s class system in a pragmatic way so that, later in the book, code can encapsulate behavior cleanly instead of passing long lists of parameters between functions.
The chapter shows how to define simple classes in Python, work with attributes and
methods, use special methods such as .__init__() and .__repr__(), and design
small, testable objects for finance workflows. It shows how to create instances, model
simple financial concepts such as positions and portfolios, separate responsibilities
between data containers and behavior, and use basic inheritance when it genuinely
simplifies code.
To follow along, you need a working python interpreter, familiarity with functions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access