Statistical Analysis of Equities using Time Series Models, Regression, the Capital Asset Pricing Model(CAPM), and the Fama French 3-Factor and 5-Factor Models in Python and iPython Notebooks.
I will be taking notes on the Textbook Statistics and Data Analysis for Financial Engineering with R examples, and use it as a reference to learn about financial engineering and translate it into Python code and iPython notebooks.
Textbook Notes: Calculating Returns
This notebook examines the calculation of Net, Gross and Log Returns of an asset, along with how and why they are used. Included is a comparison of 3 semiconductor equities, ADI, AMAT and AMD, as well as a simple time series for each stock's logarithmic returns over a 5-year period.
Textbook Notes: Examining Distributions
Python Exercises: Examining Distributions with Histograms and Kernel Density Estimates
This notebook covers histograms and kernel density estimates for examining sample distributions. Included are histograms and Gaussian KDE's of the semiconductor equity APH, implemented using matplotlib and KDEPy.
Python Exercises: Examining Distributions and Testing for Normality
This notebook covers testing for normality with samples of asset prices: Sample Quantiles, and Tests of Normality including the Shapiro-Wilk Test are some of the functions in this notebook; The plots covered are Box Plots, Normal Probability Plots, Half-Normal Plots, and Quantile-Quantile Plots.
Textbook Notes: Regression Models
This notebook contains notes on Univariate and Multivariate Linear Regression and evaulation of these models, this notebook is a work-in-progress and does not cover all the topics in the chapter yet. This will be completed when the Python Regression Model Scripts are finished.
Python Exercises: Simple Linear Regression Model from Scratch
Python Exercises: Multiple Linear Regression Model from Scratch Using Normal Equations
Equities are a class that creates a Yahoo Finance Ticker to store Stock Data for Analysis as PKL Files.
Portfolios are a class that implements a Collection of Equity Objects to run CAPM and Fama-French Portfolio Analysis.
OLS_SimpleLinearRegression is a superclass for the CAPM and Fama-French Models that contains the multiple linear regression functions and a simple ANOVA table generator.
MultipleLinearRegression is a superclass for the Fama-French Models and estimates the betas using the MLR Model's Normal Equations. ANOVA Tables will be added once the subclasses and Simple Linear Regression Classes are done.
CAPM_Regression is a subclass of OLS_SimpleLinearRegression that overrides the linear regression functions to perform a single-variable linear regression of an asset, and overrides the ANOVA table generator to add CAPM-specific metrics for the stock like Jensen's Alpha.
FF_Regression is a subclass of OLS_SimpleLinearRegression that inherits the multiple linear regression functions of its superclass to run either a 3-factor or 5-factor Fama-French analysis on a Stock, and overrides the ANOVA table generator to add finance-specific metrics for the stock.
Visualizations is a class that handles the visualization of the analysis performed in the regression scripts, and will implement PyGWalker to handle Dashboard creations for a portfolio.
Scripts will be written as/after I finish sections of the textbook, and will focus on Object-Oriented representations of the finance topics covered in the Jupyter/iPython Notebooks
If you are interested in previous projects I have written that cover similar topics, please take a look at:
CAPM and Fama-French Beta Estimation in Jupyter Notebooks
Scraping Data from Yahoo Finance
Visualizing Candle and Financial Statement Data
Ruppert, David and David S. Matteson. Statistics and Data Analysis for Financial Engineering with R examples.
Quantivity. "Why Log Returns?" Quantivity, 21 Feb. 2011, https://quantivity.wordpress.com/2011/02/21/why-log-returns/.
Costan, Julian. "Linear vs. Log Returns." Decentralized Meta-Learning, 14 Sept. 2021, https://blog.costan.ro/post/2021-09-14-linear-log-returns/.
Mathison, Jake. "Kernel Density Estimation." Kernel Density Estimation, n.d., mathisonian.github.io/kde/.
Tommy Odland. Tommyod/kdepy: Kernel Density Estimation in Python. v0.9.10, Zenodo, 18 Dec. 2018, doi:10.5281/zenodo.2392268.
Hudson, Robert and Gregoriou, Andros, Calculating and Comparing Security Returns is Harder than you Think: A Comparison between Logarithmic and Simple Returns (February 7, 2010). Available at SSRN: https://ssrn.com/abstract=1549328
Meucci, Attilio, Quant Nugget 2: Linear vs. Compounded Returns – Common Pitfalls in Portfolio Management (May 1, 2010). GARP Risk Professional, pp. 49-51, April 2010 , Available at SSRN: https://ssrn.com/abstract=1586656