Python for Finance

Table of Contents

A couple notes:

Module 0: Introduction and Setup

Week 0

Session Video

  • Course Overview:
    • What we will cover in the course.
    • The use of Python in finance.
  • Python Relative to other tools.
    • Excel
    • Other Programming Languages
    • Comparison with R
    • Using Javascript for Visualization

Week 1

Session Video (Part 1) Colab Notebooks and Basic Arithmetic

Session Video (Part 2) Defining Functions and Data Types

Exercise Solution Video

Colab Notebook

  • Interacting with Python
    • Google's Colab and Jupyter
      • Introduction to markdown
      • Sharing notebooks
  • Intro to the Linux Server
  • Creating Functions and Time-Value-of-Money calculations
  • Basic control flow
  • The importance of indentation

Week 2

Session Video

Exercise Solution Video

Colab Notebook

  • Sharing code and the Python ecosystem.
  • Python Packages
    • Extending the core language
    • Our most used packages.
    • Installing and Loading.
    • How to call methods/functions from a package.
    • Package security.

Module 1: Pandas and Spreadsheet (tabular) Data

This module focuses on corporate finance related tasks. Accordingly we read data from spreadsheet and Dataframe structures.

Week 3

Exercise: Is there a correlation between industry institutional ownership and return on equity?

  • An intro to Pandas
  • Reading csv and excel files over http.
  • Data cleaning.
  • Inspecting the objects
  • Determining dataframe size and the column types.
  • Adding new columns
  • A note of functions vs methods.

Week 4

Exercise: What is the average on and off-peak real-time fuel mix?

  • Dates in Pandas.
  • Interacting with the operating system from Python.
  • Summarizing by creating group means, etc.

Week 5

Exercise: Where were the PPP loans made?

  • Filtering DataFrames
  • Pivot Tables

Week 6

Colab Notebook

The previous sections have used data available online through APIs and flat files. Commonly the financial analyst will have to query relational (SQL) databases. In this section we'll cover the basics of connecting to a SQL database in Python, and executing SQL queries, and returning the data as a Pandas DataFrame.

Module 2: Numpy/Scipy and APIs

This module focuses on using scientific computing libraries such as Numpy Scipy to complete investments-focused tasks. We also retrieve JSON data from APIs.

Week 7

Colab Notebook

  • An introduction to Application Programming Interfaces (APIs) and online data. Above notebook uses the yfinance package. Additional APIs we can use.
    • Example: Coinbase API
    • Example: Interactive Brokers API
    • EIA API.
  • Connecting to databases.

Exercise: Pull stock data via API and estimate a Markowitz mean-variance optimal portfolio.

Alternative: Calculate futures prices given options (but we cant get this from API data).

Week 8

Old video and notebook. Coinbase API Packages are now broken.

Session Video

Colab Notebook

  • An overview of scipy and basic statistics in Python.
  • Extracting coefficients from an estimated regression model.

Exercise: Calculate market depth via Kyle's lambda. Use Coinbase API to get trades.

Week 9

Exercise: Deposit insurance valuation using (Merton's) option pricing method. (chapter 19, Merton's CTF)

Module 3: Sharing Your Work

This module focuses on showcasing your work via visualizations, sharing code via git and GitHub. We also cover reproducible environments.

Week 10

Colab Notebook

  • Visualization:
    • Matplotlib
    • Seaborn
    • Plotly
    • ggplot (using plotnine library)
  • Interactive Web Apps via Plotly's Dash

Week 11

  • The Integrated Development Environment (IDE)
    • What does an IDE provide?
      • Code Completion
      • Linter
    • Git/Github and IDE Integration
  • Virtual Environments
    • Ensuring compatible python and package versions.
    • Anaconda Python

Week 12

Colab Notebook

  • Git/Github and IDE Integration
    • Why use version control?
      • Collaborate with others more easily.
      • Show others your work.

Bonus Material

Bonus Project: Predict Small Business Loans with a Deep Neural Network in Tensorflow

Bonus Project: Calculate Performance Measures for Various ETFs (Sharpe, Information ratios, etc)

Calculating Greeks for the Margrabe Model

Created: 2024-04-23 Tue 22:15

Validate