Lecture notes and Python code written during the course Python Lab in the Maters’ degree in Finance and Quantitative Methods for Economics at the University of Perugia.
7 practical lectures of 3h each, and 1 final exercise session of 2h.
-
Lecture 1 - March 6, 2024 (3h): Introduction to Python. The Anaconda distribution. Variables and assignments. Input and print functions. Introduction to control statements: if, if-else, if-elif-else, while, for. Use of control statements: if, if-else, if-elif-else, while, for.
-
Lecture 2 (Part 1) - March 14, 2024 (2h): The statistics and random libraries. The max and min built-in functions. Introduction to Matplotlib: bar charts. Lists and tuples.
-
Lecture 2 (Part 2) - March 15, 2024 (1h): Definition of custom functions. Global and local variables. Computation of definite integrals through NumPy and SciPy libraries. Plot of functions with Matplotlib. Computation of expected utilities.
-
Lecture 3 - March 21, 2024 (3h): Expected utility maximization. Plots of multiple functions with Matplotlib. One-dimensional arrays with NumPy: creations and operations. Two-dimensional arrays with NumPy: creations and operations. Linear algebra with NumPy: submatrices, determinant of a matrix, inverse matrix, rank of a matrix.
-
Lecture 4 - March 27, 2024 (3h): Solution of a linear system with a square matrix. No-arbitrage pricing via a replicating portfolio. Use of NumPy in pricing and hedging. The binomial market model: completeness, pricing, replication scatter plot. The trinomial market model: incompleteness, replication 3D scatter plot, best hedge via MSE minimization.
-
Lecture 5 - April 24, 2024 (3h): Recap on Python's collections: a glimpse of sets and dictionaries. Pandas library: Series and DataFrames. Reading and writing csv files. Analysis of correlation and linear regression of asset prices (equity and cryptocurrencies). The yfinance library. Computation of stock log-returns and historical volatility.
-
Lecture 6 - May 8, 2024 (3h): Testing normality of log-returns: histogram; Q-Q plot with statsmodel.api; skew, kurtosis and normality test with scipy.stats. Computation of the value at risk for a single stock portfolio: non-parametric estimation and parametric estimation (normality assumption). Direct loading of a portfolio of historical prices with yfinance.
-
Lecture 7 - May 15, 2024 (3h): Value at risk of a portfolio with the variance-covariance method (normality assumption). Option pricing under Black-Scholes assumptions: BS formula; Monte Carlo pricing; integral pricing. The lognormal distribution. Adding columns and row-wise computations through apply in a DataFrame. MAE and RMSE. The bivariate normal density.
-
Exercise Session - May 22, 2024 (2h): In-class exercises.