You can’t see this text!

Introduction to Computational Finance andFinancial Econometrics
Descriptive Statistics
Eric Zivot
Summer 2015

Eric Zivot (Copyright © 2015)

Descriptive Statistics

1 / 28

Outline
1 Univariate Descriptive Statistics
2 Bivariate Descriptive Statistics
3 Time Series Descriptive Statistics

Eric Zivot (Copyright © 2015)

Descriptive Statistics

2 / 28

Covariance Stationarity{. . . , X1 , . . . , XT , . . .} = {Xt }is a covariance stationary stochastic process, and each Xt is identically
distributed with unknown pdf f (x).
Recall,E[Xt ] = µ indep of tvar(Xt ) = σ 2 indep of tcov(Xt , Xt−j ) = γj indep of tcor(Xt , Xt−j ) = ρj indep of t
Eric Zivot (Copyright © 2015)

Descriptive Statistics

3 / 28

Descriptive Statistics

Observed Sample:{X1 = x1 , . . . , XT = xT } = {xt }T
t=1
are observations generated by the stochastic process.
Descriptive Statistics:
Data summaries (statistics) to describe certain features of the data, tolearn about the unknown pdf, f (x), and to capture the observed
dependencies in the data.

Eric Zivot (Copyright © 2015)

Descriptive Statistics

4 / 28

Time PlotsLine plot of time series data with time/dates on horizontal axis.
Visualization of data - uncover trends, assess stationarity and timedependence
Spot unusual behavior
Plotting multiple time series can reveal commonality across series

Eric Zivot (Copyright © 2015)

Descriptive Statistics

5 / 28

Histograms

Goal: Describe the shape of the distribution of the data {xt }T
t=1
Hisogram Construction:
1

Order data from smallest to largest values

2

Divide range into N equally spaced bins[−| − | − | · · · | − | − |−]3Count number of observations in each bin

4Create bar chart (optionally normalize area to equal 1)

Eric Zivot (Copyright © 2015)

Descriptive Statistics

6 / 28

R Functions
Function
hist()
density()

Description
compute histogram
compute smoothed histogram

Note: The density() function computes a smoothed (kernel density)
estimate of the unknown pdf at the point x using the formula:f̂ (x) =T1 X
kTb t=1

x − xtbk(·) = kernel functionb = bandwidth (smoothing) parameter
where k(·) is a pdf symmetric about zero (typically the standard
normal distribution). See Ruppert Chapter 4 for details.
Eric Zivot (Copyright © 2015)

Descriptive Statistics

7 / 28

Empirical Quantiles/Percentiles
Percentiles:
For α ∈ [0, 1], the 100 × αth percentile (empirical quantile) of a sampleof data is the data value q̂α such that α · 100% of the data are less thanq̂α .
Quartiles:
q̂.25 = first quartile
q̂.50 = second quartile (median)q̂.75 = third quartileq̂.75 − q̂.25 = interquartile range (IQR)

Eric Zivot (Copyright © 2015)

Descriptive Statistics

8 / 28

R Functions

Functionsort()
min()max()
range()
quantile()
median()IQR()
summary()

Eric Zivot (Copyright © 2015)

Description
sort elements of data vector
compute minimum value of data vector
compute maximum value of data vector
compute min and max of a data vector
compute empirical quantiles
compute mediancompute inter-quartile range
compute summary statistics

Descriptive Statistics

9 / 28

Historical Value-at-Risk
Let {Rt }T
t=1 denote a sample of T simple monthly returns on an
investment, and let $W0 be the initial value of an investment. Forα ∈ (0, 1), the historical VaRα is:$W0 × q̂αR
q̂αR = empirical α · 100% quantile of {Rt }T
t=1
Note: For continuously compounded returns {rt }T
t=1 use:$W0 × (exp(q̂αr ) − 1)q̂αr = empirical α · 100% quantile of {rt }T
t=1

Eric Zivot (Copyright © 2015)

Descriptive Statistics

10 / 28

Sample Statistics
Plug-In Principle: Estimate population quantities using sample
statistics.
Sample Average (Mean):
T1 X
xt = x̄ = µ̂x
T t=1

Sample Variance:T1 X(xt − x̄)2 = sx2 = σ̂x2
T − 1 t=1

Sample Standard Deviation:
qsx2 = sx = σ̂xEric Zivot (Copyright © 2015)

Descriptive Statistics

11 / 28

Sample Statistics cont.
Sample Skewness:T
1 X[(xt − x̄)3 /sx3 = skew
T − 1 t=1

Sample Kurtosis:
T1 X
d(xt − x̄)4 /sx4 = kurt
T − 1 t=1

Sample Excess Kurtosis:d −3kurt

Eric Zivot (Copyright © 2015)

Descriptive Statistics

12 / 28

R Functions

Functionmean()
colMeans()
var()
sd()
skewness()kurtosis()Packagebasebasestats
stats
PerformanceAnalytics
PerformanceAnalytics

Description
compute sample mean
compute column means of matrix
compute sample variancecompute sample standard deviation
compute sample skewness
compute sample excess kurtosis

Note: Use the R function apply(), to apply functions over rows orcolumns of a matrix or data.frame.

Eric Zivot (Copyright © 2015)

Descriptive Statistics

13 / 28

Empirical Cumulative Distribution Function

Recall, the CDF of a random variable X is:FX (x) = Pr(X ≤ x)
The empirical CDF of a random sample is:F̂X (x) ==1(#xi ≤ x)nnumber of xi values ≤ xsample size

Eric Zivot (Copyright © 2015)

Descriptive Statistics

14 / 28

Empirical Cumulative Distribution Function cont.

How to compute and plot F̂X (x) for a sample {x1 , . . . , xn }.
Sort data from smallest to largest values: {x(1) , . . . , x(n) } andcompute F̂X (x) at these points
Plot F̂X (x) against sorted data {x(1) , . . . , x(n) }Use the R function ecdf()
Note: x(1) , . . . , x(n) are called the order statistics. In particular,x(1) = min(x1 , . . . , xn ) and x(n) = max(x1 , . . . , xn ).

Eric Zivot (Copyright © 2015)

Descriptive Statistics

15 / 28

Quantile-Quantile (QQ) PlotsA QQ plot is useful for comparing your data with the quantiles of a
distribution (usually the normal distribution) that you think isappropriate for your data. You interpret the QQ plot in the following
way:
If the points fall close to a straight line, your conjectured
distribution is appropriate
If the points do not fall close to a straight line, your conjectured
distribution is not appropriate and you should consider a different
distribution

Eric Zivot (Copyright © 2015)

Descriptive Statistics

16 / 28

R Functions

Function
qqnorm()qqline()qqPlot()Packagestatsstatscar

Eric Zivot (Copyright © 2015)

Description
QQ-plot against normal distribution
draw straight line on QQ-plot
QQ-plot against specified distribution

Descriptive Statistics

17 / 28

Outliers

Extremely large or small values are called “outliers
Outliers can greatly influence the values of common descriptivestatistics. In particular, the sample mean, variance, standard
deviation, skewness and kurtosis
Percentile measures are more robust to outliers: outliers do not
greatly influence these measures (e.g. median instead of mean;
IQR instead of SD)

Eric Zivot (Copyright © 2015)

Descriptive Statistics

18 / 28

Outliers cont.
IQR (interquartile range) - outlier robust measure of spread:
IQR = q.75 − q.25
Moderate Outlier:q̂.75 + 1.5 · IQR < x < q̂.75 + 3 · IQR
q̂.25 − 3 · IQR < x < q̂.25 − 1.5 · IQRExtreme Outlier:x > q̂.75 + 3 · IQR
x < q̂.25 − 3 · IQR

Eric Zivot (Copyright © 2015)

Descriptive Statistics

19 / 28

Boxplots

A box plot displays the locations of the basic features of thedistribution of one-dimensional data—the median, the upper and lower
quartiles, outer fences that indicate the extent of your data beyond thequartiles, and outliers, if any.
R functions
Function
boxplot()
chart.Boxplot()

Packagegraphics
PerformanceAnalytics

Eric Zivot (Copyright © 2015)

Description
box plots for multiple series
box plots for asset returns

Descriptive Statistics

20 / 28

Outline
1 Univariate Descriptive Statistics
2 Bivariate Descriptive Statistics
3 Time Series Descriptive Statistics

Eric Zivot (Copyright © 2015)

Descriptive Statistics

21 / 28

Bivariate Descriptive Statistics{. . . , (X1 , Y1 ), (X2 , Y2 ), . . . (XT , YT ), . . .} = {(Xt , Yt )}Covariance stationary bivariate stochastic process with realized values:{(x1 , y1 ), (x2 , y2 ), . . . (xT , yT )} = {(xt , yt )}T
t=1
Scatterplot:
XY plot of bivariate data
R functions: plot(), pairs()

Eric Zivot (Copyright © 2015)

Descriptive Statistics

22 / 28Bivariate Descriptive Statistics cont.

Sample Covariance:
T1 X(xt − x̄)(yt − ȳ) = sxy = σ̂xy
T − 1 t=1

Sample Correlation:sxy= rxy = ρ̂xysx sy

Eric Zivot (Copyright © 2015)

Descriptive Statistics

23 / 28

R Functions

Function
var()
cov()
cor()

Packagestats
stats
stats

Eric Zivot (Copyright © 2015)

Description
compute sample variance-covariance matrix
compute sample variance-covariance matrix
compute sample correlation matrix

Descriptive Statistics

24 / 28

Outline
1 Univariate Descriptive Statistics
2 Bivariate Descriptive Statistics
3 Time Series Descriptive Statistics

Eric Zivot (Copyright © 2015)

Descriptive Statistics

25 / 28

Time Series Descriptive Statistics
Sample Autocovariance:γ̂j =TX
1(xt − x̄)(xt−j − x̄) j = 1, 2, . . .
T − 1 t=j+1

Sample Autocorrelation:ρ̂j =γ̂j, j = 1, 2, . . .
σ̂ 2Sample Autocorrelation Function (SACF):Plot ρ̂j against j

Eric Zivot (Copyright © 2015)

Descriptive Statistics

26 / 28

R Functions

Functionacf()chart.ACF()
chart.ACFplus()

Eric Zivot (Copyright © 2015)

Packagestats
PerformanceAnalytics
PerformanceAnalytics

Descriptive Statistics

Description
compute and plot
sample autocorrelations
plot sample autocorrelations
plot sample autocorrelations

27 / 28

You can’t see this text!

faculty.washington.edu/ezivot/

Eric Zivot (Copyright © 2015)

Descriptive Statistics

28 / 28