ebook img

Python for Finance PDF

408 Pages·2014·4.546 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Python for Finance

Python for Finance Build real-life Python applications for quantitative finance and financial engineering Yuxing Yan BIRMINGHAM - MUMBAI Python for Finance Copyright © 2014 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: April 2014 Production Reference: 1180414 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78328-437-5 www.packtpub.com Cover Image by Aniket Sawant ([email protected]) Credits Author Project Coordinator Yuxing Yan Swati Kumari Reviewers Proofreaders Mourad MOURAFIQ Simran Bhogal Loucas Papayiannis Maria Gould Jiri Pik Ameesha Green Paul Hindle Commissioning Editor Joanna McMahon Usha Iyer Indexers Acquisition Editors Mehreen Deshkmukh Pramila Balan Monica Ajmera Mehta Llewellyn Rozario Rekha Nair Content Development Editor Tejal Soni Ruchita Bhansali Priya Subramani Technical Editors Graphics Shubhangi Dhamgaye Abhinash Sahu Krishnaveni Haridas Production Coordinator Arwa Manasawala Aditi Gajjar Patel Ankita Thakur Cover Work Copy Editors Aditi Gajjar Patel Roshni Banerjee Sarang Chari Adithi Shetty About the Author Yuxing Yan graduated from McGill university with a PhD in finance. He has taught various finance courses, such as Financial Modeling, Options and Futures, Portfolio Theory, Quantitative Financial Analysis, Corporate Finance, and Introduction to Financial Databases to undergraduate and graduate students at seven universities: two in Canada, one in Singapore, and four in the USA. Dr. Yan has actively done research with several publications in Journal of Accounting and Finance, Journal of Banking and Finance, Journal of Empirical Finance, Real Estate Review, Pacific Basin Finance Journal, Applied Financial Economics, and Annals of Operations Research. For example, his latest publication, co-authored with Shaojun Zhang, will appear in the Journal of Banking and Finance in 2014. His research areas include investment, market microstructure, and open source finance. He is proficient at several computer languages such as SAS, R, MATLAB, C, and Python. From 2003 to 2010, he worked as a technical director at Wharton Research Data Services (WRDS), where he debugged several hundred computer programs related to research for WRDS users. After that, he returned to teaching in 2010 and introduced R into several quantitative courses at two universities. Based on lecture notes, he has the first draft of an unpublished manuscript titled Financial Modeling using R. In addition, he is an expert on financial data. While teaching at NTU in Singapore, he offered a course called Introduction to Financial Databases to doctoral students. While working at WRDS, he answered numerous questions related to financial databases and helped update CRSP, Compustat, IBES, and TAQ (NYSE high-frequency database). In 2007, Dr. Yan and S.W. Zhu (his co-author) published a book titled Financial Databases, Shiwu Zhu and Yuxing Yan, Tsinghua University Press. Currently, he spends considerable time and effort on public financial data. If you have any queries, you can always contact him at [email protected]. Acknowledgments I would like to thank Ben Amoako-Adu, Brian Smith (who taught me the first two finance courses and offered unstinting support for many years after my graduation), George Athanassakos (one of his assignments "forced" me to learn C), Jin-Chun Duan, Wei-Hung Mao, Jerome Detemple, Bill Sealey, Chris Jacobs, Mo Chaudhury (my former professors at McGill), and Laurence Kryzanowski. (His wonderful teaching inspired me to concentrate on empirical finance and he edited my doctoral thesis word by word even though he was not my supervisor!) There is no doubt that my experience at Wharton has shaped my thinking and enhanced my skill sets. I thank Chris Schull and Michael Boldin for offering me the job; Mark Keintz, Dong Xu, Steven Crispi, and Dave Robinson, my former colleagues, who helped me greatly during my first two years at Wharton; and Eric Zhu, Paul Ratnaraj, Premal Vora, Shuguang Zhang, Michelle Duan, Nicholle Mcniece, Russ Ney, Robin Nussbaum-Gold, and Mireia Gine for all their help. In addition, I'd like to thank Shaobo Ji, Tong Yu, Shaoming Huang, Xing Zhang, Changwen Miao, Karyl Leggio, Lisa Fairchild, K. G. Viswanathan, Na Wang, Mark Lennon, and Qiyu (Jason) Zhang for helping me in many ways. I also want to thank Shaojun Zhang and Qian Sun, my former colleagues and co-authors on several papers, for their valuable input and discussions. Creating a good book involves many talented publishing professionals and external reviewers in addition to the author(s). I would like to acknowledge the excellent efforts and input from the staff of my publisher, Packt Publishing, especially Llewellyn F. Rozario, Swati Kumari, Arwa Manasawala, Ruchita Bhansali, Apeksha Chitnis, and Pramila Balan as well as the external reviewers, Martin Olveyra, Mourad MOURAFIQ, and Loucas Parayiannis, for their valuable advice, suggestions, and criticism. Finally, and most importantly, I thank my wife, Xiaoning Jin, for her strong support, my daughter, Jing Yan, and son, James Yan, for their understanding and love they have showered on me over the years. About the Reviewers Jiri Pik is a finance and business intelligence consultant working with major investment banks, hedge funds, and other financial players. He has architected and delivered breakthrough trading, portfolio and risk management systems, and decision-support systems across industries. His consulting firm, WIXESYS, provides their clients with certified expertise, judgment, and execution at the speed of light. WIXESYS' power tools include revolutionary Excel and Outlook add-ons available at http://spearian.com. Loucas Papayiannis was born and raised in Cyprus, where he graduated from the English School in Nicosia. After completing his mandatory military service at the Cyprus National Guard, Loucas left for the University of California, Berkeley, where he obtained a BSc in Electrical Engineering and Computer Science. While at Berkeley, he had the opportunity to work for the Bosch Research Center in Palo Alto, where he developed a strong interest in computer-human interface. In an unexpected turn of events, an opportunity to work for Bloomberg LP in London came up, after he completed his studies. Despite the fact that financial software was a sharp change of direction from where Loucas was heading at the time, he moved to London and seized the opportunity. He quickly grew to enjoy this new field and consequently enrolled in an MSc program in Financial Mathematics at King's College, London while still working full time, completing this degree in 2011. In 2010, he started at Goldman Sachs, and in August 2012, he joined Barclays Capital, where he is currently employed. His work is focused on developing an FX Options application, and he mainly works with C++. However, he has worked with a variety of languages and technologies through the years. He is a Linux and Python enthusiast and spends his free time experimenting and developing applications with them. Mourad MOURAFIQ is a software engineer and data scientist. After successfully completing his studies in Applied Mathematics, he worked at an investment bank as a quantitative modeler in the structured products market, specializing in ABS, CDO, and CDS. Then, he worked as a quantitative analyst for the largest French bank. After a couple of years in the financial world, he discovered a passion for machine learning and computational mathematics and decided to join a start-up that specializes in software mining and artificial intelligence. I would like to thank my mentors who took me under their wings during my initial days on the trading floor. www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@ packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Introduction and Installation of Python 9 Introduction to Python 10 Installing Python 12 Different versions of Python 12 Ways to launch Python 13 Launching Python with GUI 13 Launching Python from the Python command line 14 Launching Python from our own DOS window 15 Quitting Python 16 Error messages 16 Python language is case sensitive 17 Initializing the variable 17 Finding the help window 18 Finding manuals and tutorials 19 Finding the version of Python 21 Summary 21 Exercises 22 Chapter 2: Using Python as an Ordinary Calculator 23 Assigning values to variables 24 Displaying the value of a variable 24 Error messages 24 Can't call a variable without assignment 25 Choosing meaningful names 25 Using dir() to find variables and functions 26 Deleting or unsigning a variable 27

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.