Python for Finance
by Yves Hilpisch
Copyright 2019 Yves Hilpisch. All rights reserved.
Printed in Canada.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
Editors: Susan Conant and Jeff Bleiel | Indexer: Judith McConville |
Production Editor: Kristen Brown | Interior Designer: David Futato |
Copyeditor: Rachel Head | Cover Designer: Karen Montgomery |
Proofreader: Kim Cofer | Illustrator: Rebecca Demarest |
- December 2014: First Edition
- December 2018: Second Edition
Revision History for the Second Edition
- 2018-11-29: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781492024330 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Python for Finance, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the author, and do not represent the publishers views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-492-02433-0
[MBP]
Preface
These days, Python is undoubtedly one of the major strategic technology platforms in the financial industry. When I started writing the first edition of this book in 2013, I still had many conversations and presentations in which I argued relentlessly for Pythons competitive advantages in finance over other languages and platforms. Toward the end of 2018, this is not a question anymore: financial institutions around the world now simply try to make the best use of Python and its powerful ecosystem of data analysis, visualization, and machine learning packages.
Beyond the realm of finance, Python is also often the language of choice in introductory programming courses, such as in computer science programs. Beyond its readable syntax and multiparadigm approach, a major reason for this is that Python has also become a first class citizen in the areas of artificial intelligence (AI), machine learning (ML), and deep learning (DL). Many of the most popular packages and libraries in these areas are either written directly in Python (such as scikit-learn
for ML) or have Python wrappers available (such as TensorFlow
for DL).
Finance itself is entering a new era, and two major forces are driving this evolution. The first is the programmatic access to basically all the financial data available in general, this happens in real time and is what leads to data-driven finance. Decades ago, most trading or investment decisions were driven by what traders and portfolio managers could read in the newspaper or learn through personal conversations. Then came terminals that brought financial data in real time to the traders and portfolio managers desks via computers and electronic communication. Today, individuals (or teams) can no longer keep up with the vast amounts of financial data generated in even a single minute. Only machines, with their ever-increasing processing speeds and computational power, can keep up with the volume and velocity of financial data. This means, among other things, that most of todays global equities trading volume is driven by algorithms and computers rather than by human traders.
The second major force is the increasing importance of AI in finance. More and more financial institutions try to capitalize on ML and DL algorithms to improve operations and their trading and investment performances. At the beginning of 2018, the first dedicated book on financial machine learning was published, which underscores this trend. Without a doubt, there are more to come. This leads to what might be called AI-first finance, where flexible, parameterizable ML and DL algorithms replace traditional financial theory theory that might be elegant but no longer very useful in the new era of data-driven, AI-first finance.
Python is the right programming language and ecosystem to tackle the challenges of this era of finance. Although this book covers basic ML algorithms for unsupervised and supervised learning (as well as deep neural networks, for instance), the focus is on Pythons data processing and analysis capabilities. To fully account for the importance of AI in finance now and in the future another book-length treatment is necessary. However, most of the AI, ML, and DL techniques require such large amounts of data that mastering data-driven finance should come first anyway.
This second edition of Python for Finance is more of an upgrade than an update. For example, it adds a complete part () where fundamental Python programming and data analysis topics are presented before they are applied in later parts of the book. On the other hand, some chapters from the first edition have been deleted completely. For instance, the chapter on web techniques and packages (such as Flask
) was dropped because there are more dedicated and focused books about such topics available today.
For the second edition, I tried to cover even more finance-related topics and to focus on Python techniques that are particularly useful for financial data science, algorithmic trading, and computational finance. As in the first edition, the approach is a practical one, in that implementation and illustration come before theoretical details and I generally focus on the big picture rather than the most arcane parameterization options of a certain class, method, or function.
Having described the basic approach for the second edition, it is worth emphasizing that this book is neither an introduction to Python programming nor to finance in general. A vast number of excellent resources are available for both. This book is located at the intersection of these two exciting fields, and assumes that the reader has some background in programming (not necessarily Python) as well as in finance. Such readers learn how to apply Python and its ecosystem to the financial domain.
The Jupyter Notebooks and codes accompanying this book can be accessed and executed via our Quant Platform. You can sign up for free at http://py4fi.pqp.io.
My company (The Python Quants) and myself provide many more resources to master Python for financial data science, artificial intelligence, algorithmic trading, and computational finance. You can start by visiting the following sites:
- Our company website
- My private website
- Our Python books website
- Our online training website
- The Certificate Program website
From all the offerings that we have created over the last few years, I am most proud of our