O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Python for Finance, 2nd Edition

Book Description

The financial industry has recently adopted Python at a tremendous rate, with some of the largest investment banks and hedge funds using it to build core trading and risk management systems. Updated for Python 3, the second edition of this hands-on book helps you get started with the language, guiding developers and quantitative analysts through Python libraries and tools for building financial applications and interactive financial analytics.

Using practical examples throughout the book, author Yves Hilpisch also shows you how to develop a full-fledged framework for Monte Carlo simulation-based derivatives and risk analytics, based on a large, realistic case study. Much of the book uses interactive IPython Notebooks.

Table of Contents

  1. I. Python and Finance
  2. 1. Why Python for Finance?
    1. What Is Python?
      1. Brief History of Python
      2. The Python Ecosystem
      3. Python User Spectrum
      4. The Scientific Stack
    2. Technology in Finance
      1. Technology Spending
      2. Technology as Enabler
      3. Technology and Talent as Barriers to Entry
      4. Ever-Increasing Speeds, Frequencies, Data Volumes
      5. The Rise of Real-Time Analytics
    3. Python for Finance
      1. Finance and Python Syntax
      2. Efficiency and Productivity Through Python
      3. From Prototyping to Production
    4. AI-First Finance
      1. Data Availability
      2. Machine & Deep Learning
      3. Traditional vs. AI-First Finance
    5. Conclusions
    6. Further Reading
  3. 2. Python Infrastructure
    1. Introduction
    2. Conda as a Package Manager
      1. Installing Miniconda 3.6
      2. Basic Operations with Conda
    3. Conda as a Virtual Environment Manager
    4. Using Docker Containerization
      1. Docker Images and Containers
      2. Building an Ubuntu & Python Docker Image
    5. Using Cloud Instances
      1. RSA Public and Private Keys
      2. Jupyter Notebook Configuration File
      3. Installation Script for Python and Jupyter Notebook
      4. Script to Orchestrate the Droplet Set-up
    6. Conclusions
    7. Further Resources
  4. II. Mastering the Basics
  5. 3. Data Types and Structures
    1. Introduction
    2. Basic Data Types
      1. Integers
      2. Floats
      3. Boolean
      4. Strings
      5. Excursion: Printing and String Replacements
      6. Excursion: Regular Expressions
    3. Basic Data Structures
      1. Tuples
      2. Lists
      3. Excursion: Control Structures
      4. Excursion: Functional Programming
      5. Dicts
      6. Sets
    4. Conclusions
    5. Further Resources
  6. 4. Numerical Computing with NumPy
    1. Introduction
    2. Arrays of Data
      1. Arrays with Python Lists
      2. The Python Array Class
    3. Regular NumPy Arrays
      1. The Basics
      2. Multiple Dimensions
      3. Meta-Information
      4. Reshaping and Resizing
      5. Boolean Arrays
      6. Speed Comparison
    4. Structured NumPy Arrays
    5. Vectorization of Code
      1. Basic Vectorization
      2. Memory Layout
    6. Conclusions
    7. Further Resources
  7. 5. Data Analysis with pandas
    1. Introduction
    2. DataFrame Class
      1. First Steps with DataFrame Class
      2. Second Steps with DataFrame Class
    3. Basic Analytics
    4. Basic Visualization
    5. Series Class
    6. GroupBy Operations
    7. Complex Selection
    8. Concatenation, Joining and Merging
      1. Concatenation
      2. Joining
      3. Merging
    9. Performance Aspects
    10. Conclusions
    11. Further Reading
  8. 6. Object Orientated Programming
    1. Introduction
    2. A Look at Python Objects
      1. int
      2. list
      3. ndarray
      4. DataFrame
    3. Basics of Python Classes
    4. Python Data Model
    5. Conclusions
    6. Further Resources
    7. Python Codes
      1. Vector Class
  9. 7. Data Visualization
    1. Static 2D Plotting
      1. One-Dimensional Data Set
      2. Two-Dimensional Data Set
      3. Other Plot Styles
    2. Static 3D Plotting
    3. Interactive 2D Plotting
      1. Basic Plots
      2. Financial Plots
    4. Conclusions
    5. Further Reading
  10. 8. Financial Time Series
    1. Financial Data
      1. Data Import
      2. Summary Statistics
      3. Changes over Time
      4. Resampling
    2. Rolling Statistics
      1. An Overview
      2. A Technical Analysis Example
    3. Correlation Analysis
      1. The Data
      2. Logarithmic Returns
      3. OLS Regression
      4. Correlation
    4. High Frequency Data
    5. Conclusions
    6. Further Reading
  11. 9. Input/Output Operations
    1. Basic I/O with Python
      1. Writing Objects to Disk
      2. Reading and Writing Text Files
      3. SQL Database
      4. Writing and Reading NumPy Arrays
    2. I/O with pandas
      1. SQL Database
      2. From SQL to pandas
      3. Data as CSV File
      4. Data as Excel File
    3. Fast I/O with PyTables
      1. Working with Tables
      2. Working with Compressed Tables
      3. Working with Arrays
      4. Out-of-Memory Computations
    4. I/O with TsTables
      1. Sample Data
      2. Data Storage
      3. Data Retrieval
    5. Conclusions
    6. Further Reading