Andrew Patton's Matlab Code
This page contains some of the Matlab code I've written during the course of my research. If you find any mistakes or bugs in the code please let me know.
This code is being released under a BSD license, which means that you can do pretty much what ever you want with it, including make money by selling it.
1. James LeSage's Econometrics Toolbox for Matlab
Most of my functions use code contained in the econometrics toolbox for Matlab by James P. LeSage. This toolbox contains many useful programs for econometricians. It must be installed before my code will work.
2. Kevin Sheppard's GARCH Toolbox for MatlabThis toolbox contains many useful functions relating to estimating and simulating both univariate and multivariate GARCH models. Some of my programs call some of Kevin's functions, so this also needs to be installed. The GARCH toolbox can be found here.
3. Code for Hansen's (1994) skewed t distributionThis zip file contains 5 functions: the pdf, cdf, log-likelihood, inverse cdf and a function to generate random draws from the skewed t distribution.
Hansen, Bruce E., 1994, Autoregressive Conditional Density Estimation, International Economic Review, 35(3), 705-730.
This Matlab m-file (saved as a “txt” file) returns an estimate of the optimal block size for bootstrap methods (stationary or circular) of estimating the asymptotic variance of the mean of dependent data, given a sample from a univariate time series.
R code for this procedure, written by Jeff Racine and Chris Parmeter is available here, and a PDF help file is here. Alternatively, if you install R and the “np” package you will have access to the function “b.star”.
Bug fixes and updates:
26aug03: updated with suggestions from Kevin Sheppard.
16dec07: major revision: estimate of optimal block length for the stationary bootstrap corrected using recent paper by Nordman (Annals of Statistics, forthcoming). Details in a “correction” paper available here.
9dec08: fixed small bug in choice of “KN”, thanks to Jeff Racine for spotting this.
28oct09: Here is “mlag.m” (saved as a “txt” file) which is called in my code. (This function is part of the econometrics toolbox for Matlab by James P. LeSage.)
Politis, Dimitris N., and White, Halbert, 2004, Automatic Block-Length Selection for the Dependent Bootstrap, Econometric Reviews, 23(1), 53-70.
Politis, Dimitris N., White, Halbert, and Patton, Andrew J., 2009, Correction: Automatic Block-Length Selection for the Dependent Bootstrap, Econometric Reviews, 28(4), 372-375.
5. Code for computing and testing "exceedence correlations"
This zip file contains code to compute the exceedence correlations used by Longin and Solnik (2001) and Ang and Chen (2002). Code for the test that the exceedence correlation plot is symmetric recently proposed by Hong, Tu and Zhou (2003) is also included. Longin, Francois, and Solnik, Bruno, 2001, Extreme Correlation of International Equity Markets, Journal of Finance, 56, 649-676.
Ang, Andrew, and Chen, Joseph, 2002, Asymmetric Correlations of Equity Portfolios, Journal of Financial Economics, 63(3), 443-494.
Hong, Yongmiao, Tu, Jun, and Zhou, Guofu, 2007, Asymmetries in Stock Returns: Statistical Tests and Economic Evaluation, Review of Financial Studies, 20, 1547-1581.
This zip file contains Matlab code to replicate the empirical section in Patton (2011), on volatility forecast comparison using imperfect volatility proxies. The main program is called "robust_example_code.m", which generates the figures and does the calculations. The data used in the paper is included. The function "robust_loss_1.m" is a function for the parametric family of "robust" loss functions proposed in the paper. Some helper functions are also included.
7. Copula toolbox for Matlab, version 1.07, 5apr08This zip file contains a collection of Matlab functions that I wrote for my research on copulas for financial time series (Patton 2006a, Patton 2006b, Patton 2004, Granger et al. 2006, Patton 2007). Some simple example code is given in "copula_example_code.m". A table of contents is given in "contents.xls". Briefly, the toolbox contains CDFs, PDFs, log-likelihoods and random number generators for many common bivariate copulas, including the Clayton, Gumbel, Normal, Student's t, Frank, Plackett and symmetrised Joe-Clayton (SJC) copulas. Basic code for time-varying Normal, Gumbel and SJC copulas is included. Some helper functions are also included. If you find any bugs in this code please let me know: andrew.patton@economics.ox.ac.uk.Bug fixes:
22aug06: Fixed two small bugs in clayton_pdf.m and tCopula_cdf.m1aug07: Fixed big bug in sym_jc_rnd.m19aug07: Fixed small bug in copula_example_code.m2feb07: Fixed small bug in copula_example_code.m
5feb07: Fixed small bug in copula_example_code.m