Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc

上传人:文库蛋蛋多 文档编号:3025448 上传时间:2023-03-09 格式:DOC 页数:18 大小:39KB
返回 下载 相关 举报
Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第1页
第1页 / 共18页
Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第2页
第2页 / 共18页
Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第3页
第3页 / 共18页
Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第4页
第4页 / 共18页
Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc》由会员分享,可在线阅读,更多相关《Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc(18页珍藏版)》请在三一办公上搜索。

1、Time Series Analysis in Finance with SAS Examples of ARIMA and GARCHTime Series Analysis in Finance with SASExamples of ARIMA and GARCH ByHongchao WangIn this presentation I am going to show you how to apply time series analysis in modeling financial data1. Specifically, I will work with you on exam

2、ples of simple ARIMA and GARCH models , which are widely used in the financial industry. Part I: An ARMA Model ExampleLet us first apply the ARMA to model the deflator data series . Before writing the SAS program, you may want to plot the data, which helps you observe the pattern of the data. Certai

3、nly you can plot the data with SAS program, but I would say it is easy to do it in Excel. I did the following plots with Excel, but dont worry, I will give you the SAS code for plots in the presentation, and you will understand why I used Excel. Let us take a look at them. As you can see in Figure 1

4、, the original data series is strongly trended, i.e. the mean is changing over time. Figures 2 through 4 plot the log of GNP deflator series and its first and second differences. The log of original series and first differences are obviously non-stationary, but the second differencing appears to hav

5、e rendered the series stationary. Figure 1 Quarter Data of Price Deflator Figure 2 Log Price DeflatorFigure 3 First Difference of log(Deflator) Figure 4 Second Difference of log(Deflator)With what we observed in the plots, let us now write the SAS program. Below is the code, write/copy and run it:Op

6、tions ls = 70;/this option sets the line size, which must be between 64 256)Options pagesize=55; /55 lines in each page)OPTIONS OBS=137; /read in no more than 137 lines of data, including the first line, which is usually variable names.OPTIONS ERRORS=2; /the program stops if there are more than two

7、errorsTITLE AN ARMA EXAMPLE; /this gives a title which is at the top of the outputDATA temp; / designate a work-space “temp”INFILE 'data.dat' FIRSTOBS=2; /infile indicates where the data set is and imports the file. Obviously, it is easier to have data file in the same folder with the “.sa

8、s” fileINPUT Qtr GNP M1 P; /input gives each column of data a variable name. If the data in date column is word format in stead of numbers, we should use $ after it.y=log(P); / take log of P and name it y.run;Proc arima data=temp; / yes, this is the “prototype” of ARIMA model in SASIdentify var=y; /

9、 first work on y, which means we first ran ARIMA procedure on y, i.e. calculate the ACF, PACF and etc on y.identify var=y(1); / difference the series onceidentify var=y(1,1); /consecutive differencing to obtain (1-L)2yestimate p=4 method=ml; / estimate model AR(4)estimate q=4 method=ml; / estimate m

10、odel MA(4)estimate p=2 q=3 method=ml; / estimate model ARMA(2,3)estimate p=2 q=(1,3) method=ml; /estimate model ARMA(2,3), but MA only takes on lag 1 and 3estimate p=2 q=1 method=ml; / estimate model ARMA(2,1)estimate p=2 method=ml; / estimate model AR(2)run;/ the following part is the code for plot

11、s corresponding to those I showed above proc timeplot data=temp; / timeplot function plots the data and show you the trend of the data, ie, the KO price is going up or downplot P:plot y;run;Take a look at the results in the “.lst” file. Does it make sense to you? let us discuss it. I attached the re

12、sults which I am going to talk about in the tables in Appendix. The first 24 autocorrelations of the log of the price deflator series are shown in Table 1 of Appendix. The autocorrelations of the original series show the signature of a strongly trended, non-stationary series. The first difference (T

13、able 2) also exhibits non-stationarity, because the autocorrelations are still very large after a lag of 10 periods. The second difference (Table 3) appears to be stationary, with mild negative autocorrelation at the first lag, but essentially none after that. Intuition might suggest that further di

14、fferencing would reduce the autocorrelation further, but it would be incorrect, which can be shown statistically. Just keep in mind that in the real life you almost never difference a time series data more than twice. Before the estimation can begin, we need to decide on (identify) the specific numb

15、er and type of ARIMA parameters to be estimated. The major tools used in the identification phase are plots of the series, correlograms of auto correlation (ACF), and partial autocorrelation (PACF). The decision is not straightforward and in less typical cases requires not only experience but also a

16、 good deal of experimentation with alternative models. However, a majority of empirical time series patterns can be sufficiently approximated using one of the 5 basic models that can be identified based on the shape of the autocorrelogram (ACF) and partial auto correlogram (PACF). The following brie

17、f summary is based on practical recommendations of Pankratz (1983). Also, note that since the number of parameters (to be estimated) is almost never greater than 3 or 4, it is often practical to try alternative models on the same data. One autoregressive (p) parameter: ACF - exponential decay; PACF

18、- spike at lag 1, no correlation for other lags. Two autoregressive (p) parameters: ACF - a sine-wave shape pattern or a set of exponential decays; PACF - spikes at lags 1 and 2, no correlation for other lags. One moving average (q) parameter: ACF - spike at lag 1, no correlation for other lags; PAC

19、F - damps out exponentially. Two moving average (q) parameters: ACF - spikes at lags 1 and 2, no correlation for other lags; PACF - a sine-wave shape pattern or a set of exponential decays. One autoregressive (p) and one moving average (q) parameter: ACF - exponential decay starting at lag 1; PACF -

20、 exponential decay starting at lag 1. Since we believe that the series differenced twice (or after two consecutive differences) is stationary, we observe the ACF (see Table 3) and PACF (see Table 4) to identify the possible model(s) we can try and test.From the ACF, MA(3) is identified and AR(2) is

21、identified from the PACF (although AR(13) is possible). The model can possibly be ARMA(3,2). Furthermore, the estimation of MA(4) (see Table 5) shows that the fourth MA parameter is not significant at all. But the third MA is marginally significant. The estimation of AR(4) (see Table 5) shows that t

22、he last two AR parameters are not significant. Now we can estimate either AR(2) or MA(3). The parameters estimated should be significant and the residuals must be a white noise series to claim the model is adequate. If there are two (or more) competing models, then we may want to investigate their e

23、x post forecast performance to decide which model is better. Once we try ARMA(2,3) by estimating all three MA parameters (with p=2, q=3), MA parameters are not significant. We end up having AR(2) as the best model (see Table 6).Now you shall understand that when you write a SAS code like this, you h

24、ave to work back and forth to check which model works and which not, if not, find out where you can improve and come back with the improved one, then run and check again, until you get the model you feel comfortable with. Dont be frustrated, remember that is the fun part of modeling in the real life

25、 after you get such a job.Part II: An ARCH(1) Model ExampleNow, let me briefly introduce the ARCH(1) technique. We work on the same data set and fit the following “simplistic” model to demonstrate the computation. where dlogPt is the quarterly rate of change in the log of the price level, measured a

26、s 100(logPt logPt-1); dlog M1t is the rate of growth of the money stock, measured by M1; and dlogYt is the quarter rate of the growth in the output, measured by GDP. The excess growth of the money stock is measured directly and is included in the regression. The lagged value of the inflation rate (I

27、 assume) will carry the effects of previous external shocks of the economy. New shocks will be part of the disturbance. I will first give you the SAS code, and then use the four-step approach to show you how to complete the analysis. Be ready to refer to the SAS code, four-step approach, and attache

28、d print-outs back and forth, which is the best way to understand the materials. OPTIONS OBS=137;OPTIONS ERRORS=2;DATA temp;INFILE 'data.dat' FIRSTOBS=2;INPUT Qtr Y M1 P;lagP=lag1(P); /lag( ), a function which takes the previous value of yt, i.e., yt-1. lag1( ), one step back; lag2( ), two

29、step back)dlogP=100*(log(P)-log(lagP); / log(P) create a new variable which is the log of PdlaglogP=lag1(dlogP);lagM1=lag1(M1);dlogM1=100*(log(M1)-log(lagM1);lagY=lag1(Y);dlogY=100*(log(Y)-log(lagY);dlogM1Y=dlogM1-dlogY;dlaglogM1Y=lag1(dlogM1Y);run;/* step 1 */proc reg data=temp;ols: model dlogP=dla

30、glogM1Y dlaglogP; / “ols:” names the print-out of this partoutput out=tempRes R=Res; / calls out the residuals of this modelrun;/* step 2 */data temp2;set tempRes; / include data in tempRers (the residuals) into temp2 data seteSqr=Res*Res; / eSqr is the square of the residuallag_eSqr=lag1(eSqr); run

31、;proc reg data=temp2;sqr_res: model eSqr=lag_eSqr; run;/* step 3 and 4 */proc print data=temp2; / if you want to know whats in the data set now, use this proc autoreg data=temp2; / proc autoreg and garch=(q=1) below is for ARCH(1)model dlogP=dlaglogM1Y dlaglogP/garch=(q=1); / ARCH(1)run;Here is the

32、four-step procedure to implement the simple ARCH(1) method in SAS. Ordinary least squares (Refer to Appendix Table 7) Regression of squared residual obtained from the about OLS regression on a constant and lagged value (Appendix Table 8)= 0.16402 + 0.12662 On the output, ARCH0 is the constant term a

33、nd ARCH1 is the coefficient of the square of the lagged residual term. The ARCH(1) model is (Table 9)= 0.1665 + 0.1031 The estimated regression now is (Table 9) Reference:/.statsoft3/textbook/sttimser.htmlW. Greene, “Econometric Analysis”, Prentice Hall.Other useful sources: “Little SAS Book: A Prim

34、er”, 2nd Ed., ISBN: 1580252397, Author: Lora 7D. Delwiche,Susan J. Slaughter, November 1998./support.sas/91doc/docMainpage.jsp/support.sas/techsup/tnote/tnote_cindex.html/.sas/ APPENDIX Table 1 APPENDIX Table 2 APPENDIX Table 3 APPENDIX Table 4 APPENDIX Table 5 APPENDIX Table 6 APPENDIX Table 7 APPE

35、NDIX Table 8 APPENDIX Table 9 Here I assume you have some basic knowledge of Time Series analysis. In the paper you may find that I use ARIMA and ARMA interchangeably, but you shall be aware of the difference between them. I attached the data file which well work on. The data are quarterly observati

36、ons on US GDP and the implicit price deflator. Here I just showed you how to implement ARCH(1) within SAS without the consideration of the statistical fitness. In fact, for those interested, you can calculate the Lagrange Multiplier (LM) statistic and see if there are ARCH effects in the residuals. Under the null hypothesis of conditional homoscedasticity, (T-1) times the R-square in the regression of Step 2 is a LM statistic whose limiting distribution is chi-square with one degree of freedom. PAGE 4 PAGE 15

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教育教学 > 成人教育


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号