CN4321258/ TP ISSN 10072130X 2004 26 7 COMPUTER ENGINEERING & SCIENCE Vol126,No17,2004 10072130X(2004) 0720100205 MATLAB Ξ Application of Matlab in Analysing and Modeling Financial Time Sequences 1 2, LI Xing2xu 1, CUI Jian2fu 2 ( 1., 650221;2., 650091) ( 1. Yunnan University of Finance and Economics, Kunming 650221; 2. Department of Statistics, Yunnan University, Kunming 650091, China) MATLAB, MATLAB Abstract MATLAB is an outstanding mathematical computing tool. In this paper, we expatiate how to analyze and model financial time sequences with MATLAB. ;MATLAB ; ;ARMA ; GARCH Key words financial time sequence ;MATLAB ; technical analysis ; ARMA ; GARCH O245 A 1 MATLAB MathWorks MATLAB,,, MATLAB GARCH,MATLAB, ARMAX GARCH, ;, Eviews TSP,,, MAT2, 2 LAB, GARCH Ξ 2003204223 ; 2003206220 (2000A0003M) (1966 - ),,,, ;, 650221 ;Tel (0871) 5114941 ; E2mail xingxu1967 @sina. com Address School of Statistics and Information, Yunnan University of Finance and Economics, Kunming, Yunnan 650221,P. R. China 100
,, 3 MATLAB 2. 1 ( MACD) MACD (DIF) (DEA),DIF,DEA DIF MACD, DIF DEA, ;DIF DEA, 2 IBM DIF macdts = macd(tsobj, series - name) ; tsobj,series - name ; IBM 10/ 01/ 95212/ 31/ 95 ; macd - ibm = macd(part - ibm) ; plot (macd - ibm) ; 1 rsi - ibm = rsindex(part - ibm) ; plot (rsi - ibm) ; 3 IBM 3, { y ( t) } 1 t, 1 IBM, 2. 2 ( William s %R) 3. 1 William s %R 3. 1. 1, - 100 %0 %, (Autocorrelation Function, ACF) William s %R - 20 %, Cov[ y ( t), y ( t - k) ] k =, ;William s %R - 80 % [ V ( y ( t) ) V ( y ( t - k) ) ] 1/ 2,,, wpctrts = willpctr (tsobj, nperiods) ; nperiods(, 14) ; IBM William s %R wpctr - ibm = willpctr (part - ibm) ; plot (wpctr - ibm) ;datetick(x,mm/ dd/ yy ) ; 2 2. 3 ( RSI) RSI, rsits = rsindex(tsobj, nperiods,parametername, Parameter2 Value) ; nperiods ; IBM RSI ; y (1), y (2),, y ( T),, [ACF,Lags,Bounds] = autocorr (Series,nLags,M,nSTDs) Series,nLags( ) ACF,M( ) Lags > M, ACF 0, nstds( ) ACF ACF,Lags,Bounds ACF szzs. txt, 2000 szzs = ascii2fts(szzs. txt,1,3) ; part - szzs = szzs(01/ 04/ 2000 12/ 24/ 2000 ) ; closepri = fts2mtx (part - szzs. close) ; [ ACF,Lags, Bounds ] = autocorr ( closepri, ( length (closepri) - 1) ) ; autocorr (closepri, (length(closepri) - 1) ) ; Bounds = ( - 0. 1307,0. 1307), ACF Lag 4 101
[ PartialACF, Lags, Bounds] = parcorr (Series, nlags, R, nstds) ; PartialACF ; parcorr (closepri, (length(closepri) - 1) ) ; ACF, 2000 PACF 5 1 1 AR( na) MA( nc) ARMA( na, nc) 1, MATLAB ARMA ( na, nc) 4 3. 1. 2 (Partial ACF, PACF) m = armax( data, orders) k AR( k) y ( data, orders = [ na nc ] t) = < k1, na nc ; na = 0, y ( t - 1) + + < kk y ( MA( nc),nc = 0 t - k) + t < kk, <, AR ( na) m kk, FPE Akaike Yule2Walker, 2000 ACF (4) PACF ( 5), closepri, ACF PACF logclose = log(closepri) ; subplot (2,1,1) ; autocorr (logclose) ; subplot (2, 1, 2) ; parcorr (logclose) ; 6 log (closepri) ACF, AR( na), 2,,ARIMA(2,0) M = armax(logclose,[2 0 ]) A ( q) = 1-1. 147 q - 1 + 0. 1468 q - 2 5 3. 2 na [AR ( na) ] A ( q) y ( t) = e ( t), A ( q) = 1 + a 1 q - 1 + a 2 q - 2 + + a na q - na, a i < 1, q, q - m =( y ( t) = C ( q) e ( t), C ( q) = 1 + c 1 q - 1 + + c nc q - nc, ARCH AR( na) MA ( nc), AR2 (Generalized ARCH, GARCH) (Bollerselv, MA( na, nc) A ( q) y ( t) = C ( q) e ( t) 6 closepri ACF PACF 3. 3 ARCH( q) ), q - m y ( t) = y ( t - m), e ( t) WN (0, 2 y ( t) = + t U t ),, U t, t, E { e ( t) }, ( U t ) = 0, V ( u t ) = 1, t = ( 0 + nc [MA ( nc) ] q i = 1 a i ( y ( t - i) - u) 2 ) 1/ 2,ARCH, 1986,1988) GARCH( p, q) 2 t = q i =1 a i p j =1 j 2 t - j 102 0 + 2 t - i +
, p > 0 j 0,1 j p, y ( t) = 0. 0018753 + t, 2 t - 2. 0624 e - 005, + 0. 50595 2 t - 1 + 0. 49405 2 t - 1, (3), GARCH,garchfit, GARCH (LLF) (innova2 ( Fat tions) ( sigma), garchplot Tails) (Volatility Clustering) garchplot (innovations, sigma) MATLAB GARCH 8, GARCH 2000,, plot (innovations. / sigma), (1), 9 returnmtx = price2ret (closepri) ; % Create the daily return vector returnmtx subplot (2,2,1) ; plot (returnmtx) ; title (The Daily Return ) ; subplot(2,2,2) ; autocorr ( returnmtx) ; title (ACF of Daily Re2 turn ) ; subplot (2,2,3) ; parcorr (returnmtx) ; title (PACF of the Daily Re2 turn ) ; subplot (2,2,4) ; autocorr (returnmtx.^2) ; title (ACF of the Square of Daily Return ) ; 8 7 2000 7,, ACF PACF, ACF 9, Q2 ARCH Q2 ARCH [ H,pValue, Stat, CriticalValue ] = lbqtest ( returnmtx2mean ( return2 mtx),[10 15 20 ],0. 05) [ H,pValue,Stat,CriticalValue ] = archtest ( returnmtx2mean ( return2 mtx),[10 15 20 ],0. 05) Q2 0 0. 071 4 17. 134 1 18. 307 0 0 0. 193 2 19. 469 4 24. 995 8 0 0. 058 0 30. 788 6 31. 410 4 ARCH 1. 0 0. 001 5 28. 586 8 18. 307 0 1. 0 0. 010 2 30. 505 0 24. 995 8 1. 0 0. 018 5 35. 319 0 31. 410 4, ARCH Q2 H = 0, ; ARCH H = 1, ARCH (2) [coeff, errors, LLF, innovations, sigma, summary] = garchfit (re2 turnmtx) ; garchdisp (coeff, errors) [ H,pValue,Stat,CriticalValue ] = lbqtest ( (innovations. / sigma). ^ 2,[10 15 20 ],0. 05) [ H, pvalue, Stat, CriticalValue ] = archtest (innovations. / sigma, [10 15 20 ],0. 05) ; Q2 0 0. 980 8 3. 027 6 18. 307 0 0 0. 997 3 4. 113 2 24. 995 8 0 0. 989 7 8. 300 0 31. 410 4 ARCH 0 0. 970 8 3. 386 0 18. 307 0 0 0. 995 7 4. 487 0 24. 995 8 0 0. 995 5 7. 310 9 31. 410 4 H = 0, GARCH(1,1) 4, MATLAB GARCH(1,1), 103
, AP AP, t1 m MATLAB 3, ( ),,MATLAB, [1 ] []T C Mills... 2 [M].,2002. [2 ]. MATLAB 6. 0 [M].,2001. [3 ] [] G E P Box,.. [M].,1997. ( 99 ) ( vgc) AP1 ( t1, s1, m) t ( t ) MS ( t, s) ( gm rmovem ( smove, t) AP2 ( t, s2, m) t ( vgc) AP1 ( t1, s1, m) MS ( t, s) ( gm rmovem ( smove, t) AP2 ( t, s2, m) ( vgc) gm ( smove, t) IdentAP1 ( s1, m) MS ( t, s) m ( smove, t) AP2 ( t, s2, m) ( vgc) IdentAP1 ( s1, m) MS ( t2, s) AP2 ( t2, s2, m) System2, 2 3 2 Handoff 3 Handoff 2 MS AP, ;,MS s, ( select = true), AP,, 3 t2 ;, 104 5,, 802. 11MAC,,,,, [1 ] R Milner, J Parrow, D Walker. A Calculus of Mobile Processes [A]. Information and Computation[M]. 1992. [2 ] D Sangiorgi,D Walker. The 2Calculus A Theory of Mobile Pro2 cesses[m]. Cambridge University Press, 2001. [ 3 ] R Milner. Communicating and Mobile Systems The 2Calculus [M]. Cambridge University Press, 1999. [4 ] M Abadi,A D Gordon. A Calculus for Cryptographic Protocols The Spi 2Calculus[A]. Information and Computation[M]. 1999. [5 ] L Cardelli, S D Gordon. Mobile Ambient[A]. Proc of Foundations of Software Science and Computation Structures ( ToSSaCS), Euro2 pean Joint Conf on Theory and Practice of Software[ C]. 1998. [6 ] C Fournet,G Gonthier. The Receive CHAM and the Join Calculus [ A ]. 23rd ACM Symp on Principles of Programming Languages (POPL 96) [ C]. 1996. [7 ] Engberg,Nielsen. A Calculus of Communicating Systems with Label Passing[ R ]. Research Report DAIMI PB2208, Computing Science Department,University of Aarhus,1986. [8 ] C A R Hoare. Communicating Sequential Processes[M]. Prentice2 Hall International,1985. [9 ] R Milner. Communication and Concurrency[M]. Prentice2Hall In2 ternational,1989. [10 ] IEEE 802. 11. Part 11 Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications[ S]. 1999. [11 ] IEEE. Recommended Practice for Multi2Vendor Access Point In2 teroperability via an Inter2Access Point Protocol Across Distribu2 tion Systems Supporting IEEE 802. 11 Operation[ Z]. IEEE Draft 802. 1f/ D3,2002.