\(
\newcommand{\bm}[1]{\boldsymbol{#1}}
\newcommand{\textm}[1]{\textsf{#1}}
\newcommand{\textnormal}[1]{\textsf{#1}}
\def\T{{\mkern-2mu\raise-1mu\mathsf{T}}}
\newcommand{\R}{\mathbb{R}} % real numbers
\newcommand{\E}{{\rm I\kern-.2em E}}
\newcommand{\w}{\bm{w}} % bold w
\newcommand{\bmu}{\bm{\mu}} % bold mu
\newcommand{\bSigma}{\bm{\Sigma}} % bold mu
\newcommand{\bigO}{O} %\mathcal{O}
\renewcommand{\d}[1]{\operatorname{d}\!{#1}}
\)
Code Examples
This book is supplemented with a large number of code examples in R and Python that can reproduce all the figures in the book. These supplementary resources are available on the companion website for the book.
Generally speaking, the resolution of all the portfolio optimization formulations covered in the book can be approached in a variety of ways, namely:
Use a software package or library specifically designed to optimize portfolios under a wide variety of formulations and constraints. Examples include the popular R package fPortfolio (Wuertz et al., 2023) and the Python packages skfolio (Delatte et al., 2026; Nicolini et al., 2025), Riskfolio-Lib (Cajas, 2026), and PyPortfolioOpt (Martin, 2021).
Utilize a modeling framework like CVX, which automatically calls upon a solver behind the scenes, available for programming languages including Python, R, and Julia (Fu et al., 2022, 2020; Grant and Boyd, 2008, 2014).
Directly invoke an appropriate solver.
Develop ad hoc efficient algorithms for specific formulations, as done in the packages developed by the ConvexFi group.
Cajas, D. (2026).
Riskfolio-Lib.
Delatte, H., Nicolini, C., and Manzi, M. (2026).
skfolio.
Fu, A., Narasimhan, B., and Boyd, S. (2020). CVXR: An R package for disciplined convex optimization. Journal of Statistical Software, 94(14), 1–34.
Fu, A., Narasimhan, B., Kang, D. W., Diamond, S., Miller, J., Boyd, S., and Rosenfield, P. K. (2022).
CVXR: Disciplined Convex Optimization.
Grant, M., and Boyd, S. (2008). Graph implementations for nonsmooth convex programs. In V. Blondel, S. Boyd, and H. Kimura, editors, Recent advances in learning and control, pages 95–110. Springer.
Martin, R. A. (2021). PyPortfolioOpt: Portfolio optimization in Python. Journal of Open Source Software, 6(61), 1–5.
Nicolini, C., Manzi, M., and Delatte, H. (2025).
skfolio: Portfolio optimization in Python. In
Proceedings of the international research and industry symposium on AI (IRIS-AI 25), pages 35–41.
Wuertz, D., Setz, T., Chalabi, Y., Chen, W., and Theussl, S. (2023).
fPortfolio: Rmetrics – Portfolio Selection and Optimization.