VMX Excel Add-In Docs Version1
VMX Excel Add-In Docs Version1
VMX Excel Add-In Docs Version1
1.
2.
3.
2.1.
2.2.
2.3.
4.
3.1.
3.2.
5.
4.1.
4.2.
4.3.
4.4.
6.
5.1.
LU Decomposition ............................................................................................................................................................................................... 19
5.2.
QR Decomposition .............................................................................................................................................................................................. 20
5.3.
5.4.
Cholesky .............................................................................................................................................................................................................. 22
7.
6.1.
6.2.
8.
7.1.
7.2.
7.3.
Non-Square ......................................................................................................................................................................................................... 26
9.
8.1.
Co-Variance ......................................................................................................................................................................................................... 27
8.2.
Correlation .......................................................................................................................................................................................................... 28
8.3.
9.2.
10.
10.2.
10.3.
Page
1. What is vMx?
vMx is a free linear algebra Microsoft Excel add-In for operating, decomposing and solving matrices. vMx stands
for Vector Math in Excel. The Add-in consists of 45 functions and a Ribbon toolbar. Excel is one of the most
powerful tools for analyzing data but it does not offer much support for solving linear algebra problems. vMx
seeks to fill this void.
The vMx functions provide the following functionalities:
Page
2. Getting Started
vMx is a free Excel add-in that can be downloaded from the website www.vmxaddin.com. This pdf
document is also available on the website. This document contains sections explaining each vMx function
and the vMx Ribbon in detail.
2.1. Installing vMx
vMx is available as an add-in for Excel 2007 or 2010 . vMx can be installed on 32 or 64 bit systems.
However, vMx can only be installed on Excel 32 bit version. Excel 32 bit version can run on both 32 and 64
bit systems. Excel 64 bit version can run on 64 bit systems only. vMx was only tested on Windows 7 so no
assurances are given for any other Windows operating systems.
Once vMx is installed it will add a Ribbon under the Formula ribbon tab and to the right of the Function
Library menu items.
Page
2. Type =VMX. into a cell and Excels auto complete functionality will list all the vMx available functions.
3. Use the vMx ribbon to bring up the vMx function list menu. The vMx ribbon can be found under the
formula ribbon menu item.
Page
In our first example we use the vMx function VMX.TRANSPOSE() to transpose a matrix. If we want to
transpose the matrix [
We then call the function using one of the three methods described in section 2.2. In this case we use the
second method and type directly in a cell.
Page
After we press enter the function transposes the matrix but at this point we can only see the element at row
1 column 1.
Since this the function returns an array we need to enter the formula into a cell range of 2 rows and 3
columns. For example, we can enter the formula into cell address E2:G3 as an array formula. We have two
options for entering a formula as an array formula. The first option is using Excels standard method and the
second (more efficient method) is with the vMx ribbon.
Option 1: (Excels standard method): Select the cell range (E2:G3) and then hoover the cursor over the
formula bar and left click. From this point we hold CTRL and SHIFT key at the same time and finally press
ENTER. This will display the formula result of VMX.TRANSOPSE(B2:C4) in the range E2:G3. Section 2.4
discusses using array formula in more detail. The formula bar will display opening and closing curly braces
around the formula.
Section 3.1 discusses array formula using excel standard method in more detail.
Page
Option 2 (using the vMx Ribbon): The vMx ribbon includes an Auto-Size Array button for resizing array formulas
to their proper size. For example after entering the transpose function into cell E2 we then select E2 and press
the Auto-Size Array button and it will automatically set the formula over cell range E2:G3 as a formula array.
Section 3.2 discusses using the vMx toolbar ribbon in more detail.
Page
Page
Once you enter an array formula the included cells are treated as one group and can only be edited in
certain ways. If you try and change any of the included cells you will receive an error message.
Editing an Array Formula
To edit an array formula you first highlight the cells the array formula covers and then left-click the formula
bar. You can then edit the formula and finally press CTRL+SHIFT + ENTER. From our example above we
would highlight cells E2:G3, left-click the formula bar, edit the formula, and press CTRL+SHIFT + ENTER keys.
Removing an Array Formula
Excel does not provide an easy way to remove an array formula entered into multi-cells. However, the vMx
Ribbon which is discussed in section 3.2 makes it quite easy to remove array formulas. To remove an array
formula using the Excel built-in functionality you first highlight the array formula included cells, left-click the
formula bar, and hold CTRL and press ENTER. This will enter the same formula into all the highlighted cells.
From this point you can proceed to remove the formula from whichever cells you want. Fortunately, the
vMx Ribbon removes the formula except from the left top most element, which normally is what we want
when removing an array formula.
Page
10
The vMx Ribbon contains four buttons and one check box. The following describes each item:
Page
11
Function List.
When the user presses the vMx Function List button they will see a menu with all the available vMx functions.
The menu also has a function list filter to see available functions by category.
Selecting a function and pressing Insert will bring up the selected function to the Function Argument screen. On
this screen, the user can pass all the required function parameters.
Page
12
After entering the formula in cell E2 we need to enter the formula as an array formula over the range E2:G3.
Using the Auto-Size Array button will automatically perform setting E2:G3 with the formula from cell E2.
Now if we want to change our matrix and make it a 2 by 4 instead we will need to update our formula. To
update our formula we can click the insert function located to the left of the formula bar.
After clicking insert function we can update the input matrix range from B2:C4 to B2:C5 and then click the Ok
button.
Page
13
At this point our formula will update to the correct matrix input range but the array formula is still set to range
E2:G3 instead of E2:H3. To update the array formula, we select any cell in the range E2:G3 and press the AutoSize Array button. This will automatically resize our array formula to range E2:H3.
The Override Prompt check box works in tandem with the Auto-Size Array button. For example if cells H2 or H3
would have contained any value then in the above example, we would get a prompt that their content is about
to get replaced when pressing the Auto-Size Array button. The user will have the option to continue or cancel.
By default, Override Prompt is set to True but it can be disabled by unchecking it.
Page
14
Now after clicking the Set Array button cells C3:E7 are set with an array formula of =2+5
The Set Array button is a convenience feature to allow flexibility to the Auto-Size Array button.
Page
15
Page
16
4. Operating on Matrices
There are four functions for adding, dividing, multiplying and subtracting matrices or scalars. The functions
can take up to 10 matrices or scalars but requires at least the first two parameters. With the exception that
multiplying all matrices passed as parameters must be of the same dimensions. All four functions return a
matrix if at least one parameter is a matrix. The four functions will return a scalar if all parameters passed
are scalar but if all parameters are scalar it is recommended to use the built-in Excel function SUM() instead.
The four functions are also left-to-right associative. The following table lists the four operating matrix
functions and the parameters they take.
Name
VMX.ADD()
VMX.DIVIDE()
VMX.MULTIPLY()
VMX.SUBTRACT()
Parameters
matrix A1,matrix A2,[matrix A3...matrix A10]
matrix A1,matrix A2,[matrix A3...matrix A10]
matrix A1,matrix A2,[matrix A3...matrix A10]
matrix A1,matrix A2,[matrix A3...matrix A10]
We use examples 4.1.1 through 4.4.2 in the sample vMx Excel file to demonstrate how to use the operating
functions. The examples use matrix A, B and C shown below:
In example 4.1.1 we show how to add matrices of the same size. In example 4.1.2 we add two matrices and
a scalar of 3. With the vMx add function, the order of the scalar does not impact the ending result. So if the
scalar of 3 was passed as the first parameter in example 4.1.2 it would not change the result. All matrices
passed as parameters to the adding function must be of the same size.
Page
17
In example 4.2.1 we subtract matrix A from B. Example 4.2.2 subtracts a scalar of 7 from matrix B and then
subtract matrix C from the result. With the subtraction function the order of the scalar does impact the
result. In example 4.2.2 we would get an error if we passed the scalar 7 as the first parameter since we
cannot subtract a matrix from a scalar. All matrices passed as parameters to the subtraction function must
be of the same size.
4.3. Multiplying function VMX.MULTIPLY()
In order to multiply two matrices the left matrixs column count must equal the right matrixs row count. In
example 4.3.1 we multiply matrix A times B times D. Example 4.3.2 multiplies matrix C times scalar of 2
times D. When multiplying a matrix by a scalar every matrix element is multiplied by the scalar value. A
scalar can be on the left or right side of a matrix and it will yield the same result. For example scalar of 2
times Matrix A is equivalent to Matrix A times scalar of 2 (i.e. 2 x A = A x 2).
Page
18
the matrix. The function returns an error if you try to divide a matrix by a scalar. Example 4.4.1 divides
matrix A by B and example 4.4.2 divides matrix B by scalar of 2 then matrix C.
Page
19
5. Matrix Decomposition
vMx provides functions to decompose a matrix into a factorization of a product of matrices. With vMx you
can perform a LU, QR, SVD or Cholesky decomposition as discussed below.
5.1. LU Decomposition
vMx includes seven functions that utilizes LU decomposition with partial pivoting where matrix A is factored
into a lower and upper triangular matrices L and U where P * A = L * U. P is the permutation matrix. In this
section we dont demonstrate how to use the function VMX.LU.SOLVE() to solve Ax=b but instead it is
covered in section 7. The vMx functions can only perform a LU decomposition on square matrices. The
seven functions that utilize LU decomposition are listed below.
Name
VMX.LU.COMBO()
VMX.LU.DETERMINANT()
VMX.LU.INVERSE()
VMX.LU.LOWER()
VMX.LU.PERMUTATION()
VMX.LU.SOLVE()
VMX.LU.UPPER()
Parameters
matrix A
matrix A
matrix A
matrix A
matrix A
matrix A, matrix b
matrix A
Description
Returns LU decomposition in one matrix: P * A = L * U
Calculates matrix's determinant using LU decomposition
Inverts matrix using LU decomposition
Returns lower triangular matrix from LU decomposition: P * A = L * U
Returns permutation matrix from LU decomposition: P * A = L * U
Solves Ax=b using LU decomposition
Returns upper triangular matrix from LU decomposition: P * A = L * U
Example 5.1.1
In example 5.1.1 we perform a LU decomposition on matrix A to calculate the permutation, lower and upper
triangular matrices.
Page
20
Example 5.1.2 returns the lower and upper triangular matrices from a LU decomposition of matrix A from
example 5.1.1 combined in one matrix. In example 5.1.3 we calculate the determinant of matrix A and in
5.1.4 we calculate its inverse.
5.2. QR Decomposition
A QR decomposition of a matrix is a decomposition of a matrix A into a product, where A=QR, of an
orthogonal matrix Q and an upper triangular matrix R. There are two vMx functions that use QR
decomposition. The two are listed below:
Name
Parameters Description
VMX.QR.Q() matrix A
Returns orthogonal matrix Q from QR decomposition
VMX.QR.R() matrix A
Returns upper triangular matrix R from QR decomposition
Example 5.2.1
Page
21
Name
VMX.SVD.RANK()
VMX.SVD.S()
VMX.SVD.U()
VMX.SVD.VT()
Parameters
matrix A,tolerance
matrix A
matrix A
matrix A
Description
Calculates matrix rank using SVD decomposition
Returns Sigma matrix from SVD decomposition
Returns orthogonal M by M matrix U from SVD decomposition
Returns orthogonal N by N matrix V^t from SVD decomposition
Example 5.3.1
In example 5.3.1 we show how to use the available vMx SVD functions on a matrix A.
Page
22
5.4. Cholesky
Cholesky decomposition is a matrix decomposition of a symmetric positive-definite matrix into the product
of a lower triangular matrix and its conjugate transpose. There are four vMx functions that use Cholesky
decomposition as listed below. We discuss using VMX.CHOLESKY.SOLVE() function in section 7.
Name
VMX.CHOLESKY.IS.SPD()
VMX.CHOLESKY.LOWER()
VMX.CHOLESKY.SOLVE()
VMX.CHOLESKY.UPPER()
Parameters
matrix A
matrix A
matrix A,matrix b
matrix A
Description
Returns true if matrix has cholesky decomposition
Returns lower matrix from cholesky decomposition
Solves Ax=b using cholesky decomposition and returns matrix x
Returns upper matrix from cholesky decomposition
Example 5.4.1
In example 5.4.1 matrices L and U are the upper and lower triangular Cholesky decompositions of matrix A.
We also test if matrix A is Symmetric Definite Positive.
Page
Parameters Description
Returns imaginary eigen values in a diagonal matrix for a nonVMX.EIGENNONSYM.IMAGVALMTX() matrix A
symmetric square matrix
Returns imaginary eigen values in a vector for a non-symmetric
VMX.EIGENNONSYM.IMAGVALVCTR() matrix A
square matrix
VMX.EIGENNONSYM.LFTVCTRS()
matrix A
Returns left vectors of a non-symetric square matrix
Returns real eigen values in a diagonal matrix for a non-symmetric
VMX.EIGENNONSYM.REALVALMTX() matrix A
square matrix
Returns real eigen values in a vector for a non-symmetric square
VMX.EIGENNONSYM.REALVALVCTR() matrix A
matrix
VMX.EIGENNONSYM.RGHTVCTRS()
matrix A
Returns right vectors of a non-symetric square matrix
VMX.EIGENSYM.VALMTX()
matrix A
Returns a diagonal matrix with eigen values of a symmetric matrix
VMX.EIGENSYM.VALVTR()
matrix A
Returns eigen values in a diagonal matrix for a symmetric matrix
VMX.EIGENSYM.VECTORS()
matrix A
Returns eigen values in a vector for a symmetric matrix
23
Page
6.2. Non-Symmetric Examples
Examples 6.2.1 to 6.2.6 demonstrate how to use the non-symmetric vMx Eigen functions.
24
Page
25
7. Solving Ax=b
vMx provides three functions for solving the system of equations Ax=b. To solve matrix x when A is square
matrix we use VMX.LU.SOLVE() which performs a LU decomposition on A. To solve for matrix x when A is
Symmetric Positive Definite (SPD) we can use VMX.CHOLESKY.SOLVE() which performs a Cholesky
decomposition on matrix A. When matrix A is non-square we can use VMX.LEASTSQUARES() to solve for matrix
x which performs a Least square analysis. All three functions can accept matrix b that is bigger than one
column.
Name
VMX.LU.SOLVE()
VMX.CHOLESKY.SOLVE()
VMX.LEASTSQUARES()
Parameters
matrix A, matrix b
matrix A,matrix b
matrix A,matrix b, [error term]
Description
Solves Ax=b using LU decomposition
Solves Ax=b using cholesky decomposition and returns matrix x
Get least squares solution to Ax=b
In example 7.1.1 we solve for matrix x using a LU decomposition where A is a 4 by 4 matrix and b is a 4 by 1
matrix. In 7.1.2 we solve for matrix x when A is a 3 by 3 matrix and b is a 3 by 2 matrix.
7.2. Symmetric Positive Definite
In example 7.2.1 we solve for matrix x using Cholesky decomposition, where A is a 4 by 4 SPD matrix and b is
a 4 by 1 matrix. In 5.7.2 we solve for matrix x when A is a 3 by 3 SPD matrix and b is a 3 by 2 matrix.
Page
26
7.3. Non-Square
In example 7.3.1 and 7.3.2 we use matrix A which is the daily log returns of the Dow Jones, S&P 500 and
Nasdaq indices over a 14-day period. Matrix b is the daily log returns of Googles stock price over the same
14-day period. In these two example we use VMX.LEASTSQUARES() function to solve for our matrix x. This
function takes three parameters; matrix A, matrix b and a Boolean error term flag. When the error flag is set
to True, the function also returns an error term but none if set to False. In example 7.3.1 we set the error
flag to True but in 7.3.2 it is set to False. If no value is passed as the error flag it defaults to True. When the
columns of matrix A are bigger than its rows, the error flag has no impact.
We can derive the same answer to 7.3.1 using the Excel built in Regression Data Analysis functionality under
the Data Ribbon. However, the resulting answer will be static and will not update automatically if the
underlying data changes. In contrast, the VMX.LEASTSQUARES() function will automatically update when
the data changes. Additionally, Excels built-in regression functionality and the VMX.LEASTSQUARES()
function will produce different results when the columns of matrix A are bigger than its rows.
Page
27
8. Statistical Matrices
In this section we discuss the vMx functions for creating the Co-variance, correlation and standard deviation
matrices for a given data set. All the statistical functions only read and return numbers and do not return name
headers of the data set. Additionally these functions only read points that run along the rows. Excel does have a
built-in data analysis tool for calculating co-variance and correlation matrix. Though unlike the vMx functions, it
is not dynamic and will not update when the underlining data set changes. To demonstrate how to use these
functions we use the same daily log returns data for the Dow Jones index, S&P 500 index, Nasdaq index and
google stock from section 7.3:
8.1. Co-Variance
The following two functions can be used to create the co-variance matrix:
Name
Parameters
Description
VMX.STAT.COVARIANCE() matrix A,column 1,column 2 Calculates covariance of two columns for a given data set
VMX.STAT.COVARMTX()
matrix A
Returns the covariance matrix of given data set
In example 8.1.1 we use the VMX.STAT.COVARMTX() function to calculate the co-variance matrix for the
daily log returns. The function returns a 4 by 4 matrix since the data set is four columns. In example 8.1.1
the function is entered as an array formula in cell address B15:E18. In example 8.1.2 we show how we can
calculate the co-variance for two variables. We calculate the co-variance for the S&P and Nasdaq which are
the second and third variable in our data set. The vMx function VMX.STAT.COVARIANCE() produces the
same result as the built-in Excel function COVARIANCE.P() but it is part of the library as a convenience
function. The VMX.STAT.COVARIANCE() function can be used to create the co-variance matrix one element
at a time.
Page
28
8.2. Correlation
The following two functions can be used to create the correlation matrix:
Name
Parameters
Description
VMX.STAT.CORRELATION() matrix A,column 1,column 2 Calculates correlation of two columns for a given data set
VMX.STAT.CORRMTX()
matrix A
Returns the correlation matrix of given data set
In example 8.2.1 we use the VMX.STAT.CORRMTX() function to create the correlation matrix for the daily log
returns. The function returns a 4 by 4 matrix since the data set is four columns. In example 8.1.1 the
function is entered as an array formula in cell address B23:E26. In example 8.2.2 we show how we can
calculate the correlation for two variables. We calculate the correlation for the DJI and S&P which are the
first and second variables in our data set. The vMx function VMX.STAT.CORRELATION() produces the same
result as the built-in Excel function CORREL() but it is part of the library as a convenience function. The
VMX.STAT.CORRELATION() function can be used to create the correlation matrix one element at a time.
Page
29
In example 8.3.1 we use the VMX.STAT.STANDTVNMTX() function to create the standard deviation matrix
for the daily log returns. The function returns a 4 by 4 matrix since the data set is four columns. In example
8.1.1 the function is entered as an array formula in cell address B31:E34. In example 8.2.2 we show how
we can calculate the standard deviation for just one index. We calculate the standard deviation for the DJI
which is the first variable in our data set. The vMx function VMX.STAT.STANDARDDVTN() produces the same
result as the built-in Excel function STDEV.P() but it is also part of the library as a convenience function.
The VMX.STAT.STANDARDDVTN() function can be used to create the standard deviation matrix one element
at a time.
Page
30
Parameters
Row size,Column size, Begin value, End value,
VMX.RANDOM.INT
LeftBand, RightBand
Row size,Column size, Begin value, End value,
VMX.RANDOM.REAL
LeftBand, RightBand
Row=Col size, Begin value, End value,Band
VMX.RANDOM.SYMMETRIC.INT size
Row=Col size, Begin value, End value,Band
VMX.RANDOM.SYMMETRIC.REAL size
Description
Returns a matrix with random integer numbers
Returns a matrix with random real numbers
Returns a symmetric matrix with random integer
numbers
Returns a symmetric matrix with random real
numbers
In example 9.1.1 we create a 3 by 4 matrix where the random generated integer values are between 0 and
50 and the banded parameters are left blank so the function returns a full-banded matrix. In example 9.1.2
we create a 3 by 3 symmetric matrix where the real values are between -10 and 20 where both band
parameters are set to zero. Example 9.1.3 demonstrates setting the left and right band parameters to
different values. In example 9.1.4 the function returns a 5 by 5 lower triangular matrix by leaving the left
band parameter blank and setting the right band to zero.
Page
31
Example 9.1.5 demonstrates how to create a 3 by 3 integer symmetric matrix by leaving the band parameter
blank. In example 9.1.6 we create a 3 by 3 diagonal matrix by setting the band parameter to zero.
9.2. Diagonal matrix
There is one function for creating diagonal matrices. The matrixs dimensions are determined by passing
size parameters. You set the value of the diagonal by setting the diagonal value parameter. This function
can be very helpful especially for creating identity matrices.
Name
Parameters
Description
VMX.DIAGONAL() Row size,Column size, Diagonal value Returns a diagonal matrix with passed value on the diagonal
In example 9.2.1 we create a square 3 by 3 diagonal matrix with diagonal value 5.5. In example 9.2.2 we
create a rectangular 3 by 5 matrix with 2 as the diagonal value. We create a 4 by 4 identity matrix in
example 9.2.3. In the last example 9.2.4, we create a 5 by 3 rectangular matrix with 3.00 as the diagonal
value.
Page
32
Name
VMX.IS.SQUARE()
VMX.IS.SYMMETRIC()
VMX.TRANSPOSE()
10.1.
Parameters
matrix A
matrix A
matrix A
Description
Checks wether a matrix is square
Checks wether a matrix is symmetric
Transposes a matrix
In example 10.1.1 we check if Matrix A, B and C are square matrices. The square function returns TRUE for A
and B but FALSE for C.
10.2.
In example 10.2 we check if the same matrices from example 10.1.1 are symmetric.
10.3.
Transpose a matrix