28
You can’t see this text! Introduction to Computational Finance and Financial Econometrics Descriptive Statistics Eric Zivot Summer 2015 Eric Zivot (Copyright © 2015) Descriptive Statistics 1 / 28

Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

You can’t see this text!

Introduction to Computational Finance andFinancial EconometricsDescriptive Statistics

Eric ZivotSummer 2015

Eric Zivot (Copyright © 2015) Descriptive Statistics 1 / 28

Page 2: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Outline

1 Univariate Descriptive Statistics

2 Bivariate Descriptive Statistics

3 Time Series Descriptive Statistics

Eric Zivot (Copyright © 2015) Descriptive Statistics 2 / 28

Page 3: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Covariance Stationarity

{. . . ,X1, . . . ,XT , . . .} = {Xt}

is a covariance stationary stochastic process, and each Xt is identicallydistributed with unknown pdf f (x).

Recall,

E [Xt ] = µ indep of t

var(Xt) = σ2 indep of t

cov(Xt ,Xt−j) = γj indep of t

cor(Xt ,Xt−j) = ρj indep of t

Eric Zivot (Copyright © 2015) Descriptive Statistics 3 / 28

Page 4: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Descriptive Statistics

Observed Sample:

{X1 = x1, . . . ,XT = xT} = {xt}Tt=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 observeddependencies in the data.

Eric Zivot (Copyright © 2015) Descriptive Statistics 4 / 28

Page 5: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Time Plots

Line plot of time series data with time/dates on horizontal axis.Visualization of data - uncover trends, assess stationarity and timedependenceSpot unusual behaviorPlotting multiple time series can reveal commonality across series

Eric Zivot (Copyright © 2015) Descriptive Statistics 5 / 28

Page 6: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Histograms

Goal: Describe the shape of the distribution of the data {xt}Tt=1

Hisogram Construction:1 Order data from smallest to largest values2 Divide range into N equally spaced bins

[−| − | − | · · · | − | − |−]

3 Count number of observations in each bin4 Create bar chart (optionally normalize area to equal 1)

Eric Zivot (Copyright © 2015) Descriptive Statistics 6 / 28

Page 7: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

R Functions

Function Descriptionhist() compute histogramdensity() 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) = 1Tb

T∑t=1

k(x − xt

b

)

k(·) = kernel function

b = bandwidth (smoothing) parameter

where k(·) is a pdf symmetric about zero (typically the standardnormal distribution). See Ruppert Chapter 4 for details.Eric Zivot (Copyright © 2015) Descriptive Statistics 7 / 28

Page 8: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

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 quartile

q.75 − q.25 = interquartile range (IQR)

Eric Zivot (Copyright © 2015) Descriptive Statistics 8 / 28

Page 9: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

R Functions

Function Descriptionsort() sort elements of data vectormin() compute minimum value of data vectormax() compute maximum value of data vectorrange() compute min and max of a data vectorquantile() compute empirical quantilesmedian() compute medianIQR() compute inter-quartile rangesummary() compute summary statistics

Eric Zivot (Copyright © 2015) Descriptive Statistics 9 / 28

Page 10: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Historical Value-at-Risk

Let {Rt}Tt=1 denote a sample of T simple monthly returns on aninvestment, and let $W0 be the initial value of an investment. Forα ∈ (0, 1), the historical VaRα is:

$W0 × qRα

qRα = empirical α · 100% quantile of {Rt}Tt=1

Note: For continuously compounded returns {rt}Tt=1 use:

$W0 × (exp(qrα)− 1)

qrα = empirical α · 100% quantile of {rt}Tt=1

Eric Zivot (Copyright © 2015) Descriptive Statistics 10 / 28

Page 11: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Sample StatisticsPlug-In Principle: Estimate population quantities using samplestatistics.

Sample Average (Mean):

1T

T∑t=1

xt = x = µx

Sample Variance:

1T − 1

T∑t=1

(xt − x)2 = s2x = σ2

x

Sample Standard Deviation:√s2x = sx = σx

Eric Zivot (Copyright © 2015) Descriptive Statistics 11 / 28

Page 12: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Sample Statistics cont.

Sample Skewness:

1T − 1

T∑t=1

(xt − x)3/s3x = skew

Sample Kurtosis:

1T − 1

T∑t=1

(xt − x)4/s4x = kurt

Sample Excess Kurtosis:

kurt − 3

Eric Zivot (Copyright © 2015) Descriptive Statistics 12 / 28

Page 13: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

R Functions

Function Package Descriptionmean() base compute sample meancolMeans() base compute column means of matrixvar() stats compute sample variancesd() stats compute sample standard deviationskewness() PerformanceAnalytics compute sample skewnesskurtosis() PerformanceAnalytics 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

Page 14: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

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:

FX (x) = 1n (#xi ≤ x)

= number of xi values ≤ xsample size

Eric Zivot (Copyright © 2015) Descriptive Statistics 14 / 28

Page 15: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Empirical Cumulative Distribution Function cont.

How to compute and plot FX (x) for a sample {x1, . . . , xn}.Sort data from smallest to largest values: {x(1), . . . , x(n)} andcompute FX (x) at these pointsPlot FX (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

Page 16: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Quantile-Quantile (QQ) Plots

A QQ plot is useful for comparing your data with the quantiles of adistribution (usually the normal distribution) that you think isappropriate for your data. You interpret the QQ plot in the followingway:

If the points fall close to a straight line, your conjectureddistribution is appropriateIf the points do not fall close to a straight line, your conjectureddistribution is not appropriate and you should consider a differentdistribution

Eric Zivot (Copyright © 2015) Descriptive Statistics 16 / 28

Page 17: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

R Functions

Function Package Descriptionqqnorm() stats QQ-plot against normal distributionqqline() stats draw straight line on QQ-plotqqPlot() car QQ-plot against specified distribution

Eric Zivot (Copyright © 2015) Descriptive Statistics 17 / 28

Page 18: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Outliers

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

Eric Zivot (Copyright © 2015) Descriptive Statistics 18 / 28

Page 19: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

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 · IQR

Extreme Outlier:

x > q.75 + 3 · IQR

x < q.25 − 3 · IQR

Eric Zivot (Copyright © 2015) Descriptive Statistics 19 / 28

Page 20: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Boxplots

A box plot displays the locations of the basic features of thedistribution of one-dimensional data—the median, the upper and lowerquartiles, outer fences that indicate the extent of your data beyond thequartiles, and outliers, if any.

R functions

Function Package Descriptionboxplot() graphics box plots for multiple serieschart.Boxplot() PerformanceAnalytics box plots for asset returns

Eric Zivot (Copyright © 2015) Descriptive Statistics 20 / 28

Page 21: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Outline

1 Univariate Descriptive Statistics

2 Bivariate Descriptive Statistics

3 Time Series Descriptive Statistics

Eric Zivot (Copyright © 2015) Descriptive Statistics 21 / 28

Page 22: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

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)}Tt=1

Scatterplot:

XY plot of bivariate data

R functions: plot(), pairs()

Eric Zivot (Copyright © 2015) Descriptive Statistics 22 / 28

Page 23: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Bivariate Descriptive Statistics cont.

Sample Covariance:

1T − 1

T∑t=1

(xt − x)(yt − y) = sxy = σxy

Sample Correlation:sxysxsy

= rxy = ρxy

Eric Zivot (Copyright © 2015) Descriptive Statistics 23 / 28

Page 24: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

R Functions

Function Package Descriptionvar() stats compute sample variance-covariance matrix

cov() stats compute sample variance-covariance matrixcor() stats compute sample correlation matrix

Eric Zivot (Copyright © 2015) Descriptive Statistics 24 / 28

Page 25: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Outline

1 Univariate Descriptive Statistics

2 Bivariate Descriptive Statistics

3 Time Series Descriptive Statistics

Eric Zivot (Copyright © 2015) Descriptive Statistics 25 / 28

Page 26: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

Time Series Descriptive Statistics

Sample Autocovariance:

γj = 1T − 1

T∑t=j+1

(xt − x)(xt−j − x) j = 1, 2, . . .

Sample Autocorrelation:

ρj = γjσ2 , j = 1, 2, . . .

Sample Autocorrelation Function (SACF):

Plot ρj against j

Eric Zivot (Copyright © 2015) Descriptive Statistics 26 / 28

Page 27: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

R Functions

Function Package Description

acf() stats compute and plotsample autocorrelations

chart.ACF() PerformanceAnalytics plot sample autocorrelationschart.ACFplus() PerformanceAnalytics plot sample autocorrelations

Eric Zivot (Copyright © 2015) Descriptive Statistics 27 / 28

Page 28: Introduction to Computational Finance and Financial ...Descriptive Statistics Observed Sample: {X 1 = x 1,...,X T = x T}= {x t}Tt =1 are observations generated by the stochastic process

You can’t see this text!

faculty.washington.edu/ezivot/

Eric Zivot (Copyright © 2015) Descriptive Statistics 28 / 28