Quantitative Finance with Python Chapman & Hall/CRC Financial Mathematics Series Aims and scope: The field of financial mathematics forms an ever-expanding slice of the financial sector. This series aims to capture new developments and summarize what is known over the whole spectrum of this field. It will include a broad range of textbooks, reference works and handbooks that are meant to appeal to both academics and practitioners. The inclusion of numerical code and concrete real-world examples is highly encouraged. Series Editors M.A.H. Dempster Centre for Financial Research Department of Pure Mathematics and Statistics University of Cambridge, UK Dilip B. Madan Robert H. Smith School of Business University of Maryland, USA Rama Cont Department of Mathematics Imperial College, UK Robert A. Jarrow Lynch Professor of Investment Management Johnson Graduate School of Management Cornell University, USA Introductory Mathematical Analysis for Quantitative Finance Daniele Ritelli, Giulia Spaletta Handbook of Financial Risk Management Thierry Roncalli Optional Processes: Stochastic Calculus and Applications Mohamed Abdelghani, Alexander Melnikov Machine Learning for Factor Investing: R Version Guillaume Coqueret, Tony Guida Malliavin Calculus in Finance: Theory and Practice Elisa Alos, David Garcia Lorite Risk Measures and Insurance Solvency Benchmarks: Fixed-Probability Levels in Renewal Risk Models Vsevolod K. Malinovskii Financial Mathematics: A Comprehensive Treatment in Discrete Time, Second Edition Giuseppe Campolieti, Roman N. Makarov Pricing Models of Volatility Products and Exotic Variance Derivatives Yue Kuen Kwok, Wendong Zheng Quantitative Finance with Python A Practical Guide to Investment Management, Trading, and Financial Engineering Chris Kelliher For more information about this series please visit: https://www.crcpress.com/Chapman-and-HallCRC-Financial- Mathematics-Series/book series/CHFINANCMTH Quantitative Finance with Python A Practical Guide to Investment Management, Trading, and Financial Engineering Chris Kelliher First edition published 2022 by CRC Press 6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742 and by CRC Press 4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN © 2022 Chris Kelliher CRC Press is an imprint of Taylor & Francis Group, LLC Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowl- edged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including pho- tocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please contact [email protected] Trademark notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe. Library of Congress Cataloging-in-Publication Data Names: Kelliher, Chris, author. Title: Quantitative finance with Python : a practical guide to investment management, trading, and financial engineering / Chris Kelliher. Description: 1 Edition. | Boca Raton, FL : Chapman & Hall, CRC Press, 2022. | Series: Chapman & Hall/CRC Financial Mathematics series | Includes bibliographical references and index. Identifiers: LCCN 2021056941 (print) | LCCN 2021056942 (ebook) | ISBN 9781032014432 (hardback) | ISBN 9781032019147 (paperback) | ISBN 9781003180975 (ebook) Subjects: LCSH: Investments--Management. | Trading bands (Securities) | Financial engineering. | Python (Computer program language) Classification: LCC HG4515.2 .K445 2022 (print) | LCC HG4515.2 (ebook) | DDC 332.6--dc23/eng/20220113 LC record available at https://lccn.loc.gov/2021056941 LC ebook record available at https://lccn.loc.gov/2021056942 ISBN: 978-1-032-01443-2 (hbk) ISBN: 978-1-032-01914-7 (pbk) ISBN: 978-1-003-18097-5 (ebk) DOI: 10.1201/9781003180975 Typeset in Latin Modern font by KnowledgeWorks Global Ltd. Publisher’s note: This book has been prepared from camera-ready copy provided by the authors. Access the Support Material: www.routledge.com/9781032014432 To my amazing daughter, Sloane, my light and purpose. To my wonderful, loving wife, Andrea, without whom none of my achievements would be possible. To my incredible, supportive parents and sister and brother, Jen and Lucas. Contents Foreword xxxi Author xxxiii Contributors xxxv Acknowledgments xxxvii Section I Foundations of Quant Modeling Chapter 1■ Setting the Stage: Quant Landscape 3 1.1 INTRODUCTION 3 1.2 QUANTFINANCEINSTITUTIONS 4 1.2.1 Sell-Side: Dealers & Market Makers 4 1.2.2 Buy-Side: Asset Managers & Hedge Funds 5 1.2.3 Financial Technology Firms 6 1.3 MOSTCOMMONQUANTCAREERPATHS 6 1.3.1 Buy Side 6 1.3.2 Sell Side 7 1.3.3 Financial Technology 8 1.3.4 What’s Common between Roles? 9 1.4 TYPESOFFINANCIALINSTRUMENTS 9 1.4.1 Equity Instruments 9 1.4.2 Debt Instruments 10 1.4.3 Forwards & Futures 11 1.4.4 Options 12 1.4.5 Option Straddles in Practice 14 1.4.6 Put-Call Parity 14 1.4.7 Swaps 15 1.4.8 Equity Index Total Return Swaps in Practice 17 1.4.9 Over-the-Counter vs. Exchange Traded Products 18 vii viii ■ Contents 1.5 STAGESOFAQUANTPROJECT 18 1.5.1 Data Collection 19 1.5.2 Data Cleaning 19 1.5.3 Model Implementation 19 1.5.4 Model Validation 20 1.6 TRENDS:WHEREISQUANTFINANCEGOING? 20 1.6.1 Automation 20 1.6.2 Rapid Increase of Available Data 20 1.6.3 Commoditization of Factor Premias 21 1.6.4 Movement toward Incorporating Machine Learning/Artificial Intelligence 21 1.6.5 Increasing Prevalence of Required Quant/Technical Skills 22 Chapter 2■ Theoretical Underpinnings of Quant Modeling: Modeling the Risk Neutral Measure 23 2.1 INTRODUCTION 23 2.2 RISKNEUTRALPRICING&NOARBITRAGE 24 2.2.1 Risk Neutral vs. Actual Probabilities 24 2.2.2 Theory of No Arbitrage 25 2.2.3 Complete Markets 26 2.2.4 Risk Neutral Valuation Equation 26 2.2.5 Risk Neutral Discounting, Risk Premia & Stochastic Discount Factors 26 2.3 BINOMIALTREES 27 2.3.1 Discrete vs. Continuous Time Models 27 2.3.2 Scaled Random Walk 28 2.3.3 Discrete Binomial Tree Model 29 2.3.4 Limiting Distribution of Binomial Tree Model 32 2.4 BUILDINGBLOCKSOFSTOCHASTICCALCULUS 33 2.4.1 Deterministic vs. Stochastic Calculus 33 2.4.2 Stochastic Processes 33 2.4.3 Martingales 34 2.4.4 Brownian Motion 34 2.4.5 Properties of Brownian Motion 35 2.5 STOCHASTICDIFFERENTIALEQUATIONS 38 2.5.1 Generic SDE Formulation 38 Contents ■ ix 2.5.2 Bachelier SDE 38 2.5.3 Black-Scholes SDE 39 2.5.4 Stochastic Models in Practice 39 2.6 ITO’SLEMMA 40 2.6.1 General Formulation & Theory 40 2.6.2 Ito in Practice: Risk-Free Bond 41 2.6.3 Ito in Practice: Black-Scholes Dynamics 42 2.7 CONNECTIONBETWEENSDEsANDPDEs 44 2.7.1 PDEs & Stochastic Processes 44 2.7.2 Deriving the Black-Scholes PDE 44 2.7.3 General Formulation: Feynman-Kac Formula 47 2.7.4 Working with PDEs in Practice 48 2.8 GIRSANOV’STHEOREM 48 2.8.1 Change of Measure via Girsanov’s Theorem 48 2.8.2 Applications of Girsanov’s Theorem 50 Chapter 3■ Theoretical Underpinnings of Quant Modeling: Modeling the Physical Measure 51 3.1 INTRODUCTION:FORECASTINGVS.REPLICATION 51 3.2 MARKETEFFICIENCYANDRISKPREMIA 52 3.2.1 Efficient Market Hypothesis 52 3.2.2 Market Anomalies, Behavioral Finance & Risk Premia 53 3.2.3 Risk Premia Example: Selling Insurance 54 3.3 LINEARREGRESSIONMODELS 54 3.3.1 Introduction & Terminology 54 3.3.2 Univariate Linear Regression 56 3.3.3 Multivariate Linear Regression 58 3.3.4 Standard Errors & Significance Tests 59 3.3.5 Assumptions of Linear Regression 62 3.3.6 How are Regression Models used in Practice? 63 3.3.7 RegressionModelsinPractice:CalculatingHigh-YieldBetas to Stocks and Bonds 64 3.4 TIMESERIESMODELS 65 3.4.1 Time Series Data 65 3.4.2 Stationary vs. Non-Stationary Series & Differencing 65 3.4.3 White Noise & Random Walks 66