那么这个文件夹出来很多年,怎么使用很多新学的学生还不会,这里只给出一个我修改的使用程序。其实严格来说不太规范的使用,因为可以按照作者的PDF说明用作者的两步法:第一步估计garch 分布函数(使用作者的文件夹里的函数,其中很多函数直接引用英国牛津大学keven sheppard 的 MFETOOLBOX 里的garch函数),那么如果需要用作者的原方法的,有必要的话我发帖 2019-002号教学。
这里是我个人使用 MATLABR R2019a ,利用官方econometric toolbox 里的garch 估计函数来修改的。请看源代码,文件名为:
garch_copula_test.m ,下划线最后test代表是我做的一个小测试。
- %% Import the Supporting Historical Dataset
- % tulips 2019年7月8日 修改
- % Load a daily historical Dataset of 3-month Euribor, the trading dates spanning
- % the interval 07-Feb-2001 to 24-Apr-2006, and the closing index levels of the
- % following representative large-cap equity indices:
- %
- % * TSX Composite (Canada)
- % * CAC 40 (France)
- % * DAX (Germany)
- % * Nikkei 225 (Japan)
- % * FTSE 100 (UK)
- clc
- clear;close all
- % Clear Up
- load Data_GlobalIdx1 % Import daily index closings
- % The next line ,chang data read for your dataset
- % [Data,~]=xlsread('YourDataset.xlsx');
- returns = price2ret(Data); % Logarithmic returns
- T = size(returns,1); % # of returns (i.e., historical sample size)
- %%
- % Since the first step in the overall modeling approach involves a repeated
- % application of GARCH filtration and Extreme Value Theory to characterize
- % the distribution of each individual equity index return series, it is
- % helpful to examine the details for a particular country. You can change the
- % next line of code to any integer in the set {1,2,3,4,5,6} to examine the
- % details for any index.
- index = 1; % 1 = Canada, 2 = France, 3 = Germany, 4 = Japan, 5 = UK, 6 = US
- figure
- plot(dates(2:end), returns(:,index))
- datetick('x')
- xlabel('Date')
- ylabel('Return')
- title('Daily Logarithmic Returns')
- %%
- % To produce a series of i.i.d. observations, fit a first order
- % autoregressive model to the conditional mean of the returns of each
- % equity index
- %
- % $r_t = c + \theta r_{t-1} + \epsilon_t$
- %
- % and an asymmetric GARCH model to the conditional variance
- %
- % $\sigma^2_t = \kappa + \alpha\sigma^2_{t-1} + \phi\epsilon^2_{t-1} + \psi[\epsilon_{t-1}<0]\epsilon^2_{t-1}$
- %
- % The first order autoregressive model compensates for autocorrelation,
- % while the GARCH model compensates for heteroskedasticity. In particular,
- % the last term incorporates asymmetry (leverage) into the variance by a
- % Boolean indicator that takes the value 1 if the prior model residual
- % is negative and 0 otherwise (see Glosten, Jagannathan, & Runkle [3]).
- %
- % Additionally, the standardized residuals of each index are modeled
- % as a standardized Student's t distribution to compensate for the fat
- % tails often associated with equity returns. That is
- %
- % $z_t = \epsilon_t/\sigma_t$ i.i.d. distributed $t(\nu)$
- %
- % The following code segment extracts the filtered residuals and conditional
- % variances from the returns of each equity index.
- model = arima('AR', NaN, 'Distribution', 't', 'Variance', gjr(1,1));
- nIndices = size(Data,2); % # of indices
- residuals = NaN(T, nIndices); % preallocate storage
- variances = NaN(T, nIndices);
- fit = cell(nIndices,1);
- options = optimoptions(@fmincon, 'Display', 'off', ...
- 'Diagnostics', 'off', 'Algorithm', 'sqp', 'TolCon', 1e-7);
- for i = 1:nIndices
- fit{i} = estimate(model, returns(:,i), 'Display', 'off', 'Options', options);
- summarize(fit{i})
- [residuals(:,i), variances(:,i)] = infer(fit{i}, returns(:,i));
- end
- %%
- % Having filtered the model residuals from each return series, standardize
- % the residuals by the corresponding conditional standard deviation. These
- % standardized residuals represent the underlying zero-mean, unit-variance,
- % i.i.d. series upon which the EVT estimation of the sample CDF tails is based.
- residuals = residuals ./ sqrt(variances);
- uData = zeros(T,nIndices); % Cell array of Pareto tail objects
- for i = 1:nIndices
- uData(:,i) = empiricalCDF(residuals(:,i));
- end
- %% TWO STEP COPULA OR COPULA VINE
- % STEP ONE (ASSUMES GARCH TYPE MARGINS). CALL:
- % specM = modelspec(rets) %Data is the Data set. Choose "GARCH model for each series"
- % and make the desired choices for the margins. Then call:
- % [parsM, LogLM, evalM, GradHessM, uData] = fitModel(specM, rets, 'fmincon');
- % if you do not care for standard errors you can use 'fmincon'. parsM
- % contains the estimated parameters, in the form of table 5, in the pdf
- % LogLM is the vector of the marginal log likelihoods at the optimum
- % evalM is a cell that contains structures
- % GradHessM is a cell that contains structures
- % uData is the matrix of sample GARCH residuals turned to uniform.
- %% STEP TWO.
- % STEP TWO.
- % Define your copula or copula vine by:
- % specC = modelspec(uData)
- % Estimate the copula parameters, by:
- % [parsC, LogLC, evalC, GradHessC] = fitModel(specC, uData, 'fminunc');
- %% STARTING VALUES
- % In case you want to estimate the same model in one step it would be wise
- % to create a vector of starting values for the one step procedure, as
- % follows:
- % p=size(uData,1);
- % p=size(parsM,1);
- % test = [reshape(parsM,[p,1]),parsC]; %p is the dimension
- % If you want to fit a copula vine you are advised to use good starting
- % values. To obtain such values, one more step is needed, prior to step two
- % call:
- specS = modelspec(uData);
- % and define the model as "copula vine sequentially"
- % Estimate the copula parameters, by:
- [parsC, LogLC, evalC, GradHessC] = fitModel(specS, uData, 'fmincon');
- % the array parsS is a good initial guess for the model parameters. Then go
- % to step two (line 18)
- %%
- % NOTES:
- % 1. Fminunc should be used when asymptotic standard errors are to be
- % computed. Fmincon is more robust than fminunc, in the sence that it
- % always converges to a solution unlike fminunc
- % 2. The estimated parameters are always ordered as in the tables in the
- % pdf. For the marginal models, the correct order is:
- % [mean parameters;GARCH parameters;marginal distribution parameters]
- % For the t DCC copula the order is
- % [copula DoF;alphaDCC;bDCC];
- % For the SJC copula the first parameter(s) always corresponds to the upper
- % tail (equation).
程序到90行那里估计了garch 边缘分布,garch为非对称gjrGARCH模型,分布为 student t 分布 。
90行后工具箱函数会弹出对话框,点第二个选项,估计copula ,其中可以设定 tvp-copula 或者 Vine copula
这里只展示边缘分布估计gjrGARCH 的估计值和一个非vine copula 的估计值。
ARIMA(1,0,0) Model (t Distribution)
Effective Sample Size: 2664
Number of Estimated Parameters: 7
LogLikelihood: 7827.51
AIC: -15641
BIC: -15599.8
Value StandardError TStatistic PValue
_____ _____________ __________ ______
Constant -0.00 0.00 -0.86 0.39
AR{1} -0.01 0.02 -0.48 0.63
DoF 8.97 1.24 7.26 0.00
GJR(1,1) Conditional Variance Model (t Distribution)
Value StandardError TStatistic PValue
_____ _____________ __________ ______
Constant 0.00 0.00 2.72 0.01
GARCH{1} 0.91 0.01 71.79 0.00
ARCH{1} 0.02 0.01 2.48 0.01
Leverage{1} 0.10 0.02 5.60 0.00
DoF 8.97 1.24 7.26 0.00
copula 估计值:
Estimation output
parameter St. Error t-stats
---------------------------------
0.1908 0.029 6.6079
0.2263 0.026 8.6863
---------------------------------
Akaike: -455.7162
BIC: -443.9410
Log Likelihood: 229.858
---------------------------------
Estimation time is 120.07 seconds
enjoyi yours: daniel tulips liu