• 沒有找到結果。

第五章 結論

B. Syntax

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

28

數,適合用來解釋市場同時大漲時之報酬率相關程度,其函數形式如下:

CX,Y(u, v) = exp ( − [(−logu)1a+ (−logv)1a]a) (3) (2)Clayton copula

與 Gumbel copula 相較,Clayton copula 為較能反映左尾相關性結構之非對稱型 態的 copula 函數,對變數在分配下尾處的變化十分敏感,故能快速捕捉到下尾 相關的變化,可用於描述具下尾相關特性的變數間之相關;但對變數在分配上尾 處的變化則不敏感,僅能考量單尾極端事件發生機率。可以捕捉市場同步崩跌時 之報酬率的相關性,其函數形式如下:

CX,Y(u, v) = (u−a + v−a− 1)1a (4)

B. Syntax

1. Copula

### R code from vignette source 'nacopula-pkg.Rnw'

###################################################

### code chunk number 1: preliminaries

###################################################

op.orig <-

options(width = 70,

## SweaveHooks= list(fig=function() par(mar=c(5.1, 4.1, 1.1, 2.1))), useFancyQuotes = FALSE, prompt="R> ", continue="+ ")

Sys.setenv(LANGUAGE = "en") if(.Platform$OS.type != "windows") Sys.setlocale("LC_MESSAGES","C")

## if(Sys.getenv("USER") == "maechler")# take CRAN's version, not development one:

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

29

## require("copula", lib="~/R/Pkgs/CRAN_lib")

###################################################

### code chunk number 2: acopula-family

###################################################

require(copula)

ls("package:copula", pattern = "^cop[A-Z]") copClayton

copClayton@psi

copClayton@psiInv # the inverse of psi(), psi^{-1}

copClayton@V0 # "sampler" for V ~ F()

###################################################

### code chunk number 3: ex1-definition

###################################################

(theta <- copJoe@tauInv(0.5))

C3joe.5 <- onacopula("Joe", C(theta, 1:3))

###################################################

### code chunk number 4: ex1-str

###################################################

str(C3joe.5) # str[ucture] of object

###################################################

### code chunk number 5: ex1-U3

###################################################

require(lattice) set.seed(1)

dim(U3 <- rnacopula(500, C3joe.5))

###################################################

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

30

### code chunk number 6: ex1-splom-def (eval = FALSE)

###################################################

## splom2(U3, cex = 0.4)

###################################################

### code chunk number 7: ex1-splom

###################################################

## NB: 'keep.source=false' is workaround-a-bug-in-R-devel-(2.13.x)--- and 2 x more "splom"

print(

splom2(U3, cex = 0.4) )

###################################################

### code chunk number 8: ex1-explore1

###################################################

round(cor(U3, method="kendall"), 3)

###################################################

### code chunk number 9: ex1-explore2

###################################################

c(pnacopula(C3joe.5, c(.5, .5, .5)), pnacopula(C3joe.5, c(.99,.99,.99)))

###################################################

### code chunk number 10: ex1-explore3

###################################################

prob(C3joe.5, c(.8, .8, .8), c(1, 1, 1))

###################################################

### code chunk number 11: ex2-explore4

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

31

###################################################

c(copJoe@lambdaL(theta), copJoe@lambdaU(theta))

###################################################

### code chunk number 12: NAC_3d-ex

###################################################

( C3 <- onacopula("A", C(0.2, 1, C(0.8, 2:3))) )

###################################################

### code chunk number 13: NAC_3d-ex2

###################################################

stopifnot(identical(C3,

onacopula("A", C(0.2, 1, list(C(0.8, 2:3, list())))) ))

###################################################

### code chunk number 14: AMH-V01

###################################################

copAMH@nestConstr copAMH@V01

###################################################

### code chunk number 15: ex2-definition

###################################################

theta0 <- copClayton@tauInv(0.2) theta1 <- copClayton@tauInv(0.5) theta2 <- copClayton@tauInv(0.8) c(theta0, theta1, theta2)

C_9_clayton <- onacopula("Clayton",

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

32

C(theta0, c(3,6,1), C(theta1, c(9,2,7,5), C(theta2, c(8,4))))) C_9_clayton

###################################################

### code chunk number 16: U9-prepare-splom

###################################################

set.seed(1)

U9 <- rnacopula(500, C_9_clayton)

j <- allComp(C_9_clayton)# copula component "numbers": 1:9 but in "correct order"

(vnames <- do.call(expression,

lapply(j, function(i) substitute( U[I], list(I=0+i)))))

###################################################

### code chunk number 17: ex2-splom-def (eval = FALSE)

###################################################

## splom2(U9[, j], varnames= vnames, cex = 0.4, pscales = 0)

###################################################

### code chunk number 18: ex2-splom

###################################################

print(

splom2(U9[, j], varnames= vnames, cex = 0.4, pscales = 0) )

###################################################

### code chunk number 19: ex2-explore1

###################################################

round(cor(U9[,9],U9[,7], method="kendall"), 3)

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

33

###################################################

### code chunk number 20: ex2-explore2

###################################################

c(pnacopula(C_9_clayton, rep(.5,9)), pnacopula(C_9_clayton, rep(.99,9)))

###################################################

### code chunk number 21: ex2-explore3

###################################################

prob(C_9_clayton, rep(.8,9), rep(1,9))

###################################################

### code chunk number 22: ex2-explore4

###################################################

c(copClayton@lambdaL(theta0), copClayton@lambdaU(theta0)) c(copClayton@lambdaL(theta1), copClayton@lambdaU(theta1)) c(copClayton@lambdaL(theta2), copClayton@lambdaU(theta2))

###################################################

### code chunk number 23: outerpower-def

###################################################

str(opower)

###################################################

### code chunk number 24: opwer-def2

###################################################

thetabase <- copClayton@tauInv(.5)

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

34

(opow.Clayton <- opower(copClayton, thetabase))

###################################################

### code chunk number 25: opwer-def3

###################################################

theta0 <- opow.Clayton@tauInv(2/3) # will be 1.5 theta1 <- opow.Clayton@tauInv(.75) # will be 2

opC3 <- onacopula(opow.Clayton, C(theta0, 1, C(theta1, c(2,3))))

###################################################

### code chunk number 26: U3-ex

###################################################

U3 <- rnacopula(500, opC3) ; stopifnot(dim(U3) == c(500,3))

###################################################

### code chunk number 27: opower-splom-def (eval = FALSE)

###################################################

## splom2(U3, cex = 0.4)

###################################################

### code chunk number 28: opower-splom

###################################################

print(

splom2(U3, cex = 0.4) )

###################################################

### code chunk number 29: opower-explore1

###################################################

round(cor(U3, method="kendall"), 3)

###################################################

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

35

### code chunk number 30: opower-explore2

###################################################

rbind(th0 =

c(L = opow.Clayton@lambdaL(theta0), U = opow.Clayton@lambdaU(theta0)), th1 =

c(L = opow.Clayton@lambdaL(theta1), U = opow.Clayton@lambdaU(theta1)))

###################################################

### code chunk number 31: sessionInfo

###################################################

toLatex(sessionInfo())

###################################################

### code chunk number 32: copula-version (eval = FALSE)

###################################################

## my.strsplit( packageDescription("copula")[c("Date", "Revision")] )

###################################################

### code chunk number 33: copula-version

###################################################

pd <- lapply(packageDescription("copula")[c("Date", "Revision")], function(ch) gsub("\\$",'', ch))

cat(pd[["Revision"]], "-- ", sub("^Date: +", '', pd[["Date"]]), "\n", sep="")

###################################################

### code chunk number 34: finalizing

###################################################

options(op.orig)

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

36

###################################################

### code chunk number 35: fitCopula

###################################################

function (copula, data, method = "mpl", start = NULL, lower = NULL, upper = NULL, optim.control = list(NULL), optim.method = "BFGS", estimate.variance = TRUE)

{

if (method == "ml")

fit <- fitCopula.ml(data, copula, start, lower, upper, optim.control, optim.method, estimate.variance) else if (method == "mpl")

fit <- fitCopula.mpl(copula, data, start, lower, upper, optim.control, optim.method, estimate.variance) else if (method == "itau")

fit <- fitCopula.itau(copula, data, estimate.variance) else if (method == "irho")

fit <- fitCopula.irho(copula, data, estimate.variance) else stop("Implemented methods are: ml, mpl, itau, and irho.") fit

}

2. Contagion clc

num_target = 101;

X = Data(:,i);

Y = Data(:,j);

Sorted_X = sort(X);

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

37

Sorted_Y = sort(Y);

X_Target = linspace(prctile(X,2.5),prctile(X,97.5),num_target);

Weight = zeros(length(X),1)

%OptimalPieceNum ~= 18 if use optknt function for i = 1 : num_target

AddToTarget = 1 - (X - X_Target(i)).^2;

AddToTarget(AddToTarget < 0) = 0;

Weight = Weight + AddToTarget;

end

%Weight = ones(length(X),1);

%Local Correlation of X<-->Y (Quadratic)

%Get Function sp = m (Quadratic, local polynomial fitting) MISE_Main = zeros(length(X),1);

CurrentBandWidth = 1;

while 1 == 1

disp(CurrentBandWidth)

Vector = Sorted_X(1 : CurrentBandWidth : end);

try

sp = spap2(Vector,3,X,Y,Weight);

catch

CurrentBandWidth = CurrentBandWidth + 1;

continue end

MISE_Main(CurrentBandWidth) = sum(((fnval(sp,X)-Y).^2 + var(fnval(sp,X))).*Weight);

CurrentBandWidth = CurrentBandWidth + 1;

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

38

if (CurrentBandWidth >= length(X)) break

end end

MISE_Main(MISE_Main == 0) = Inf;

BestSplineNum_Main = find(MISE_Main == min(MISE_Main));

Vector = Sorted_X(1 : BestSplineNum_Main : end);

sp =spap2(Vector,3,X,Y,Weight);

%sp = spap2(3,3,X,Y,Weight);

%If you want to calculate the value, use fnval(sp,X_Interpolate) to get Y

%value

%If you want to see the result, use fnplt function

%Get Function Beta (differentiate function m):

sp_diff = fnder(sp);

Beta = sp_diff;

%Local Correlation of X<-->Residual variance (= VAR(Y|X = x)) (Linear,

%local polynomial fitting)

MISE_VarY = zeros(length(X),1);

CurrentBandWidth = 1;

while 1 == 1

disp(CurrentBandWidth)

Vector = Sorted_X(1 : CurrentBandWidth : end);

try

sp_VarY = spap2(Vector,2,X,(Y-fnval(sp,X)).^2,Weight); %sigma^2 catch

CurrentBandWidth = CurrentBandWidth + 1;

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

39

continue end

MISE_VarY(CurrentBandWidth) = sum(((fnval(sp_VarY,X)-(Y-fnval(sp,X))).^2 + var(fnval(sp_VarY,X))).*Weight);

CurrentBandWidth = CurrentBandWidth + 1;

if (CurrentBandWidth >= length(X)) break

end end

MISE_VarY(MISE_VarY == 0) = Inf;

BestSplineNum_VarY = find(MISE_VarY == min(MISE_VarY));

Vector = Sorted_X(1 : BestSplineNum_VarY : end);

sp_VarY = spap2(Vector,2,X,(Y-fnval(sp,X)).^2,Weight); %sigma^2

%sp_VarY = spap2(20,2,X,(Y-fnval(sp,X)).^2); %sigma^2 Std_X = std(X);

%Use this to evaluate Rho value of value x0:

Xm = prctile(X,50); %Median Beta_Xm = fnval(Beta,Xm);

Rho_Xm = (Std_X*Beta_Xm)/(Std_X^2*Beta_Xm^2 + fnval(sp_VarY,Xm)).^0.5 Sigma_Xm = fnval(sp_VarY,Xm) ^ 0.5

Xl = prctile(X,2.5); %(0.025) Beta_Xl = fnval(Beta,Xl);

Rho_Xl = (Std_X*Beta_Xl)/(Std_X^2*Beta_Xl^2 + fnval(sp_VarY,Xl)).^0.5 Sigma_Xl = fnval(sp_VarY,Xl) ^ 0.5

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

40

Z = (Rho_Xl - Rho_Xm) / (fnval(sp_VarY,Xm) + fnval(sp_VarY,Xl)).^0.5 if (Z > 1.65)

disp('Contagion') else

disp('Not Contagion') end

Journal of Financial Economics, 63, 443-494.

Arestis, P., Caporale, G.M., Cipollini, C., Spagnolo, N. (2005),“Testing for Financial

Contagion Between Developed and Emerging Markets During the 1997 East Asian Crisis,” International Journal of Finance and Economics, 10(4),

359-367.

Azad, S. (2009),“Efficiency, Cointegration and Contagion in Equity Markets:

Evidence from China,”Japan and South Korea Asian Economic Journal,23(1), 93-118.

Bradley, B. and Taqqu, M., (2005),“How to Estimate Spatial Contagion between Financial Markets,”Finance Letters, 3 (1), 64-76.

Bradley, B. and Taqqu, M., (2005),“Empirical evidence on spatial contagion between financial markets,”Finance Letters, 3 (1), 77-86.

Chancharoenchai, K. and Dibooglu, S. (2006),“Volatility Spillovers and Contagion During the Asian Crisis: Evidence from six Southeast Asian Stock Markets,”Emerging Markets Finance and Trade, 42(2), 4-17.

Chollete, L., Pena, V., and Lu, C. C. (2011),“International diversification: A copula approach,”Journal of banking and Finance, 35, 403-417.

Duan, J. C., Gauthier G., Sasseville, C., and Simonato, J. G. (2006),“No Contagion, Only Independence: Measuring Stock Market Comovements,”Journal of Finance, 57(5), 2223-2261.

Forbes, K. and Rigobon, R. (1999),“No Contagion, Only Independence: Measuring Stock Market Comovements,”Journal of Finance, 57(5), 2223-2261.

Hong, Y., Tu, J., and Zhou, G. (2007),“Asymmetries in Stock Returns: Statistical Tests and Economic Evaluation,”Journal of Multivariate Analysis, 20, 1547-1581.

Hu, L. (2006),“Dependence patterns across financial markets: a mixed copula approach,”Applied Financial Economics, 16(10), 717-729.

Joe, H. and Xu, J. J. (1996),“The Estimation Method of Inference Functions for Margins for Multivariate Models,”Technical Report, No. 166, Department of Statistics, University of British Columbia.

Joe, H. (1997), “Multivariate Models and Dependence Concept, ” London: Chapman and Hall.

‧ 國

立 政 治 大 學

N a tio na

l C h engchi U ni ve rs it y

42

Lai, Y. H. and Tseng, J. C. (2010),“The Role of Chinese Stock Market in Global Stock Markets: A safe Haven or a Hedge?”International Review of Economics and Finance, 19, 211-218.

Longin, F. A. and Solnik, B. (2001),“Extreme Correlation of International Equity Markets,”Journal of Finance, 56(2), 649-676.

Pontines, V. and Siregar, R.Y. (2009),“Tranquil and Crisis windows, heteroscedasticity, and contagion measurement: MS-VAR application of DCC procedure,”Applied Financial Economics, 19(9), 745-752.

Roncalli, T., Bouye, E., Durrleman, V., Nikeghbali, A., and Riboulet, G., (1959),“Copulas: an open field for risk management,”Warwick Business School Financial Econometrics Research Centre, Universal of Warwick, working Paper.

Ruicheng, Y., Xuezhi, Q., and Tian, C., (2009),“CDO pricing using single factor copula model with stochastic correlation and random factor loading,”Journal of Mathematical Analysis and Applications, 350(1), 73-80.

Sklar, A. (1959),“Fonctions de repartition a n dimensions et leurs marges,”Publication s de l’Institut de Statistique de l’Universite de Paris, 8, 229-231.

Steven, S. and Ng, W. L. (2009),“The Effect of Real Estate Downturn on the Link between REITs and the Stock Market,”Journal of Real Estate Portfolio Management, 15(3), 211-219.

Yiu, M. S., Ho, W.Y., and Choi, D. F. (2010),“Dynamic correlation analysis of financial contagion in Asian markets in global financial turmoil,”Applied Financial Economics, 20(4), 345-354.

相關文件