Professional Documents
Culture Documents
Eric Zivot
July 7, 2011
Matrices and Vectors Matrix a11 a12 a a22 A = 21 . . ... . . (nm) an1 an2 n = # of rows, m = Square matrix : n = m Vector
(n1)
x1 x2 . . xn
Remarks
R is a matrix oriented programming language Excel can handle matrices and vectors in formulas and some functions Excel has special functions for working with matrices. There are called array functions. Must use <ctrl>-<shift>-<enter> to evaluate array function
A 0 = transpose of A
(nm)
Example
A=
"
1 2 3 4 5 6
1 h i 0 x= 2 , x = 1 2 3 3
1 4 0 , A = 2 5 3 6
A = A0
Example
"
A=
1 2 2 1
, A0 =
"
1 2 2 1
"
4 9 2 1
"
2 0 0 7
= =
"
4 9 2 1
"
2 0 0 7
= =
42 90 20 17 2 9 2 6
#
c = 2 = scalar A= 2A=
" "
3 1 0 5
2 3 2 (1) 20 25
"
6 2 0 10
" # a11 a12 b11 b12 b13 A = a21 a22 , B = b21 b22 b23 (32) (23) a31 a32
A B
Remark: In general,
A B 6= B A
Example
A= AB=
R operator
" "
1 2 3 4
, B=
"
5 6 7 8
#
5 + 14 6 + 16 15 + 28 18 + 32
"
19 22 43 50
Identity Matrix The n dimensional identity matrix has all diagonal elements equal to 1, and all o diagonal elements equal to 0. Example
I2 =
" " #"
"
1 0 0 1
# #
I2A =
=
1 0 0 1
"
=A
Similarly
A I2 =
= R function
" "
#" #
1 0 0 1
=A
(nn)
A1A=In AA1=In
Remark: A1 is similar to the inverse of a number: 1 a = 2, a1 = 2 1 a a1 = 2 = 1 2 1 a1 a = 2 = 1 2
Representing Systems of Linear Equations Using Matrix Algebra Consider the system of two linear equations x+y =1 2x y = 1 The equations represent two straight lines which intersect at the point 2 1 x= , y= 3 3
or
1 1 2 1
#"
x y
"
1 1
Az=b
where
A=
"
1 1 2 1
, z=
"
x y
and b =
"
1 1
x y
"
1 1 2 1
#1 "
1 1
Remark: As long as we can determine the elements in A1, we can solve for the values of x and y in the vector z. Since the system of linear equations has a solution as long as the two lines intersect, we can determine the elements in A1 provided the two lines are not parallel.
There are general numerical algorithms for nding the elements of A1 and programs like Excel and R have these algorithms available. However, if A is a (2 2) matrix then there is a simple formula for A1. Let
A=
Then
"
.
#
1 A1 = det(A) where
A1 =
Notice that
1 1 2
"
1 3 2 3
"
1 1 2 1
#"
=
#
"
1 3 2 3
1 3 1 3
A1A =
Our solution for z is then
1 3 1 3
1 1 2 1
"
1 0 0 1
z = A1b
"
1 so that x = 2 3 and y = 3 .
In general, if we have n linear equations in n unknown variables we may write the system of equations as a11x1 + a12x2 + + a1nxn = b1 a21x1 + a22x2 + + a2nxn = b2 . .=. . an1x1 + an2x2 + + annxn = bn which we may then express in matrix form as
or
x1 x2 . . xn
b1 b2 . . bn
(nn) (n1)
= b.
(n1)
x = A1b
where A1A = I and I is the (n n) identity matrix. If the number of equations is greater than two, then we generally use numerical algorithms to nd the elements in A1.
i=1
n X
xi = x1 + x2 + + xn =
(n1)
x1 x2 . . xn
1 = , (n1)
1 1 . . 1
Then
x01 =
x1 x2 xn
1 1 . . 1
n X
= x1 + x2 + + xn = Equivalently
xi
i=1
10x =
1 1 1
x1 x2 . . xn
= x1 + x2 + + xn =
i=1
n X
xi
Sum of Squares
n X 2 2 2 x2 i = x1 + x2 + + xn
i=1
x0x =
x1 x2 xn
2 2 = x2 1 + x2 + + xn =
x1 x2 . . xn
n X
x2 i
i=1
i=1
x0y =
x1 x2 xn
y1 y2 . . yn
i=1
n X
xiyi
Portfolio Math with Matrix Algebra Three Risky Asset Example Let Ri denote the return on asset i = A, B, C and assume that R1, R2 and R3 are jointly normally distributed with means, variances and covariances:
2 = var(R ), cov(R , R ) = i = E [Ri], i i i j ij
RA A 1 R = RB , = B , 1 = 1 1 RC C
2 A AB AC xA 2 x = xB , = AB B BC 2 xC AC BC C
1 x01 = ( xA xB xC ) 1 1 = x1 + x2 + x3 = 1
Digression on Covariance Matrix Using matrix algebra, the covariance matrix of the return vector R is dened as cov(R) = E [(R )(R )0] = If R has N elements then will be the N N matrix
2 1 12 2 12 2 . . . . 1n 2n
1n 2n . ... . 2 n
(R1 1)2 (R1 1)(R2 2) =E (R2 2)(R1 1) (R2 2)2 ! E [(R1 1)2] E [(R1 1)(R2 2)] = E [(R2 2)(R1 1)] E [(R2 2)2] =
"
12
"
R1 1 R2 2
(R1 1, R2 2)
!#
2 1 12 2 12 2
= .
Portfolio return
Portfolio variance
2 = var(x0R) = E [x0(R )(R )0x] = p,x
Covariance Between 2 Portfolio Returns 2 portfolios xA yA x = xB , y = yB xC yC x01 = 1, y01 = 1 Portfolio returns Rp,x = x0R Rp,y = y0R Covariance cov(Rp,x, Rp,y ) = x0y = y0x
Derivation
cov(Rp,x, Rp,y ) = cov(x0R, y0R) = E [(x0R E [x0R])(y0R E [y0R])0] = x0E [(R )(R )0]y = E [x0(R )(R )0y]
= x0y
Bivariate Normal Distribution Let X and Y be distributed bivariate normal. The joint pdf is given by f (x, y ) = 1 x X exp 2(1 2 ) X XY
!2
2X Y
y Y + Y
1 2 XY
!2
2XY (x X )(y Y ) X Y
Dene
X=
X Y
, x=
x y
, =
X Y
, =
2 X XY
XY 2 Y
Then the bivariate normal distribution can be compactly expressed as f (x) = where
2 2 2 2 2 2 2 2 det() = X Y XY = X Y X Y XY 2 2 (1 2 ). = X Y XY
0 1 1 1 2 (x) (x) e 2 det()1/2
X N (, )