"This is a code block that does show output"
"This is a code block that does show output"
Alec Loudenback
“I think one of the things that really separates us from the high primates is that we’re tool builders. I read a study that measured the efficiency of locomotion for various species on the planet. The condor used the least energy to move a kilometer. And, humans came in with a rather unimpressive showing, about a third of the way down the list. It was not too proud a showing for the crown of creation. So, that didn’t look so good. But, then somebody at Scientific American had the insight to test the efficiency of locomotion for a man on a bicycle. And, a man on a bicycle, a human on a bicycle, blew the condor away, completely off the top of the charts.
And that’s what a computer is to me. What a computer is to me is it’s the most remarkable tool that we’ve ever come up with, and it’s the equivalent of a bicycle for our minds.” - Steve Jobs (1990)
The world of financial modeling is incredibly complex and variegated. It, along with many of the sciences, is a place where practical goals harness computational tools to arrive at answers that (we hope) are meaningful in a way that tells us more about the world we live in. What this usually means specifically is that practitioners utilize computers to do the heavy work of processing data or running simulations which reveal insights about the complex systems we seek to represent. In this way, then, financial modelers must also be a craftsman who seeks not only to design new products, but must also think carefully about the tools and the process used therein.
This book seeks to aid the practitioner in developing that workmanship: we will develop new ways to look at the process, think about how to most clearly represent ideas, dive into details about computer hardware and bring it back up to the most abstract levels, and develop a vocabulary to more clearly express and communicate these concepts. The book contains a large number of practical examples to demonstrate that the end result is better for the journey we will take.
This book addresses programming for the applied financial professional, starting with a fundamental question: “Why is this relevant for financial modeling?”. The answer is simple: financial modeling is complex, data intensive, and often very abstract. Programming is the best tool humans have so far developed for rigorously transforming ideas and data into results. A builder may be the most skilled person in the world with a hammer but another with some basic training in a richer set of tools will build a better house. This book will enhance your toolkit with experience with multiple tools: a specific programming language, yes, but much more than that: a language to talk about solving problems, a deeper understanding of specific problem solving techniques, how to make decisions about what the architecture of a solution looks like, and practical advice from experienced practitioners.
The authors of the book are practicing actuaries, but we intend for the content to be applicable to nearly all practitioners in the financial industry. The discussion and examples may have an orientation towards insurance topics, but the concepts and patterns are applicable to a wide variety of related disciplines.
We will pull from examples on both sides of the balance sheet: the left (assets) and right (liabilities). We may also take the liberty to, at times, abuse traditional accounting notions: a liability is just an asset with the obligor and obligee switched. When the accounting conventions are important (such as modeling a total balance sheet) we will be mindful in explaining the accounting perspective. In practice, this means that we’ll take examples that use examples of assets (fixed income, equity, derivatives) or liabilities (life insurance, annuities, long term care) and show that similar modeling techniques can be used for both.
It is our hope that with the help of this book, you will find it more efficient to discuss aspects of modeling with colleagues, borrow problem solving language from computer science, spot recurring structural patterns in problems that arise, and understand how best to make use of the “bicycle for your mind” in the context of financial modeling.
It is the experience of the authors that many professionals that do complex modeling as a part of their work have gotten to be very proficient in spite of not having substantive formal training on problem solving, algorithms, or model architecture. This book serves to fill that gap and provide the “missing semester” (or “years of practical learning”!). After reading this book, we hope that you will appreciate the attributes of Microsoft Excel that made it so ubiquitous, but that you prefer to use a programming language for the ability to more naturally express the relevant abstractions which make your models simpler, faster, or more usable by others.
Even if your direct responsibility does not entail hands-on-coding, be it management or “low-code”, the ideas and language should prove useful in guiding the work to a cleaner, more efficient solution.
Learning a new topic, especially one that’s not well trodden in a given field, can be intimidating. There are many resources available online, this book will recommend some others, and there are community support resources available - check the chat and forums and look for the users talking about the topics that interest you. One of the wonderful things about the technology community is the degree to which content is available online for learning and reference.
Further, moving substantial parts of the financial services industry towards a digital-first, modern workflow is a monumental effort and you should seek partners on both the finance and information technology side. In general, good ideas and processes will prevail. The trick to encouraging adoption is finding the right place to plug a new idea or suggestion.
Additionally, this book provides the language and technical knowledge to partner with others (such as peers and IT) to make pragmatic decisions about the tradeoffs that will need to be made.
This book will guide you through:
The goal is to build both theoretical understanding and practical skills you can apply immediately in your work.
Basic experience with financial modeling is not strictly required, but it will benefit the reader to be familiar so that the examples will not be attempting to teach both financial maths and computer science simultaneously.
Advanced financial maths (e.g. stochastic calculus) is not required. Indeed, this book is not oriented to the advanced technicalities of Wall Street “quants” and is instead directed at the multitudes of financial practitioners focused on producing results that are not measured in the microseconds of high-frequency trading.
Prior programming experience is not required either: 5 Elements of Programming introduces the basic syntax and concepts while 21 Writing Julia Code covers setting up your environment to follow along. For readers with background in programming, we recommend skimming 5 Elements of Programming.
The book is organized into eight parts, each addressing key aspects of computational thinking and financial modeling. Part I introduces foundational concepts, explaining why programming matters for financial professionals, and why Julia is particularly well-suited for financial modeling applications.
Parts II, III, and IV establish the theoretical foundations—covering effective financial modeling practices, programming abstractions, and techniques for building performant models. These sections bridge theory with practical implementation, exploring topics like model design, functional programming, data types, and parallelization strategies.
Part V connects interdisciplinary concepts with practical applications, demonstrating how software engineering practices, computer science principles, statistical methods, and visualization techniques enhance financial modeling.
Part VI provides detailed guidance on developing in Julia, from writing and troubleshooting code to optimization. This is the section that really leans into Julia-specific ideas and workflows.
Part VII showcases applied financial modeling techniques through real-world examples, including stochastic mortality projections, scenario generation, sensitivity analysis, and portfolio optimization.
While Julia is used for the examples throughout the book, the concepts presented are largely language-agnostic. The principles of computational thinking and financial modeling remain applicable regardless of implementation language. Readers are encouraged to follow along with the examples on their own computers, with the entire book available at https://ModernFinancialModeling.com.
This text is written with the intention to explain and show many core and related concepts that are useful for a practitioner utilizing code-based modeling and workflows. If you are looking for a crash course in getting up to speed in order to contribute to a functional project, here is a “crash course” syllabus for getting the most out of this book:
How | Chapter Number | Chapter Title | Why |
---|---|---|---|
Skim and re-reference | 5 | Elements of Programming | Programming syntax and core components provided by most languages |
Read in Entirety | 6 | Functional Abstractions | Patterns of functional abstractions that are repeatedly useful in financial modeling |
Read in Entirety | 7 | Data and Types | Utilizing types of data to improve efficiency and architecture of models |
Read in Entirety | 12 | Apply Software Engineering Practices | Best practices for code-based workflows, including version control, testing, documentation, and code distribution. |
Skim and re-reference | 21-24 | Developing in Julia | Writing, troubleshooting, distributing, and optimizing Julia specific code. Skim lightly if using a language other than Julia, because you will learn what kinds of tools to look for in other languages. |
When a concept is defined for the first time, the term will be bold. Code, or references to pieces of code will be formatted in inline code style like 1+1
or in separate code blocks:
"This is a code block that doesn't show any results"
"This is a code block that does show output"
"This is a code block that does show output"
When we show inline commands are to be sent to Pkg mode in the REPL (see Environments and Dependencies), such as add DataFrames
, we will try to make it clear in the context. If using Pkg mode in standalone codeblocks, it will be presented showing the full prompt, such as:
(@v1.10) pkg> add DataFrames
There will be various callout blocks which indicate tips or warnings. These should be self-evident but we wanted to point to a particular callout which is intended to convey advice that stems from practical modeling experience of the authors:
This box indicates a side note that’s particularly applicable to improving your financial modeling.
The HTML and PDF book were rendered using Quarto and Quarto’s open source dependencies like Pandoc and LaTeX.
The HTML version of this book uses Lato for the body font and JuliaMono for the monospace font.
The PDF version of this book uses TeX Gyre Pagella for the body font and JuliaMono for the monospace font.
The cover was designed by Alec Loudenback using Affinity Designer with the graphic used under permission by user cormullion on GitHub.
This book was rendered on July 25, 2025. The system used to generate the code and benchmarks was:
versioninfo()
Julia Version 1.11.6
Commit 9615af0f269 (2025-07-09 12:58 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin24.0.0)
CPU: 14 × Apple M4 Max
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 10 default, 0 interactive, 5 GC (on 10 virtual cores)
Environment:
JULIA_NUM_THREADS = auto
JULIA_PROJECT = @.
JULIA_LOAD_PATH = @:@stdlib
This work is copyright Alec Loudenback and Yun-Tien Lee. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License unless otherwise noted. The chapters including and between 21 Writing Julia Code and 24 Optimizing Julia Code are licensed under the CC Attribution-ShareAlike 4.0 International License. This is not a Milliman-sponsored project.