1、金融时间序列分析,陆贵斌 2012年10月,基本思路,作为引入,先搞清楚时间序列; 分析时间序列的目的:挖掘背后的规律,以利于预测未来;,内容,第3部分 Matlab时间序列分析,Matlab时间序列分析工具箱,统计工具箱 Statistics toolbox 计量工具箱 Econometric toolbox 金融工具箱 Finance toolbox,3.1 统计工具箱 Statistics toolbox,单变量随机分布单变量模拟抽样多变量随机分布Copulas模拟(暂时不讲)回归分析,单变量随机分布,disttool 演示各种随机分布图,t分布 与 Z分布,也可直接用程序,呈现随机分布
2、 x = -5:0.1:5; y = tpdf(x,5); % t 分布 z = normpdf(x,0,1); % 标准正态分布 plot(x,y,-,x,z,-.),重复抽样,randtool %可保存随机数 %后面可用,z1 = random(Normal,0,1,2,4) %2行4列 x1 =1.1650 0.0751 -0.6965 0.05910.6268 0.3516 1.6961 1.7971,多变量随机分布,mu = 2 3; SIGMA = 1 1.5; 1.5 3; %协方差矩阵 r = mvnrnd(mu,SIGMA,100); %随机数对 plot(r(:,1),r(
3、:,2),+),数据的随机拟合:单变量,dfittool,多变量随机数模拟,MU = 1 2;-3 -5; SIGMA = cat(3,2 0;0 .5,1 0;0 1); p = ones(1,2)/2; obj = gmdistribution(MU,SIGMA,p); Y = random(obj,1000); scatter(Y(:,1),Y(:,2),10,.),Copulas模拟,Copulas函数: 描述多变量间相关性; 描述边际分布。 对于非标准多元随机分布,一大难题:相互依赖性 如,Monte Carlo 模拟 相关性可能都需要从实际数据中获取。,rho = .7; Sigm
4、aDep = sigma.2 .* 1 rho; rho 1 ZDep = mvnrnd(0 0,SigmaDep,n); XDep = exp(ZDep); lot(XDep(:,1),XDep(:,2),.) axis(0 5 0 5) axis equal xlabel(X1) ylabel(X2),传统模型,用多元正态、Gamma、极值分布来描述 缺点:边际分布都是同一族类的,n = 1000; z = normrnd(0,1,n,1); hist(z,-3.75:.5:3.75),Copulas的目标,生产多元分布,存在相互依赖; 通过一定的转变方法,将各自的分布、及依赖结构分离出来
5、。Z:标准正态分布;:Z的分布函数U:Unif(0,1) 分布,u = normcdf(z); hist(u,.05:.1:.95),Copulas核心,将F分布的逆分布函数应用于(0,1)均匀随机变量上,仍然是F随机分布。,可以将它转变为gamma(2,1)分布,x = gaminv(u,2,1); hist(x,.25:.5:9.75),n = 1000; rho = .7; Z = mvnrnd(0 0,1 rho; rho 1,n); U = normcdf(Z); X = gaminv(U(:,1),2,1) tinv(U(:,2),5); scatterhist(X(:,1),X(
6、:,2),Direction,out),Copulas重要理解,Sklar(1959)定理:对于多元分布H,F、G为边际分布,则C函数存在,且唯一。 C(u,v), u=F(x), v=G(y) u,v: (0,1)2, C:(0,1) FarlieGumbelMorgenstern family copulas,若X,Y相互独立,则C=uv 若Y是X的确定函数,则 FrchetHoeffding bounds 递减型:W(u,v) = max(0,u + v 1) 递增型:M(u,v) = min(u,v) W(u,v) C(u,v)M(u,v),转换transform,two increa
7、sing transformations,为了描述这种一致性,引入rank pairs(R*,S*)经验copulas, Deheuvels(1979)可以证明:Cn是C的无偏估计量,服从正态分布。,Copulas研究现状,copulas模型的推断统计仍有待深入; 面向终端用户的应用太少,不够直观; 金融方面:Frees and Valdez 1998; Cherubini et al. 2004,Statistics Toolbox functions compute,Probability density functions (copulapdf) ,the cumulative dist
8、ribution functions (copulacdf) for Gaussian copulasRank correlations from linear correlations (copulastat) and vice versa (copulaparam)Random vectors (copularnd)Parameters for copulas fit to data (copulafit),Probability Distributions Used for Multivariate Modeling,Copulas: Generate Correlated Sample
9、s Determining Dependence Between Simulation Inputs Constructing Dependent Bivariate Distributions Using Rank Correlation Coefficients Using Bivariate Copulas Higher Dimension Copulas Archimedean Copulas Simulating Dependent Multivariate Data Using Copulas Example: Fitting Copulas to Data,回归分析,robust
10、demo,3.2 计量工具箱 Econometric toolbox,a model:面向对象(类似于结构变量),model selection,a model:adequately describes your data. 基础 for:regression inference, forecasting, and Monte Carlo simulation.Specification tests: identify data generating process. Model comparisons the fit of competing models, with penalties f
11、or complexity. Goodness-of-fit checks assess the in-sample adequacy, assumptions hold, out-of-sample forecast performance.,Model Objects, Properties, and Methods,Model Objects arima garch egarch gjr Model Properties Parametric form of the model Number of model parameters (e.g., the degree of the mod
12、el) Innovation distribution (Gaussian or Students t) Amount of presample data needed to initialize the model,A static conditional mean model:the ordinary linear regression model.A dynamic conditional mean model,p207,arima class,model objects for stationary, or unit-root nonstationary linear time ser
13、ies models. includes moving average (MA), autoregressive (AR), mixed autoregressive and moving average (ARMA), integrated (ARIMA), multiplicative seasonal models.,Specify Conditional Mean Models Using arima,arima(p,D,q),(seasonal) ARIMA model p257stationary ARMA model p283MA模型modelMA = arima(Constan
14、t,0,MA,0.8,0.5,-0.1); impulse(modelMA,30) :响应值,2012a版出错,ARMA Model,modelARMA = arima(AR,0.6,-0.3,MA,0.4);,Methods,estimate:Estimate ARIMA model parameters infer:Infer GJR model conditional variances forecast simulate,1)Simulate 500 data points from the ARMA(2,1) model simModel = arima(AR,0.5,-0.3,MA
15、,0.2,Constant,0,Variance,0.1); rng(5);Y = simulate(simModel,500); 2)Specify an ARMA(2,1) model with no constant and unknown coefficients and variance.model = arima(2,0,1);model.Constant = 0 3)Fit the ARMA(2,1) model to Y.fit = estimate(model,Y),Data Transform,Why Transform? Isolate temporal componen
16、ts of interest. Remove the effect of nuisance components (like seasonality). Make a series stationary. Reduce spurious regression effects. Stabilize variability that grows with the level of the series. Make two or more time series more directly comparable.,p122,a five-step process for identifying, s
17、electing, and assessing conditional mean models (for discrete, univariate time series data). ARMAEstablish the stationarity of your time series. ACF,PACF Identify a (stationary) conditional mean model for your data. Specify the model, and estimate the model parameters. Conduct goodness-of-fit checks
18、 to ensure the model describes your data adequately. use the model to forecast or generate Monte Carlo simulations,步骤1识别:决定模型的阶数,数据的动态特征 数据时间图,acf,pacf 步骤2估计:参数估计,OLS,极大似然估计; 步骤3检验:模型检验 过度拟合法:拟合一个更大模型,应该不显著; 残差诊断法:残差序列无线性关系,否则还有模型没有反映出来的动态特征;(acf,pacf,Ljung-Box法),ARMA模型选择的信息法则,一开始实际数据比较杂乱,acf和pacf的规
19、律不会非常简单、直观;难以选择模型; 信息准则包含: 残差平方和的函数; 由于增加额外参数所丧失的自由度的惩罚项; 增加一个新变量: 残差平方和减少 惩罚项增加 目标:使信息准则的值最小。,最常用的信息准则,赤池AIC 更具有有效性 阶数较大 Schwarz贝叶斯准则SBIC 较强一致性 渐进递归到正确的模型阶数 平均波动性较大 Hannan-Quinn准则HQIC没有一种准则明显有优势,各有特点。,画出ACF,PACF,load Data_JAustralian Y = Dataset.PAU; N = length(Y); figure(1) plot(Y)figure(2) subplo
20、t(2,1,1) autocorr(Y) subplot(2,1,2) parcorr(Y),Difference the data.,ACF线性递减,显著:非平稳 dY = diff(Y);差分后序列ACF快速衰减,PACF2阶截断;表现与AR(2)类似; Specify and fit an ARIMA(2,1,0) model. model = arima(2,1,0); fit = estimate(model,Y); coefficients are significant at the 0.05 significance level,Infer the residuals from
21、 the fitted model. Check that the residuals are normally distributed and uncorrelated.res = infer(fit,Y); plot(res./sqrt(fit.Variance) qqplot(res):正态分布对比 autocorr(res) parcorr(res),Generate forecasts and approximate 95% forecast intervals Yf,YMSE = forecast(fit,16,Y0,Y); UB = Yf + 1.96*sqrt(YMSE); L
22、B = Yf - 1.96*sqrt(YMSE); h1 = plot(Y,Color,.75,.75,.75); hold on h2 = plot(78:93,Yf,r,LineWidth,2); h3 = plot(78:93,UB,k-,LineWidth,1.5); plot(78:93,LB,k-,LineWidth,1.5);,Ljung-Box Q-Test,P136 to test for autocorrelation at multiple lags jointlyload Data_Overshort Y = Data; N = length(Y); h,p,Qstat
23、,crit = lbqtest(Y,Lags,5,10,15)h=1 1 1 significant autocorrelation,用于检验arch效应,load Data_EquityIdx; Y = Dataset.NASDAQ; r = price2ret(Y); N = length(r); e = r - mean(r); figure(2) subplot(2,1,1) autocorr(e.2) subplot(2,1,2) parcorr(e.2) h,p = lbqtest(e.2,Lags,5,10),Maximum Likelihood Estimation for C
24、onditional Mean Models p292 Estimate Conditional Mean and Variance Model p307,Specifying Static Time Series Models,Demo_StaticModels.m Specifying Static Time Series Models.pdf,Box-Jenkins Differencing vs. ARIMA Estimation,p288,generate M sample paths, each of length NMarkov Chain Monte Carlo (MCMC)
25、generate dependent random draws; The simulate method in Econometrics Toolbox generates independent realizations.Demonstrating theoretical results Forecasting future events Estimating the probability of future events,Step 1. Specify a model. model = arima(Constant,0.5,AR,0.7,0.25,Variance,.1);Step 2.
26、 Generate one sample path rng(default) :控制随机数生成模式 Y = simulate(model,50);Step 3. Generate many sample paths. Y = simulate(model,50,numPaths,1000);Step 4. Oversample the process. To reduce transient effects, (短暂的) simulate paths of length 150, and discard the first 100 observations.,Transient Effects
27、,stationary processes the impulse response function decays to zero over time.the starting point of the simulation is eventually forgotten. Oversample: generate sample paths longer than needed, and discard the beginning samples that show transient effects. Recycle: use a first simulation to generate
28、presample data for a second simulation. nonstationary processesthe starting point of the simulation is never forgotten. default: begin with 0; specify your own presample data.,没有自相关性,但是, 有相关性, 称为“serially dependent”,金融条件方差模型特征,波动聚集 Volatility clustering 原因:波动率的自相关性 杠杆效应 Leverage effects 非对称性效应:波动率对大
29、幅下跌的反应强于大幅上升(EGARCH, GJR),多元时间序列分析,3.3 金融工具箱 Finance toolbox,Hot Tip,How do I incorporate my logo to a slide that will apply to all the other slides? On the View menu, point to Master, and then click Slide Master or Notes Master. Change images to the one you like, then it will apply to all the other
30、 slides.,You can briefly add outline of this slide page in this text box.,Diagram,You can briefly add outline of this slide page in this text box.,Diagram,You can briefly add outline of this slide page in this text box.,Cycle Diagram,You can briefly add outline of this slide page in this text box.,D
31、iagram,You can briefly add outline of this slide page in this text box.,Diagram,You can briefly add outline of this slide page in this text box.,Diagram,You can briefly add outline of this slide page in this text box.,Diagram,You can briefly add outline of this slide page in this text box.,Diagram,Y
32、ou can briefly add outline of this slide page in this text box.,Diagram,You can briefly add outline of this slide page in this text box.,Table,You can briefly add outline of this slide page in this text box.,Diagram,You can briefly add outline of this slide page in this text box.,Diagram,You can bri
33、efly add outline of this slide page in this text box.,Progress Diagram,You can briefly add outline of this slide page in this text box.,Block Diagram,TEXT,TEXT,TEXT,TEXT,TEXT,TEXT,TEXT,TEXT,You can briefly add outline of this slide page in this text box.,3-D Pie Chart,You can briefly add outline of this slide page in this text box.,Table,You can briefly add outline of this slide page in this text box.,Add your company slogan,Thank You !,谢谢观赏,WPS Office,Make Presentation much more fun,WPS官方微博kingsoftwps,