risk analysis & modelling lecture 9: auto-correlated risks

41
Risk Analysis & Modelling Lecture 9: Auto- Correlated Risks

Upload: julius-price

Post on 04-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Risk Analysis & Modelling

Lecture 9: Auto-Correlated Risks

Page 2: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

http://www.angelfire.com/linux/lecturenotes

Page 3: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

What we will learn in this lecture

• We will look at a new new measure of correlation: auto-correlation

• How difference equations can be used to model complicated patterns across time

• A look at auto-correlation of volatility through ARCH, GARCH and EWMA models

• The use of VBA to build up auto-correlated sequences

Page 4: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Auto-Covariance

• Frequently we observe random sequences that have patterns across time

• One such pattern is that a high value is likely to follow a high value, and a low value is more likely to follow a low value

• These patterns across time can be measured and quantified using auto-covariance and auto-correlation

• The measurement of auto-covariance is central to the idea of forecasting.

Page 5: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Auto Covariance Calculation:

• Imagine we have a sequence of returns on a stock r

• The j th auto-covariance is measured by:

)).((1

)).((),(

jt

T

jttrjtrtjtt rr

NrrErrCov

• The jth auto-correlation is simply:

)(

),(),(

rVar

rrCovrrCorr jtt

jtt

Page 6: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Auto-Correlation and Risk• When we have auto-correlated random variables we have to

base our assessment of risk on the current sequence of events and not just on a single probability distribution

• If we want to assess worse case scenarios in the future we must take into account the direct correlations between the future and the present

• So far we have been dealing with unconditional risk: what is likely to happen in the future regardless of current patterns

• With auto-correlation we must take into account current patterns and use an estimate conditional on recent patterns or a Conditional Expectation

Page 7: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

A simple model of an auto-correlated random variable

• Imagine we have a random variable whose observation at time T is:

1. tttY

• Where is a sequence of normally distributed random variable with mean 0 (Gaussian White Noise)

• This sequence will exhibit auto-covariance between Yt and Yt-1

• It is called an MA(1) process (moving average one process)

Page 8: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Properties on MA(1)

)(.)()( 1ttt EEYE

2221

2 ).1().()( ttt EYE

21 .)).(( tt YYE

Where 2 is the variance of the Gaussian White Noise process

0)).(( jtt YYE For all j > 1

Page 9: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Forecasting a MA(1) Process• If we want to try to forecast the value for Yt+1 we need to

take into account the autocorrelation, the optimal forecast is obviously not the unconditional mean

tttY .11

• We already know the value for t since we have observed the current period so the conditional expectation of Yt+1 based on our observation of t is:

tttt EYE ..)()( 11

• Our best guess for t+1 is 0

• Note that the uncertainty of our forecast is dependant upon the variance of

Page 10: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

MA(Q) process

• We can model systems with longer sequences of autocorrelations by extending the sequence of the MA

........ 21 ttttY

• By extending the number of lags of the white noise process for the MA we increase the length of the auto-correlations

Page 11: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

The AR process• Another way of representing serially correlated random variables is

Auto Regression• The AR process represents the next value in the sequence in terms

of the previous value(s) and a white noise element.• For an AR(1) process the representation is:

ttt YcY 1.

• The AR(1) is an example of a first order difference equation

• It can be shown that if –1<<1 then the AR(1) can be represented as a restricted MA(inf) series:

...........1 3

32

21

ttttt

cY

Page 12: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Proof of MA(Inf) representation

ttt YcY 1.

121 . ttt YcY • By substitution:

tttt YcY )..( 12

22

1 ... tttt YcY

• Repeating again:

33

22

12 ..... ttttt YccY

• If || <1 then n will get smaller as n becomes larger.

Page 13: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Stationarity• Our assumption that –1<<1 is vital to the stationarity of the AR time

series• We could invert the AR into an MA because n will become small and

we can ignore it for large n• If 1 then we cannot ignore n for large n• It means that across time shocks or noise () will decay and the time

series will return to a central tendancy• If > 1 then the effect of a shock or noise compounds over time, so a

shock 10 years ago will have a bigger effect today than it did then!• Series which compound like this shoot off to infinity at the first

opportunity and are not of interest• A special case is where = 1, in this case we have a random walk• This is why sometimes a random walk is called a unit root process

Page 14: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

The problem with MA• The MA representation is powerful because it represents future

values interms of white noise with mean 0, this is very useful for forecasting

• The problem with the MA process is that we cannot directly observe the we only observe the resulting serially correlated series (Yt)

• Is it possible to represent the MA process in terms of Yt rather than in terms of the hidden ?

• It turns out that we can use an AR (auto regressive process) and a MA process interchangeably

• This transformation is closely linked to the covariance stationarity of the series

Page 15: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Invertability of a MA(1)

• It can also be shown that an MA(1) process can be inverted to an AR(inf) process• Using this inversion we can calculate the hidden terms for the MA process!• For an MA(1) process this inversion take the form, where –1<<1

1. tttY

....).().().()( 33

22

1 ttttt YYYY

....).().().()( 43

32

211 ttttt YYYY

Page 16: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Proof of AR(inf) representation

1. ttt Y

211 . ttt Y

By substitution

)..( 21 tttt YY

22

1 .).()( tttt YY

)..().()( 322

1 ttttt YYY By further substitution:

33

22

1 .).().()( ttttt YYY

Page 17: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

General Inversions of AR(n) and MA(n)

• The AR(1) and MA(1) inversions are fairly simple• To calculate AR(n) and MA(n) inversions we need to express them

as Lag Polynomials• We then need to factor the real and complex roots of the lag

polynomial• It can be thought of as factoring AR(n) into the product of a AR(1)s

and MA(n) into the product of MA(1)s• Each of these factors can then be inverted using the AR(1) and

MA(1) inversions we just looked at• It can be shown that there is an equivalence between finding the

roots of a Lag Polynomial and finding the Eigen Values of a special matrix describing difference equations

• We are not interested in this calculation!

Page 18: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Forecasting Volatility: ARCH & GARCH

• There is a lot of empirical evidence to suggest that volatility is serially correlated

• We can therefore forecast volatility more accurately than we can forecast returns

• This is important because risk is dependant upon volatility

• ARCH and GARCH are volatility forecast models• We want our estimates/forecasts of volatility to be as

accurate as possible so our estimate of risk are accurate• We intuitively expect volatility to be auto-correlated

Page 19: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

The ARCH model• ARCH stands for Auto Regressive Conditional Heteroskedasticity• A simple AR(1), ARCH(1) model is

ttt uYcY 1.• Where ut or the noise follows a process:

ttt udu 2

12 .

• Where t is a white noise process bounded from bellow by d (ie we cut the normal distribution off at –d)

• We need to do this because is t < d then ut2 could

be negative, which is obviously nonsense!

Page 20: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Back To Our Model of Returns• Our returns model can be thought of as an AR(0) or

MA(0) process (which are identical):

tt ur • Where is the mean of returns and ut is a random

normal noise with mean 0 and variance equal to the variance of returns that follows an ARCH process, we will use an ARCH(1):

ttt udu 2

12 .

• Notice that since ut has a mean zero ut2 can be thought

of as our forecast for variance (2) of returns at time t:2

12 . tt ud

tt ru

Page 21: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

ARCH Observations • Using our AR(1) to MA(inf) inversion trick:

...........1 3

32

21

2

tttt

dut

• If we take the long run expectation of or the unconditional mean by assuming all are 0

12 d

d

)1.(2

• For this reason the ARCH process is sometimes written as:

ttt uu 2

122 .)1.(

21

22 .)1.( tt u

Page 22: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Forecasting Volatility With ARCH

• We can forecast volatility by using our best estimate for the , which we expect to be 0

221 . tt d

21

22 . tt d

• Our forecasts of volatility decay toward the long run expectation for variance

2222 .. tt dd

23223 ... tt ddd

Page 23: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

ARCH ForecastsF

orec

ast

2

Time

Long Run Centre ofVariance

Initial Volatility Above Long Run Expectation

Volatility Forecast

As time progresses ourARCH forecast decays to theLong Run

Page 24: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

GARCH Model• GARCH is Generalised ARCH• GARCH can be derived from an ARCH(inf)• The forecast volatility forecast made by GARCH is

based on previous forecasts and previous observations

• GARCH(1,1) would take the form2

12

12 .. ttt u

• Where is standard normal noise N(0,1)

tttu .

2222 ).()(ttt

EuE t

Page 25: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Interpretation of GARCH• The correct interpretation of the GARCH model is that it

adapts its forecast of volatility using its previous forecast error

221

21

21

21

22 .... ttttttt uuuuu 22

12

12

122 ).().( tttttt uuuu

).()().( 21

21

2221

2 tttttt uuuu

• ut2-t

2 is the difference between our forecast of volatility and the observed volatility

• We can see that GARCH adjusts its estimates not only on previous observations but also on previous forecast errors

• GARCH automatically adjusts itself to take into account its previous errors! GARCH is self correcting!

Page 26: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Estimating ARCH and GARCH• We could estimate ARCH and GARCH in Excel• We will not be doing this but the process would be to use a

maximum likelihood methodology• We would get solve to maximise the likelihood of observing the

specified process by changing the parameters of the ARCH or GARCH model

• For GARCH(1,1) solver would maximise the Log-Likelihood by altering and

• It would find the values for andthat maximised the likelihood of observing the process for the dataset we provide

• The likelihood method is central to fitting Time Series in general

Page 27: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

EWMA Model

• The Exponentially Weighted Moving Average model is simply a weighted moving average between the current innovation ut and our previous forecast for volatility:

21

21

2 )1( ttt u

• It behaves like ARCH but is simpler

• JP Morgan uses EWMA with = 0.94 for daily volatility VAR forecasts

Page 28: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Part 2: Visual Basic For Applications

Page 29: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

What is a computer program?

• A computer program is an ordered list of instructions given to the computer

• The programming language defines the structure that this list of instructions take

• Different programming languages have different structures

• VBA is the programming language used by Excel and Microsoft office

Page 30: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

The basic building blocks

• We will divide our program into two logical blocks: operations and variables

• Variables are spaces in the computers memory where we store data

• We declare variables using the programming language and give them a unique name

• Statements are used to do things to variables and give the computer instructions

• The computer executes statements in the order they are typed in

Page 31: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Variables

• A variable is like a box with a name on it• We use this name to identify and to perform

operations on the variable• We can give a variable any name we want, we could

call it “MyVariable” or “ForecastVolatility”• Variable names cannot contain spaces• We will deal with 3 types of variables: Integers (boxes

used to store whole numbers 1,2,3), Double (boxes used to store decimal numbers 3.1416), and String (boxes used to store text such as “The Quick Fox”)

Page 32: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Creating a variable• Say we want to create a box or variable that can store a decimal

number or Double, in VBA we would write:Dim DailyReturn as Double

• Dim is short for Dimension• If we wanted to create a variable containing an Integer we would

sayDim NumberOfStudents as Integer

• If we wanted to create a variable containing a some text we would say

Dim StudentName as String • It is upto us how many variables we declare and the names we

give them!

Page 33: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Statements• A statement is a command the programmer gives

to the computer to do something• A statement must take up a single line• An example of a statement is

NumberOfStudents = 10• This would assign the number 10 to our integer

variable NumberOfStudents• Another statement would be

NumberOfStudents = NumberOfStudents * 2

• This would double the integer number currently stored in NumberOfStudents

Page 34: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

A Subroutine• We will think of a Subroutine as a mini computer program• A subroutine has a name• A subroutine consists of a series of variables and statements

that perform a task we as programmers want to explain to the computer

• A sub routine is a named list of instructions we give the computer

• Once we have created the subroutine we can tell the computer to run the instructions by saying:

Call CalculateRisk• Where CalculateRisk is the name of the subroutine

Page 35: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Declaring A Subroutine• A Subroutine is declared as follows

Sub CalculateRisk()……(INSTRUCTIONS ANDVARIABLES GO HERE!)…..End Sub

• The CalculateRisk is the name we give the list of instructions and variables

• The computer goes through the list sequentially until it sees the End Sub statement and then stops

• End Sub is the end of the list of commands

Page 36: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

A Simple Subroutine

Sub CalculateRisk() Dim Volatility as Double Dim VAR as Double Volatility = 0.03 VAR = 1.96 * Volatility

Cells(1,1) = VAREnd Sub

This subroutine first declares two variables Volatility and VAR it assigns 0.03 to Volatility then sets VAR to 1.96 * Volatility. Finally it outputs the value stored in VAR to cell A1 or Cells(1,1) of the current spread sheet

Page 37: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

More Complicated• Lets say we want to let the user of our program

type in the volatility. We use the InputBox Function built into VBA:

Sub CalculateInputRisk() Dim Volatility as Double Dim VAR as Double Dim UserInput as String UserInput = InputBox(“Input Today Volatility”) Volatility = CDbl(UserInput) VAR = 1.96 * Volatility

Cells(1,1) = VAREnd Sub

Page 38: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

The If statement• The If statement is a very powerful programming concept• It allows us to tell the program to do different things depending on the value of a variable• The simple if statement takes the form:

If VAR > 0.5 then call MsgBox(“This is too Risky”)• This if statement can be written

If VAR > 0.5 thencall MsgBox(“This is too Risky!”)

End If• This second type of statement is called a block if• More than one statement can be put between the “If VAR > 0.5 then” and “End If”• For example:

If VAR > 0.5 thencall MsgBox(“This is too Risky!”)cells(2,1) = “Risky!”

End If• This will display a MsgBox and then output the text “Risky!” to cells(2,1), or row=2 column=1 (A2)

Page 39: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

The Do While Loop• Often in a program we want to repeat a task a number of

times

• One form of loop is the Do While Loop

• Bellow is an example of a subroutine that will fill cells in column A with all the numbers between 1 and 100

Sub FillCellsUp() Dim Counter as Integer Counter = 1

Do While Counter <= 100 Cells(Counter, 1) = Counter Counter = Counter + 1 LoopEnd Sub

Page 40: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

A Function

• A function has a name and describes a sequence of statements which perform operations on some input variables and produces an output variable or answer

• An example of a function which averages 2 double variables and returns a double is

Function Average(NumOne as Double, NumTwo as Double) as DoubleAverage = (NumOne + NumTwo) / 2

End Function

• NumOne and NumTwo are the inputs and the Answer is returned by set the function name equal to a value

• Functions are very useful because they let us split up bigger programs into small sections!

Page 41: Risk Analysis & Modelling Lecture 9: Auto-Correlated Risks

Our First Useful Program!

• We will generate a serially correlated sequence of returns using an MA(1) process

• We will use a helper function I have created called BoxMuller which returns a random number sampled from a standard normal distribution

• We will use a loop to calculate a sequence of 100 variables from this sequence

• It will take abit of thought to understand all the statements but once we can we are on the way to becoming programmers!