Python Programming in Finance

Location: Room 223B, 德田館
Time: 1900 ~ 2200


``All money is a matter of belief.''
-- Adam Smith

``Money often costs too much.''
-- Ralph Waldo Emerson

``In the business world, the rearview mirror is
always clearer than the windshield.''
-- Warren Buffett

Instructor Information

Recording Classroom Lectures Policy Recording of classroom lectures is prohibited unless advance written permission is obtained from the class instructor and any guest presenter(s).

Wi-Fi Access

Objectives

This course is an inter-disciplinary course in the fields of computer science, finance, and (a lot of) math:

These techniques are essential both in P & Q quant. Just for the record, this course is not to teach you how to get rich in your life but get rich in knowledge (such that you may get rich in the future).

Prerequisites

Overview

Python crash course

Data acquisition & visualization

Mathematical tools

Modern portfolio theory

Financial time series analysis

Pricing theory

Risk management

Machine learning

Misc

Wish list

Schedule [ 298, 300, 305, 310, 312, 319, 325 ]

Date Summary
2020.2.5 notebook
  • Syllabus
  • Coding platform
  • Programming basics
    • Lecture slides: lecture1.pdf
    • Variables and naming
    • Simple data types (float, str, bool)
    • Arithmetic operators (+,-, *, /, //, %, **), assignment operator (=), rational operators (<, <=, ==, >, >=, !=), logical operators (and, or, not)
    • Built-in data structures: list, dictionary, tuple
    • Branching (if-elif-else)
    • Iteration (for, while)
    • Application: Monte Carlo simulation with random number generator, bisection method for root-finding
2020.2.8 no class due to personal excuse
2020.2.12 notebook
  • Programming basics (cont'd)
    • Flow controls
      • Jump statements (break, continue, pass)
      • Looping techniques: enumerate, zip, reverse, sorted
      • Comprehensions
    • Functions
      • User-defined function
      • Variable scope
      • Default arguments
      • Positional & keyword arguments
      • Lambda expressions
      • Functional programming (map, filter)
      • Advanced usage: iterator (next) & generator (yield)
    • Object-oriented programming
      • class & object
      • Applications: string, file i/o (with-as), date & time, exceptions (try-except-else-finally)
2020.2.15 notebook
  • Data acquisition, visualization & backtesting
    • Customized data crawlers (or you can buy financial data from those famous information suppliers)
    • High-level data structure: Dataframe of Pandas
    • Another package based on Pandas: financial functions for Python (ffn)
    • Plotting: matplotlib, seaborn, mpl_finance, pygal, bokeh
    • Signal generation: technical analysis using ta
    • Backtesting
2020.2.19
  • (FYR) Jake VanderPlas, Python's data science stack, 2016
  • Numerical & scientific packages: numpy & scipy
    • Lecture notebook: pyf_math.ipynb
    • Vectorization
    • Matrix computation
    • Interpolation
    • Optimization
    • Statistics
    • Regression (by using statsmodels)
2020.2.22
2020.2.26
  • Financial time series analysis
    • Lecture notebook: pyf_financial_time_series_analysis.ipynb
    • Autocorrelation
    • Stationaryness
    • Autoregressive moving-average (ARMA) model
    • Generalized autoregressive conditional heteroskedasticity (GARCH) model
    • Vector autoregression (VAR) model
    • Cointegrated VAR using vector error correction (VEC) model
    • Granger causality
2020.3.4
  • Pricing theory
    • Lecture slides: lecture6.pdf
    • Lecture notebook: pyf_pricing_theory.ipynb
    • Arbitrage-free principle
    • Complete market
    • Valuation framework: fundamental theorem of asset pricing
    • Binomial option pricing model (BOPM)
    • Stochastic calculus: Wiener process & Ito's formula
    • Random walk: Brownian motion
    • Black-Schole formula
    • Monte Carlo simulation
      • Euorpean options
2020.3.7
  • Pricing theory (cont'd)
    • Monte Carlo simulation (cont'd)
      • American options using least-square Monte Carlo (LSM)
    • More stochastic processes & simulation
      • Mean-reverting process: CIR model
      • Stochastic volatility model: Heston model
      • Jump-diffusion process: Merton's model
    • QuantLib tutorial
    • Model calibration
  • Risk management
2020.3.11
  • Risk management (cont'd)
    • Sensitivity analysis: Greeks
    • Dynamic hedging
  • Machine learning tutorial
    • Lecture notebook: pyf_machine_learning_tutorial_1.ipynb
    • Regression with regularization: ridge regression & LASSO regression
    • Logistic regression
    • Support vector machine (SVM)
    • Decision tree and random forest
2020.3.14
  • Machine learning tutorial
    • Principal component analysis (PCA)
    • K-means clustering
    • Reinforcement learning: Q-learning
    • Lecture notebook: pyf_machine_learning_tutorial_2.ipynb
    • Recurrent neural network (RNN)
    • Long-short term memory (LSTM) model
  • Performance issues
    • Lecture notebook: pyf_misc.ipynb
    • Row major vs. column major
    • Performance profiling
    • Multiprocessing/multithreading and Amdahl's law
    • Dynamic compiling
  • TODO
    • Cointegration: change API to vecm
    • Corrected MC simulation for square-root process
    • Write lecture slides
    • Organize the contents of machine learning
    • Reorganize all notebooks and slides by topics (one notebook for one topic)

Notebooks

Gradebook

References

Python programming

Finance

Mathematics

Machine learning

Blockchain

Misc