VBA Templates and Financial Models


‘It is a good morning exercise for a research scientist to discard a pet hypothesis every day before breakfast; it keeps him young’

- Konrad Lorenz–

On this page you may find a selection of statistical models, VBA templates and Excel-based financial models. All spreadsheets and applets are available for download. Some templates are not open source but passwords to access the modules in the Visual Basic editor can be obtained via the contact page. Please feel free to comment on your experiences and to suggest improvements to the templates. Please note that some templates are still in a development stage (check status); the author does not take responsibility for any shortcomings or errors in the source code. Bookmark this site to check on updates and new developments regularly. Please note that in Windows 7 files might only be downloadable as .zip. Just open the compressed file in Excel and save as workbook for further use.


Multifactor Linear Regression Modeldownloads: 8198 | type: xlsm | size: 189 kB

Last update: April 2010. The following changes have been implemented:

  • A new algorithm has been introduced to calculate inverse matrices more accurately via the Gauss-Jordan algorithm.
  • The formula can be used to display regression residuals.
  • General Least Squares estimation without constant (intercept at origin) and data labels.
  • Extended version of Errorhandler.

The above template uses matrix algebra to determine regression coefficients, predictions, and confidence intervals. Thus, the function REGOUTPUT() is not subject to the limitations of the Excel-inherent Linest()-Function / Matrix-Functions. In addition, the template provides extensive regression diagnostics: test for collinearity of consecutive error terms, normality, and goodness of fit.

Stepwise Regression Modeldownloads: 3800 | type: xlsm | size: 211 kB

This model uses a forward stepwise regression algorithm to select predictor variables from a range of parameters. The input parameters include the level of tolerance, F-to-leave and F-to-enter. The maximum number of iterations is set to 1000 but can be changed manually in the source code (please inquire about the password first). The output parameters are identical to the multiple factor regression model.

Advanced Regressiondownloads: 4188 | type: xlsm | size: 229 kB

This model allows for different calculations of coefficient standard error estimates in time series regression:

  • Standard OLS estimate assuming constant variance.
  • White standard error estimate.
  • GMM standard errors and Newey-West estimate (weighted according to Bartlett kernel).

Lag truncation for Newey-West estimates may be specified separately. 

Constrained Multifactor Pricing Modelsdownloads: 3504 | type: xlsm | size: 67 kB

In accordance with the Sharpe Multifactor Pricing models, the above routine calculates the coefficient estimates for a number of regressors based on the assumption that the sum of coefficients = 1. This allows for a more meaningful interpretation of the factor loadings. The spreadsheet uses an example estimating the performance of a hedge fund from five input parameters.

Durbin Watson testdownloads: 3023 | type: xlsm | size: 192 kB

This spreadsheet calculates the Durbin-Watson test statictic for serial correlation based on a single factor regression model. In addition, it returns the critical lower and upper limits from the Durbin-Watson tables (for up to n = 200 observations and k = 20 regressors). Please refer to the multifactor models above when testing for serial correlations in residuals with k > 2 (more than one regressor).

Testing for Normalitydownloads: 2929 | type: xlsm | size: 109 kB

Data series can be tested for normality using either the non-parametric Chi-Squared Test for Normality or the Jarque-Bera statistic. The latter uses the third and fourth moment of the distribution (also referred to as skew and kurtosis). Some series are found to be more sensitive to one or the other test statistic.

Downside Riskdownloads: 4073 | type: xlsm | size: 31 kB

This spreadsheet provides macros to calculate a number of downside risk measures including maximum continuous drawdown, semi-deviation and Value-at-Risk. Some of the code snippets were downloaded from http://www.andreassteiner.net and altered to expressing the sub-period returns as (1 + Rt, t + 1) to account for compounding effects, where Rt, t + 1 is the perentage return between t and time t + 1.

T-test for equal means (paired or random)downloads: 2119 | type: xlsm | size: 31 kB

This simple algorithm compares two time series on the basis of the t-test for equal means. The input options for the experimental designs are: paired vs random and one-tail vs two-tail. Testing for equality of sample variances is conducted via the F-test. All templates are function-based.

Tests For Autocorrelationdownloads: 3396 | type: xlsm | size: 272 kB

The macro calculates the autocorrelation coefficients and partial autocorrelation coefficients of order k of any time series. In addition, it uses the Breusch-Godfrey LM test to detect autocorrelation at distinct lags. The Durbin-Watson test and Durbin h test for ARMA-Models may be used to identify serial correlation among consecutive residuals in linear regression. All tests function-based.

Unit Root testdownloads: 3728 | type: xlsm | size: 258 kB

The unit root test is conducted as an augmented Dickey Fuller test. The test accounts for first differences (extension of model follows shortly), intercept and appropriate lags. The p-value is calculated from Dickey Fuller tables of critical values included in the macro and approximated via linear interpolation. The statistic is function-based.

Unit Root tests - Extended Versiondownloads: 3862 | type: xlsm | size: 328 kB

Allows for a number of unit root tests including Dickey-Fuller, Augmented-Dickey-Fuller (ADF) and Phillips-Perron (PP). The last test statistic uses the heteroskedasticity-autocorrelation-consistent (HAC) error variance estimator of Newey and West (with Bartlett kernel). The following specifications can be made with respect to the test regression: differences considered, intercept and trend line included, lags considered and type of error estimation. The signficance of the AR[p]-processes is determined according to the Akaike Information Criterion (AIC). The maximum number of lags follows from Schwartz (if not specified otherwise). The spreadsheet also includes McKinnon critical values for the ADF-tests as well as Engle-Granger. You may use the CommandButton in Worksheet "AR(1)-Process" to generate AR[1]-Processes.  

Dickey Fuller critical values (Simulation)downloads: 2604 | type: xlsm | size: 117 kB

This VBA script uses Monte Carlo to simulate critical values for the Dickey Fuller test statistic from many replications of random walks (with or without intercept/trend). The user may specify the sample size, confidence level as well as the number of replications. An excerpt from the original DF-tables is included for comparison.

ANOVAdownloads: 2156 | type: xlsm | size: 273 kB

The following changes have been made as of March 2010:

  • Errors occuring with unbalanced ANOVA problems where the number of treatments is larger then 6 (e.g. n * k > 6) have been addressed. The model now works for any possible number of levels of factors A and B.
  • Some additional error messages were introduced with respect to ill-specified models violating the regression requirements of Type III SS models (minimum number of replicates required for a specified number of treatments).
  • Two additional large-sample examples were included showing how pivottables can be used in conjunction with the ANOVA-functions.
  • Treatment()-functionality (rather than pivottables) to convert raw data into tables that can be used in conjunction with ANOVA.

This macro allows users to conduct the following Analysis of Variance tests: Single-Factor ANOVA, Randomized Blocks Experiment, Unbalanced Single-Factor ANOVA, Two-factor ANOVA, Unbalanced Two-Factor ANOVA. The unbalanced experiments require a simple multivariate regression routine (included) to compare partial and full models. Note that one may use ANOVA for more than two factors. This approach may be undesirable due to computational efforts involved.

Tests for Stability of Error Term Variancedownloads: 2038 | type: xlsm | size: 242 kB

This spreadsheet includes three distinct tests to check for the presence of heteroscedasticity in the error terms of regression models. For univariate models, the Szroeter test statistic or Breusch-Pagan test may be used. For multivariate models, the Breusch-Pagan test or, alternatively, for extended models different White test may be applicable. Alternatively, manual solutions using Excel-inherent functions are provided.

European Option Pricingdownloads: 2509 | type: xlsm | size: 35 kB

These simple algorithms for option valuation circumvent the tedious manual calculations of the Black-Scholes-Merton model. The functions make provisions for foreign interest rate / dividend leakage and allow for calculation of all relevant option sensitivities (Delta, Theta, Gamma, Vega, Rho). Alternatively, prices of floating strike lookback options may be determined. All options assumed to be European style (exercise only at expiry date).

Unbalanced ANOVAdownloads: 1797 | type: xlsm | size: 192 kB

The spreadsheet gives an example as to the use of multiple linear regression in determining the significance of factors and interaction thereof when sample sizes / treatments are unequal in size. For a VBA-implementation see ANOVA model above.  


Excel Models

Financial Planning Model (Evaluator)downloads: 4792 | type: xlsm | size: 170 kB

This workbook includes a financial planning model that can be used to analyze the expected ROI of a business venture. It includes predicted balance sheets, cashflow and income statements, as well as sensitivity analysis. This applet is extremely useful when drafting business plans or assessing investment opportunities.

Minimum Variance portfolio / Optimizationdownloads: 3616 | type: xlsm | size: 93 kB

This spreadsheet requires the Solver Add-in, which can be downloaded from the Frontline Systems homepage. It includes an example to construct Minimum Variance portfolios from five assets, as well as an example of multiple objective optimization (optimal risk-return portfolios) using percentage deviations and sensitivity analysis. The sensitivity assistant too may be downloaded from Frontline Systems. Please note that Solver is not free-ware. A VBA-based optimization algorithm is currenlty under development.

Simulated HF/Index Portfoliosdownloads: 3994 | type: xlsm | size: 3 MB

This spreadsheets compares efficient portfolios of hedge funds and standard asset indices. It is helpful in finding the optimal asset allocation with regard to standard and alternative investments. The spreadsheet requires a Bloomberg uplink for data refresh.

Box Cox Transformationdownloads: 2353 | type: xlsm | size: 209 kB

This spreadsheet shows the relationship between maximum likelihood (ML) estimators of regression and ordinary least squares (OLS), as well as the the calculation of an unbiased estimator of the variability in Y from the ML estimator of variance. Additionally, it shows the determination and application of the Box-Cox power transformation in Y to ensure the assumptions of the Linear Model. In order to solve for the ML estimates, the Solver-Addin is required. Although this spreadsheet does not rely on VB Macros, regressions are calculated using the user-defined REGOUTPUT() function. Please enable macros or change the formula into LINEST().

Rebalancing portfolios - weighted index creationdownloads: 2488 | type: xlsm | size: 78 kB

This model creates a weighted series from several individual series. The input parameters are the return matrix, the weight matrix and a rebalancing interval depending on the nature of the source data (e.g. daily, 3-monthly, annual). The workbook contains a manual solution as well as a VBA-based array formula. Please note that missing return observations have to be entered as empty cells, not 0. Portfolio weights may change dynamically over time (matrix) or stay fixed (single row).


EastReg Internationaldownloads: 1596 | type: exe | size: 23 MB

This freeware statistical software was written by Herman J Bierens from Pennsylvania State University. It is a suprisingly powerful tool capable of conducting a multitude of operations. Please note that this is not an official mirror site. The install file has been placed here for convenience. However, no support or updates will be provided. Please follow this link to the official website.

matrix.xladownloads: 2353 | type: zip | size: 0 kB

Libero sponsors a number of extremely powerful Excel Add-ins that include matrix calculations and linear algebra. All software is freeware and Excel 2003/XP and VB6 compatible. The matrix.xla download has been tested in a Excel 2007/Vista environment and worked flawlessly. However, no responsibility is taken for compatibility issues. Please refer to Libero for further inquiries and browse their catalogue for other software. 

last updated: Mar 18 2018 1:59 AM
An XML error occurred on line 26: Mismatched tag