标签:nbsp which short apply reg type repr rto ram
1. Cointegrated VAR and Vector Error Correction Model (VECM)
1.1 传统VAR要求variables是stationary,实际上不同股票会被同样基本面驱动。若按常规,在cointegrated series的背景下use first differentiate to remove unit root model会导致overdifferencing并丧失许多信息,尤其是long-term comovement of variable levels。故而使用VECM:consists of VAR model of (1) the order (p-1) on the differences of variables, and (2) an error-correction term derived from the known(estimated) cointegrating relationship。
e.g., in stock market, VECM establishes short-term relationship between stock returns, while correcting with deviation from long-term comovement of prices.
1.2 Two variable: Engle-Granger; Multivariate: Johansen procedure
1.3 Case
library(quantmod) getSymbols(‘DTB3‘, src = ‘FRED‘) getSymbols(‘DTB6‘, src = ‘FRED‘) DTB3.sub = DTB3[‘1999-03-18/2020-03-18‘] DTB6.sub = DTB6[‘1999-03-18/2020-03-18‘] plot(DTB3.sub) lines(DTB6.sub, col = ‘pink‘)
1.3.1 Mistake to Use Traditional ADF
Run linear regression to estimate cointegratign relationship. If residuals is stationary series, then the two series are cointegrated.
a = as.numeric(na.omit(DTB3.sub)) b = as.numeric(na.omit(DTB6.sub)) y = cbind(a, b) cointregr <- lm(a ~ b) r = cointregr$residuals library(urca) summary(ur.df(r,type = ‘none‘))
ADF tests indicate that NULL of unit root cannot be rejected. But in our case, conventional critical values are not appropriate, 需要修正变量。
1.3.2 Phillips and Ouliaris test (考虑了cointegration)
NULL: Two series are not cointegrated.
Result shows low p-value, indicating rejection of NULL, i.e. there exisit cointegration.
library(tseries) pocointregr <- po.test(y, demean = T, lshort = T) pocointregr$parameter
1.3.3 Johansen Procedure test
# K is lag order johansentest <- ca.jo(y, type = c(‘trace‘), ecdet = c(‘none‘), K = 2) summary(johansentest)
The test statistic for r = 0 is 113.71 > critical, indicating rejection of NULL; for r ≤ 1, cannot reject NULL. Thus, conclude that one cointegrating relationship exists.
1.3.4 Obtain VECM representation (run OLS on lagged differenced variables and the error correction term derived from previously calculated cointegrating relationship)
yJoregr = cajorls(johansentest, r = 1) yJoregr
The coefficient of error-correction term is negative: short-term deviation from long-term equilibrium level would push variables to zero-equilibrium deviation.
2. Volatility Modeling
(1) Volatility Clustering;
(2) Non-normality of Asset Returns (fat tails);
(3) Leverage Effect (σ reacts differently to positive or negative price movements, 价格下降带来的σ 变动幅度更大);
2.1 Case S&P
getSymbols(‘SNP‘,from = ‘2008-03-18‘, to = Sys.Date(), env = data_env) data_env <- new.env() snp <- do.call(merge, eapply(data_env, Cl)) head(snp) library(fImport) ret <- dailyReturn(snp$SNP.Close, type = ‘log‘) par(mfrow = c(2, 2)) acf(ret, main = ‘Return ACF‘); pacf(ret, main = ‘Return PACF‘); acf(ret^2, main = ‘Squared return ACF‘); pacf(ret^2, main = ‘Squaredreturn PACF‘); par(mfrow = c(1, 1))
We expect log returns to be serially uncorrelated, while results below the squared or absolute log returns show significant autocorrelations, which means that log returns are not correlated,but not independent.
m = mean(ret) s = sd(ret) par(mfrow = c(1,2)) hist(ret, nclass = 40, freq = F, main = ‘Return histograms‘) curve(dnorm(x, mean = m, sd = s), from = -0.3, to = 0.2, add = T, col = ‘brown‘) plot(density(ret), main = ‘Return empirical distribution‘) curve(dnorm(x, mean = m, sd = s), from = -0.3, to = 0.2, add = T, col = ‘brown‘) par(mfrow = c(1, 1))
Fat tail and excess kurtosis exisit.
kurtosis(ret)
# Zoom in fat tail plot(density(ret), main = ‘Return EDF - upper tail‘, xlim = c(0.1, 0.2), ylim = c(0, 2)) curve(dnorm(x, m, s),from = -0.3, to = 0.2, add = T, col = ‘brown‘)
# density on log-scale plot(density(ret), xlim = c(-5*s, 5*s), log = ‘y‘, main = ‘Density on log-scale‘) curve(dnorm(x, m, s), from = -5*s, to = 5*s, log = ‘y‘, add = T, col = ‘brown‘)
#qqplot depicts empirical quantiles against normal/theoretical distribution #deviations from straight line means presence of fat tails qqnorm(ret) qqline(ret)
3. Modelling Volatility
3.1 GARCH-family
Conditional σ2 given past observations is known.
3.2 Stochastic Volatility(SV)
Volatility is not measurable.
标签:nbsp which short apply reg type repr rto ram
原文地址:https://www.cnblogs.com/sophhhie/p/12515132.html