Preface
"All we have to decide is what to do with the time that is given to us."
— Gandalf, The Lord of the Rings: The Fellowship of the Ring (2001)
There is no shortage of deciding-what-to-do in quantitative finance.
Every model trained, every position sized, every alert investigated is
a small decision under uncertainty. What this book argues — and what
each chapter will try to make concrete — is that the workflow for
those decisions has finally matured enough to be written down
end-to-end.
I have spent the last few years assembling that workflow piece by
piece for my own work: a forecaster I could defend to a risk officer,
a policy I could explain to a portfolio manager, a latent-state model
I could intervene on for a research question, an agent that could glue
the rest together when the deadline was tight. Each piece exists in
excellent isolated treatments — there are textbooks on time-series
forecasting, on portfolio choice, on state-space modelling, and now
on agentic AI. What is harder to find is a single source that takes
one problem all the way through, with the same notation, the same
data, and the same code. This book is my attempt at that source.
What this book is
A practical, end-to-end walkthrough of modern financial forecasting
and decision systems, organised so each chapter feeds the next:
- Theory and Python foundations in Chapters 2 and 3 set the
conventions everything else assumes — return formulas, evaluation
protocols, Polars patterns, PyTorch basics.
- Forecasting (Chapter 4) turns those returns into predictive
distributions. Calibration and sharpness are the through-lines, not
RMSE.
- Optimal decisions (Chapter 5) turn the predictions into
positions, balancing utility, risk, and the friction of real
markets. Static optimisation, dynamic programming, and reinforcement
learning each get their place.
- Modelling dynamics (Chapter 6) opens up the latent-state
machinery — Kalman filters, dynamic factor models, deep dynamic
factor models — that lets us reason about why a forecast moves,
not just what it predicts.
- LLM integration and AI agents (Chapters 7 and 8) wrap the
numerical core in language interfaces, retrieval, and tool calls.
Useful as glue; not yet a replacement for the numerical core itself.
- RL fine-tuning (Chapter 9) covers the practical TRL toolchain
— SFT, DPO, GRPO, reward modelling — for the cases where pure
prompting is not enough.
- Synthetic data (Chapter 10) closes the loop by generating
realistic counterfactual paths so the rest of the stack can be
stress-tested without exposing capital.
The aim throughout is to keep theory close to code. Every chapter
pairs the mathematical statement of an idea with a working snippet,
usually in Polars for data and
PyTorch for models. Longer runs live as
end-to-end scripts under codes/; the README there maps each script
to the section it backs.
What this book is not
It is not a substitute for a serious treatment of probability,
optimisation, or asset pricing. Where those subjects are needed I
quote the result and point to the standard reference. It is also not
a tutorial on back-testing infrastructure or production deployment —
those topics are adjacent and important, but each deserves its own
book.
It is also not, deliberately, a survey. Every methods chapter has had
to pick a small number of techniques to develop in depth rather than
list everything in the area. Where a technique I think is genuinely
useful did not make the cut, the relevant section says so and points
to the literature.
How to read it
The chapters are designed to be read in order, but each chapter index
is self-contained so you can drop in to any topic and still see the
plan. Chapter 1 is the entry point I would skim even if you read
nothing else — it lays out the prediction → decision → dynamics →
automation → synthesis pipeline, names the three reading paths through
the book, and fixes the notation everything later uses.
If you are new to dynamic-factor or state-space thinking, the path I
would recommend is modelling-first: Chapter 2 → Chapter 6 →
Chapter 4 → Chapter 5, then Chapters 7–9 in order. If you already
know the modelling and need the agentic plumbing, jump to Chapters 7
and 8. Detailed reading paths and the full notation table live in the
Chapter 1 index.
Acknowledgements
This material grew out of teaching notes and a series of research
projects on identifiable latent representations and recursive-utility
reinforcement learning. I am grateful to the students who pushed
back on early drafts, and to the open-source communities behind
Polars, PyTorch, sktime, and Hugging Face for the tools that make
this kind of book possible at all.