time series analysis r, Thesis of Statistics

time series analysis in R for financial data complete description with code

Typology: Thesis

2016/2017

Uploaded on 09/08/2017

anant-khandelwal
anant-khandelwal 🇮🇳

4.7

(3)

1 document

1 / 416

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download time series analysis r and more Thesis Statistics in PDF only on Docsity!

WILEY SERIES IN PROBABILITY AND STATISTICS

Established by WALTER A. SHEWHART and SAMUEL S. WILKS

Editors: David J Balding, Noel A. C. Cressie, Garrett M Fitzmaurice, Harvey Goldstein, lain M. Johnstone, Geert Molenberghs, David W Scott, Adrian F. M. Smith, Ruey S. Tsay, Sanford Weisberg Editors Emeriti: Vic Barnett, J Stuart Hunter, Joseph B. Kadane, JozefL. Teugels

A complete list of the titles in this series appears at the end of this volume.

AN INTRODUCTION TO

ANALYSIS OF FINANCIAL

DATA WITH R

Ruey S. Tsay

University of Chicago

A JOHN WILEY & SONS, INC., PUBLICATION

To Teresa

  • 1 FINANCIAL DATA AND THEIR PROPERTIES Preface xiii
    • 1.1 Asset Returns
    • 1.2 Bond Yields and Prices
    • 1.3 Implied Volatility
    • 1.4 R Packages and Demonstrations
      • 1.4.1 Installation of R Packages
      • 1.4.2 The Quantmod Package
      • 1.4.3 Some Basic R Commands
    • 1.5 Examples of Financial Data
    • 1.6 Distributional Properties of Returns
      • 1.6.1 Review of Statistical Distributions and Their Moments
    • 1.7 Visualization of Financial Data
    • 1.8 Some Statistical Distributions
      • 1.8.1 Normal Distribution
      • 1.8.2 Lognormal Distribution
      • 1.8.3 Stable Distribution
      • 1.8.4 Scale Mixture of Normal Distributions
      • 1.8.5 Multivariate Returns
      • Exercises
      • References
  • 2 LINEAR MODELS FOR FINANCIAL TIME SERIES
    • 2.1 Stationarity
    • 2.2 Correlation and Autocorrelation Function
    • 2.3 White Noise and Linear Time Series
    • 2.4 Simple Autoregressive Models
      • 2.4.1 Properties of AR Models
      • 2.4.2 Identifying AR Models in Practice
      • 2.4.3 Goodness of Fit viii CONTENTS
      • 2.4.4 Forecasting
    • 2.5 Simple Moving Average Models
      • 2.5.1 Properties of MA Models
      • 2.5.2 Identifying MA Order
      • 2.5.3 Estimation
      • 2.5.4 Forecasting Using MA Models
    • 2.6 Simple ARMA Models
      • 2.6.1 Properties of ARMA(1,1) Models
      • 2.6.2 General ARMA Models
      • 2.6.3 Identifying ARMA Models
      • 2.6.4 Forecasting Using an ARMA Model
      • 2.6.5 Three Model Representations for an ARMA Model
    • 2.7 Unit-Root Nonstationarity
      • 2.7.1 Random Walk
      • 2.7.2 Random Walk with Drift
        • 2.7.3 Trend-Stationary Time Series
        • 2.7.4 General Unit-Root Nonstationary Models
        • 2.7.5 Unit-Root Test
    • 2.8 Exponential Smoothing
    • 2.9 Seasonal Models - 2.9.1 Seasonal Differencing - 2.9.2 Multiplicative Seasonal Models - 2.9.3 Seasonal Dummy Variable
    • 2.10 Regression Models with Time Series Errors
    • 2.11 Long-Memory Models
    • 2.12 Model Comparison and Averaging - 2.12.1 In-sample Comparison - 2.12.2 Out-of-sample Comparison - 2.12.3 Model Averaging - Exercises - References
  • 3 CASE STUDIES OF LINEAR TIME SERIES
    • 3.1 Weekly Regular Gasoline Price
      • 3.1.1 Pure Time Series Model
      • 3.1.2 Use of Crude Oil Prices
      • 3.1.3 Use of Lagged Crude Oil Prices
      • 3.1.4 Out-of-Sample Predictions
    • 3.2 Global Temperature Anomalies CONTENTS ix
      • 3.2.1 Unit-Root Stationarity
      • 3.2.2 Trend-Nonstationarity
      • 3.2.3 Model Comparison
      • 3.2.4 Long-Term Prediction
      • 3.2.5 Discussion
    • 3.3 US Monthly Unemployment Rates
      • 3.3.1 Univariate Time Series Models
      • 3.3.2 An Alternative Model
      • 3.3.3 Model Comparison
      • 3.3.4 Use of Initial Jobless Claims
      • 3.3.5 Comparison
      • Exercises
      • References
  • 4 ASSET VOLATILITY AND VOLATILITY MODELS
    • 4.1 Characteristics of Volatility
    • 4.2 Structure of a Model
    • 4.3 Model Building
    • 4.4 Testing for ARCH Effect
    • 4.5 The ARCH Model
      • 4.5.1 Properties of ARCH Models
      • 4.5.2 Advantages and Weaknesses of ARCH Models
      • 4.5.3 Building an ARCH Model
      • 4.5.4 Some Examples
    • 4.6 The GARCH Model
      • 4.6.1 An Illustrative Example
      • 4.6.2 Forecasting Evaluation
      • 4.6.3 A Two-Pass Estimation Method
    • 4.7 The Integrated GARCH Model
    • 4.8 The GARCH-M Model
    • 4.9 The Exponential Garch Model
      • 4.9.1 An Illustrative Example
      • 4.9.2 An Alternative Model Form
      • 4.9.3 Second Example
      • 4.9.4 Forecasting Using an EGARCH Model
    • 4.10 The Threshold Garch Model
    • 4.11 Asymmetric Power ARCH Models
    • 4.12 Nonsymmetric GARCH Model
    • 4.13 The Stochastic Volatility Model x CONTENTS
    • 4.14 Long-Memory Stochastic Volatility Models
    • 4.15 Alternative Approaches
      • 4.15.1 Use of High Frequency Data
      • 4.15.2 Use of Daily Open, High, Low, and Close Prices
      • Exercises
      • References
  • 5 APPLICATIONS OF VOLATILITY MODELS
    • 5.1 Garch Volatility Term Structure
      • 5.1.1 Term Structure
    • 5.2 Option Pricing and Hedging
    • 5.3 Time-Varying Correlations and Betas
      • 5.3.1 Time-Varying Betas
    • 5.4 Minimum Variance Portfolios
    • 5.5 Prediction
      • Exercises
      • References
  • 6 HIGH FREQUENCY FINANCIAL DATA
    • 6.1 Nonsynchronous Trading
    • 6.2 Bid–Ask Spread of Trading Prices
    • 6.3 Empirical Characteristics of Trading Data
    • 6.4 Models for Price Changes
      • 6.4.1 Ordered Probit Model
      • 6.4.2 A Decomposition Model
    • 6.5 Duration Models
      • 6.5.1 Diurnal Component
      • 6.5.2 The ACD Model
      • 6.5.3 Estimation
    • 6.6 Realized Volatility
      • 6.6.1 Handling Microstructure Noises
      • 6.6.2 Discussion
      • Appendix A: Some Probability Distributions
      • Appendix B: Hazard Function
      • Exercises
      • References
  • 7 VALUE AT RISK
    • 7.1 Risk Measure and Coherence
      • 7.1.1 Value at Risk (VaR) CONTENTS xi
      • 7.1.2 Expected Shortfall
    • 7.2 Remarks on Calculating Risk Measures
    • 7.3 Riskmetrics
      • 7.3.1 Discussion
      • 7.3.2 Multiple Positions
    • 7.4 An Econometric Approach
      • 7.4.1 Multiple Periods
    • 7.5 Quantile Estimation
      • 7.5.1 Quantile and Order Statistics
      • 7.5.2 Quantile Regression
    • 7.6 Extreme Value Theory
      • 7.6.1 Review of Extreme Value Theory
      • 7.6.2 Empirical Estimation
      • 7.6.3 Application to Stock Returns
    • 7.7 An Extreme Value Approach to Var
      • 7.7.1 Discussion
      • 7.7.2 Multiperiod VaR
      • 7.7.3 Return Level
    • 7.8 Peaks Over Thresholds
      • 7.8.1 Statistical Theory
      • 7.8.2 Mean Excess Function
      • 7.8.3 Estimation
      • 7.8.4 An Alternative Parameterization
    • 7.9 The Stationary Loss Processes
      • Exercises
      • References
  • Index

xiv PREFACE

intensity and realized volatility. Finally, Chapter 7 studies quantitative methods for risk management, including value at risk and conditional value at risk. The chapter covers important econometric and statistical methods to assess risk, including those based on extreme value theory and quantile regression. The book contains many plots and demonstrations. The goal is to simplify the analysis of financial data and to make the results easily understandable. Like many authors, I struggle to obtain a balance between the length of the book and new develop- ments in financial econometrics. Omission of some important topics is unavoidable. There is some overlap with Analysis of Financial Time Series in coverage, but all examples are new. I like to express my sincere thanks to my wife. Without her love and support, this book could not be written. I also like to thank my children; they are my inspiration and help me editing some chapters. Many readers and students constantly give me feedback and suggestions. Their input is invaluable. Finally, I like to thank Steve Quigley, Jacqueline Palmieri and their Wiley team for their support and encouragement. The web page of the book is http://faculty.chicagobooth.edu/ruey.tsay/teaching/introTS.

R. S. T. Chicago, Illinois October 2012

FINANCIAL DATA AND THEIR

PROPERTIES

The importance of quantitative methods in business and finance has increased substantially in recent years because we are in a data-rich environment and the economies and financial markets are more integrated than ever before. Data are collected systematically for thousands of variables in many countries and at a finer timescale. Computing facilities and statistical packages for analyzing complicated and high dimensional financial data are now widely available. As a matter of fact, with an internet connection, one can easily download financial data from open sources within a software package such as R. All of these good features and capabilities are free and widely accessible. The objective of this book is to provide basic knowledge of financial time series, introduce statistical tools useful for analyzing financial data, and gain experience in financial applications of various econometric methods. We begin with the basic concepts of financial data to be analyzed throughout the book. The software R is intro- duced via examples. We also discuss different ways to visualize financial data in R. Chapter 2 reviews basic concepts of linear time series analysis such as stationarity and autocorrelation function, introduces simple linear models for handling serial depen- dence of the data, and discusses regression models with time series errors, seasonality, unit-root nonstationarity, and long-memory processes. The chapter also considers

An Introduction to Analysis of Financial Data with R , First Edition. Ruey S. Tsay. © 2013 John Wiley & Sons, Inc. Published 2013 by John Wiley & Sons, Inc.

ASSET RETURNS 3

One-Period Simple Return. Holding the asset for one period from date t − 1 to date t would result in a simple gross return

1 + Rt = P (^) t Pt − 1 or Pt = Pt − 1 ( 1 + R (^) t ). (1.1)

The corresponding one-period simple net return or simple return is

Rt = P (^) t Pt − 1 − 1 = P (^) tPt − 1 P (^) t − 1

. (1.2)

For demonstration, Table 1.1 gives five daily closing prices of Apple stock in December 2011. From the table, the 1-day gross return of holding the stock from December 8 to December 9 is 1 + R (^) t = 393. 62 / 390. 66 ≈ 1.0076 so that the corre- sponding daily simple return is 0.76%, which is (393.62-390.66)/390.66.

Multiperiod Simple Return. Holding the asset for k periods between dates tk and t gives a k -period simple gross return

1 + Rt [ k ] = Pt P (^) tk = Pt P (^) t − 1 × Pt − 1 P (^) t − 2 × · · · × Ptk + 1 Ptk = ( 1 + Rt )( 1 + Rt − 1 ) · · · ( 1 + Rtk + 1 )

=

k ∏ − 1

j = 0

( 1 + R (^) tj ).

Thus, the k -period simple gross return is just the product of the k one-period simple gross returns involved. This is called a compound return. The k -period simple net return is Rt [ k^ ]^ =^ ( Pt −^ P^ tk )/ P^ tk. To illustrate, consider again the daily closing prices of Apple stock of Table 1.1. Since December 2 and 9 are Fridays, the weekly simple gross return of the stock is 1 + Rt [5] = 393. 62 / 389. 70 ≈ 1.0101 so that the weekly simple return is 1.01%. In practice, the actual time interval is important in discussing and comparing returns (e.g., monthly return or annual return). If the time interval is not given, then it is implicitly assumed to be one year. If the asset was held for k years, then the annualized (average) return is defined as

Annualized{ R (^) t [ k ]} =

⎡ ⎣

k ∏ − 1

j = 0

( 1 + R (^) tj )

⎤ ⎦

1 / k − 1.

TABLE 1.1. Daily Closing Prices of Apple Stock from December 2 to 9, 2011 Date 12/02 12/05 12/06 12/07 12/08 12/ Price($) 389.70 393.01 390.95 389.09 390.66 393.

4 FINANCIAL DATA AND THEIR PROPERTIES

This is a geometric mean of the k one-period simple gross returns involved and can be computed by

Annualized{ Rt [ k ]} = exp

⎡ ⎣ 1 k

k^ −^1

j = 0

ln( 1 + Rtj )

⎤ ⎦ (^) − 1,

where exp( x ) denotes the exponential function and ln( x ) is the natural logarithm of the positive number x. Because it is easier to compute arithmetic average than geometric mean and the one-period returns tend to be small, one can use a first-order Taylor expansion to approximate the annualized return and obtain

Annualized{ R (^) t [ k^ ]} ≈^ 1 k

k ∑ − 1

j = 0

R (^) tj. (1.3)

Accuracy of the approximation in Equation (1.3) may not be sufficient in some appli- cations, however.

Continuous Compounding. Before introducing continuously compounded return, we discuss the effect of compounding. Assume that the interest rate of a bank deposit is 10% per annum and the initial deposit is $1.00. If the bank pays interest once a year, then the net value of the deposit becomes $1(1+0.1) = $1.1, 1 year later. If the bank pays interest semiannually, the 6-month interest rate is 10%/2 = 5% and the net value is $ 1( 1 + 0. 1 / 2 )^2 = $1.1025 after the first year. In general, if the bank pays interest m times a year, then the interest rate for each payment is 10%/ m and the net value of the deposit becomes $1( 1 + 0. 1 / m ) m^ , 1 year later. Table 1.2 gives the results for some commonly used time intervals on a deposit of $1.00 with interest rate of 10% per annum. In particular, the net value approaches

TABLE 1.2. Illustration of the Effects of Compounding: the Time Interval is 1 Year and the Interest Rate is 10% Per Annum

Number of Interest Rate Net Type Payments per Period Value

Annual 1 0.1 $1. Semiannual 2 0.05 $1. Quarterly 4 0.025 $1. Monthly 12 0.0083 $1.

Weekly 52 0.^1 52 $1.

Daily 365 0365.^1 $1. Continuously ∞ $1.