1 Preface

1.1 Purpose

This book provides an introduction to the topic of portfolio optimization and discusses several branches of practical interest from this broad subject.

We intended it to be a practical guide, a cookbook, that not only serves as a reference but also supports the reader with practical implementation. We do not assume that the reader is acquainted with portfolio optimization, thus the book can be used as a starting point, while for the experienced reader it can serve as a review.

First we familiarize the reader with the basic concepts and the most relevant approaches in portfolio optimization, then we also present computational examples with code to illustrate these concepts and to provide a basis for implementing more complex and more specific cases. We aim to keep the discussion concise and self-contained, covering only the main ideas and tools, the most important pitfalls, both from theoretical and from technical perspective. The reader is directed towards further reading in each subject through references.

1.2 Content

Each of the chapters is organized around a specific subject:

  • Sec. 2 (Markowitz portfolio optimization) is a general introduction, and is recommended to be read first to familiarize with the problem formulation and notations used throughout this book. Here we also present a code example showing how to use MOSEK to model the problem and how to solve it.

  • Sec. 3 (Input data preparation) summarizes concepts and pitfalls related to the preparation of raw data. Here we discuss how to arrive at security returns data suitable for optimization, starting from raw data that is commonly available on the internet. This chapter is recommended as a second read.

  • Each of the subsequent chapters are focusing on a specific topic: mitigating estimation error, using factor models, modeling transaction costs, and finally optimizing relative to a benchmark. These chapters are independent and thus can be read in any order.

  • The book assumes a basic familiarity with conic optimization. Sec. 8.1 (Conic optimization refresher) can be used as a quick refresher in this topic. It shows how to convert traditional quadratic optimization (QO) and quadratically constrained quadratic optimization (QCQO) problems into equivalent quadratic conic optimization models, and what are the advantages of this conversion. Then it briefly introduces other types of cones as well.

1.3 Code examples

The code examples are all in MOSEK Fusion API for Python, but all of them can be written in other languages too. The list of programming languages that MOSEK Fusion exist for can be found at


The code examples appearing in this cookbook as well as other supplementary material are available from