MATLAB MEX Function Reference

This is a listing of some of my MATLAB MEX files written in C language which might interest people working with econometrics or on quantitative macroeconomics theory.
These programs were developed for economists Dr. Marco Del Negro and Dr. Tao Zha during my research assistantship at the Federal Reserve Bank of Atlanta.
Follow the links to compiled binaries and source codes to download them to your computer.

Iskander Karibzhanov, March 24, 2007
E-mail: karib003@umn.edu


The Kalman Filter (kalcvf.dll)
The Kalman filter is one of the computational techniques used by applied economists necessary to implement Bayesian methods
when doing empirical work. It provides a tool for dealing with state space models to analyze economic and financial time series
of not only correlated its past values but also contemporaneously correlated each other and each other's past values.
You can develop a model of the univariate or multivariate time series and the relationships between the vector time series.
The program computes the one-step prediction and the filtered estimate, as well as their covariance matrices.
The function uses forward recursions, and you can also use it to obtain k-step forecasts.

Overview of Kalman Filter Functions
Getting Started with State Space Models
KALCVF performs covariance filtering and prediction
KALCVS performs fixed-interval smoothing
Kalman Filtering Example 1: Likelihood Function Evaluation
Kalman Filtering Example 2: Estimating an SSM Using the EM Algorithm
Download compiled mex-programs: kalcvf.dll (for Windows) or kalcvf.mexglx (for Linux)
(kalcvs function is presently available only in the form of M-file - see below)
If you are using old version of MATLAB v6.1 Release 12, you may have to copy msvcr70.dll
to your C:\WINDOWS\system32 directory (do not replace the file if it already exists).
This file is required because program was compiled under Microsoft Visual Studio .NET.
Download translated Kalman examples in MATLAB's M scripts: kalex1.m and kalex2.m
Download original Kalman examples in SAS/IML language: kalex1.sas and kalex2.sas
Download C source codes of MEX-files: kalcvf.c and kalcvs.c
NOTE: you will need C source codes in case compiled MEX-files do not run on your computer.
To compile use "mex filename.c" on Linux or "mex filename.c $MATLAB\extern\lib\win32\$CC\libmwlapack.lib" on PC,
where $MATLAB denotes your MATLAB installation directory (e.g. C:\MATLAB6p5 or C:\MATLAB6p1) and
$CC denotes your C compiler chosen after running "mex -setup" (e.g. lcc, microsoft\msvc60, borland, etc.).
Download M analogies of MEX-files: kalcvf.m and kalcvs.m
NOTE: these M functions work as described, but are inefficient since written in MATLAB language
and not intended for production purposes. They do not necessarily replicate the exact algorithm of MEX files.

Solving Linear Rational Expectations Models (gensys.dll)
C implementation of Chris Sims' solution algorithm for Linear Rational Expectations Models.
The program is based on the Intel Math Kernel Library which provides routines for a complex QZ
(generalized Schur) decomposition. (Note: the LAPACK ZGGES routine has advantage over MATLAB's
qz built-in function by giving possibility of ordering the eigenvalues so that a selected cluster of
eigenvalues appears in the leading diagonal blocks of the upper triangular complex output matrices.
Therefore, the algorithm of qzdiv.m and qzswitch.m functions was not neccessary to write gensys program.)
You will need to copy dynamic link libraries mkl_lapack64.dll and libguide40.dll to your
$MATLAB\bin\win32 directory, where $MATLAB denotes your MATLAB installation directory
(e.g. C:\MATLAB6p5 or C:\MATLAB6p1). If you are using old version of MATLAB v6.1 Release 12,
you may have to copy msvcr70.dll to your C:\WINDOWS\system32 directory (do not replace the file if it
already exists). This file is required because program was compiled under Microsoft Visual Studio .NET.
The program analyzes linear rational expectations systems and returns solutions for their dependence on
exogenous disturbances. The systems need not have non-singular lead matrices (coefficients on current
variables in discrete time) and they need not be well-specified. The program analyzes them to determine
whether solutions exist and whether they are unique. It returns a solution even when it is not unique, and it
returns a solution that constrains exogenous variable behavior when no solution that does not do so exists.
Only discrete time program is currently available.
View manual UsingGensys.pdf
Download program gensys.dll
Download source code gensys.c

Unconstrained Minimization Algorithm (csminwel.dll)
C implementation of Chris Sims' robust optimization algorithm commonly used to maximize likelihood function.
The program is based on a gradient quasi-Newton method with BFGS update of the estimated inverse Hessian.
It is robust against certain pathologies common on likelihood functions and attempts to be robust against "cliffs",
i.e. hyperplane discontinuities, though it is not really clear whether what it does in such cases succeeds reliably.
If no analytic gradient is supplied, the program uses crude numerical derivative. Beware of this or any other
numerical derivative on large or ill-conditioned problems. The algorithm tries random search directions if things
look bad and will not get stuck at a flat spot in the sum of deviations objective function that is not a solution.
Download program csminwel.dll
Download source code csminwel.c