Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第1页
Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第2页
Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第3页
Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第4页
Time Series Analysis in Finance with SAS Examples of ARIMA and GARCH.doc_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 examples 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. certainly 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, 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 have 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:options 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 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 “.sas” 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; / 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 model 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 plots 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 results 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 (table 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 differencing 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 number 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 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 brief 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 - 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; pacf - 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 - 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 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 the 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 ex 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 have 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 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 as 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 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 attached 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 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=dlaglogm1y 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;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 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 and 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 primer”, 2nd ed., i

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论