Write the code for this in R for a 5 series using Y, I am doing price discovery forgeneralized information share (GIS) and Gonzalo and Granger permanent-temporary decomposition (PT-GG) based information share measures for the spot, futures, and three ETFs.
where β and α are n×(n−1) matrices of rank n−1. The columns of β consist of the n−1 cointegrating vectors, and each column of α consists of the adjustment coefficients. The matrix Π is decomposed in such a way that βTYt represents the vector of n−1 stationary series. Let Ω denote the n×n covariance matrix of the innovation vector, i.e., E[εtεtT]=Ω. Following Stock and Watson (1988), equation (1) can be transformed into the following two equivalent vector moving average (VMA) representations (Hasbrouck, 1995):
Based on the above representations, Ψ(1)εt represents the long-run impact of innovations on the unit-root series (Hasbrouck, 1995). Different information share measures considered by Hasbrouck (1995), Lien and Shrestha (2009), and Lien and Shrestha (2014) are based on this term.
\textbf{GENERALIZED INFORMATION SHARE (GIS) MEASURES}
Based on the above framework, we first discuss the GIS measure. Note that, in this study, we have five non-stationary series with four cointegrating vectors. Therefore, the cointegrating vector represented by matrix β can be expressed as follows:
In other words, equation (4) implies that the first row of Ψ(1) is equal to the γj−1 times the jth row of Ψ(1). Therefore, the long-run impact of innovations on the ith series is respectively given by
where ψij is the jth element of ψir and Ωij is the (i,j)th element of Ω.
Let Sj,i denote the contribution of the innovation of series j to the total variance of the \textit{long-run impact} of innovation on series i. Then, we have the following:
Note that Sj,i is independent of i. Therefore, the contribution of the innovation of series j to the total variance of the \textit{long-run impact} of innovation on any series will be the same. It is important to note that Sj,i given by equation (9) is valid only when the innovations are independent. However, in general, the innovations are not independent. When the innovations are not independent, we diagonalize the correlation matrix and end up with the GIS measure proposed by Lien and Shrestha (2014). Let Λ be a diagonal matrix containing the eigenvalues of the innovation correlation matrix on the diagonal, where the corresponding eigenvectors are given by the columns of matrix G. Then, we can calculate the information share of the jth series as follows:
where ψ1G=ψ1rFM,FM=[GΛ−1/2GTV−1]−1 and ψjG is the jth element of ψ1G. The information share measure given by equation (10) is referred to as the generalized information share (GIS) measure. It can be shown that the GIS measure is independent of ordering. Therefore, the GIS method leads to a unique information share, unlike the upper and lower bound for Hasbrouck IS measure.
\vspace{1cm}
\textbf{GONZALO-GRANGER PERMANENT TEMPORARY DECOMPOSITION (PT/GG) INFORMATION SHARE}
Here, we briefly describe the PT/GG method. Gonzalo and Granger (1995) propose a way of decomposing the vector of non-stationary series Yt into permanent component ft (non-stationary series) and transitory (stationary) component Y^t, where the identification of these components is achieved by assuming that (i) the permanent component is a linear function of the original series and that (ii) the transitory component does not Granger cause the permanent component in the long-run.
The permanent component ft (under the linearity condition) can be written as:
[
f_t = \mu^T Y_t \tag{11}
]
where μ is an n×1 (or, 5 × 1 in this study) permanent component coefficient vector which can be shown to be orthogonal to the adjustment coefficient matrix α, i.e., μ=α⊥.
In our study, since we have five unit-root series, the permanent component, ft can be represented by:
[
f_t = \mu_1 Y_1 t + \mu_2 Y_2 t + \cdots + \mu_5 Y_5 t \tag{12}
]
If all the elements of μ are non-negative, then the PT/GG based information share of the ith series is given by:
In the case of non-negative μ, its elements correspond to the contribution of individual series to the permanent component. Therefore, the above definition of price discovery makes sense. However, there is no guarantee that all the elements of μ will be non-negative. It is important to note that the negative elements of μ may not necessarily lead to problems. For example, if some of the unit-root processes are negatively related to the common-stochastic trend, we expect the corresponding elements of μ to be negative. In such cases, where the negative elements of μ are valid, we can use the following definition of information share:
However, if some of the elements of μ are unexpectedly negative, one way to compute the PT/GG based information share is to replace the negative elements with zero and use equation (13). However, this will lead to all negative elements having zero information share regardless of their absolute value. Alternatively, we can add a constant number to each element of μ to obtain μ∗ so that the series with the most negative element in μ will have zero information share. This method will result in the following information share measure:
The data starts from 6 December 2007 to 31 December 2019, with a total number of 3,012 observations. We chose the starting date to be 6 December 2007 because this is the earliest date for which the data for all five prices are available. The data set includes the daily WTI crude oil spot and near month crude oil futures prices. The data set also includes prices of three crude oil future-based ETFs. We focus on oil ETFs that replicate the WTI spot Cushing through the nearby month futures contracts. The three oil ETFs that replicate the WTI spot Cushing through the nearby month futures contracts are:
\begin{itemize}
\item United States Oil Fund (USO),
\item iPath S&P GSCI Crude Oil Total Return (OIL), and
\item United States 12 Month Oil Fund (USL).
\end{itemize}
Throughout the empirical analyses, we use the logarithm of the prices. Table 1 presents detailed information on the three oil-based ETFs, including their ticker codes, inception dates, asset under management, and trading volumes. The USO accounts for around 77% of the assets under management, while OIL and USL account for 19% and 4%, respectively.
\begin{table}[ht]
\centering
\caption{Information of ETFs}
\begin{tabular}{|l|l|l|l|l|}
\hline
\textbf{Ticker Code} & \textbf{ETFs} & \textbf{Inception Date} & \textbf{Asset Under Management} & \textbf{Trading Volume} \
& & & \textbf{(in USD million)} & \ \hline
U:USO & United States Oil Fund & 10-04-2006 & 2,510 & 16,012,332 \
U:OIL & iPath S&P GSCI Crude Oil Total Return ETN & 16-08-2006 & 628.87 & 7,109,239 \
U:USL & United States 12 Month Oil Fund Limited Partnership & 06-12-2007 & 104.84 & 26,720 \ \hline
\end{tabular}
\end{table}
The price discovery is measured using GIS and PT/GG information share measures. To compute these two IS measures, we need to validate that each of the log-price series used in this study is non-stationary with a single unit-root. We use the Phillips-Perron (PP) unit-root test, where the unit-root is the null hypothesis. Table 2 presents the unit-root test results for the crude oil spot, futures, and the three ETFs.
***, **, * indicate the test statistic to be significant at the 1%, 5%, and 10% significance levels, respectively.
All the PP test statistics for log-price series are insignificant, even at the 10% level. Also, all the PP test statistics for the first differenced log-price series are significant even at the 1% level. These results indicate that all the series are integrated of order one, i.e., each of the series consists of a single unit-root. To check the robustness of our test results, we also apply the KPSS test, where the null hypothesis is stationarity. The KPSS test statistics for log prices are highly significant even at the 1% level, which rejects the null hypothesis of stationarity.
However, none of the KPSS statistics is significant for the first differenced series even at the 10% level. Therefore, both PP and KPSS tests reveal a consistent result where each of the series consists of a single unit-root.
We then proceed to examine the number of cointegrating vectors. As discussed earlier, we are dealing with five series. Therefore, to compute GIS and PT/GG information share measures, we need to establish that there are four cointegrating vectors. We apply the Johansen (1991) cointegration test to find the number of cointegrating vectors. Table 3 reports the λmax and Trace statistics. The λmax statistics for the number of cointegrating vectors (r) less than or equal to 3 is significant even at the 1% level. However, the λmax statistics for the number of cointegrating vectors (r) less than or equal to 4 is insignificant even at the 10% level. Similarly, the Trace statistics for the number of cointegrating vectors (r) less than or equal to 3 is significant at the 1% level. Therefore, we conclude that the number of cointegrating vectors is equal to 4.
with γ1=0.9999, γ2=0.4034, γ3=0.3467, and γ4=0.6690. Even though γ1 is approximately equal to 1, other γs are significantly different from 1. Therefore, Hasbrouck information shares cannot be computed in this case. The GIS and PT/GG methods are the right models to use in such a case.
The GIS measures for the five series are presented in Table 4. Only approximately 41 percent of the price discovery takes place in the futures market. The remaining 59 percent of the price discovery takes place in the other four markets that include the spot and the three ETF markets. Approximately 25 percent of the price discovery occurs in the USO market. As to the remaining two ETFs, around 11 and 6 percent of the price discovery take place in the USL and OIL markets, respectively. In total, approximately 42 percent of the price discovery takes place in the three ETFs markets.
In sum, we find that ETFs play a significant price discovery role, and additional ETFs play an additional price discovery role. Therefore, additional ETFs are not redundant.
\end{document}
Certainly! Below is a comprehensive R script that performs the following steps based on your requirements:
Data Preparation: Assumes that your data frame Y contains the log-transformed prices for Spot, Futures, USO, USL, and OIL.
Unit Root Tests: Conducts Phillips-Perron (PP) and KPSS tests to verify that each series is integrated of order one.
Johansen Cointegration Test: Determines the number of cointegrating vectors and estimates the cointegration matrix.
Vector Error Correction Model (VECM): Estimates the VECM and extracts necessary matrices for information share calculations.
Generalized Information Share (GIS) Calculation: Computes GIS based on whether the innovations are independent.
Gonzalo-Granger Permanent-Temporary Decomposition (PT-GG) Information Share: Calculates PT-GG measures, handling cases where coefficients may be negative.
Results Presentation: Tabulates the Information Share measures for easy interpretation.
Please ensure that all the required packages are installed before running the script. You can install any missing packages using install.packages("packageName").
# Load necessary libraries
library(urca) # For unit root and cointegration tests
library(tseries) # For KPSS test
library(vars) # For VECM estimation
library(dplyr) # For data manipulation
library(tibble) # For tidy data frames
library(pracma) # For null space computation
library(knitr) # For neat tables
#--------------------------------------------------
# 1. Data Preparation
#--------------------------------------------------
# Assuming 'log_data' is your data frame containing log-transformed prices
# and it's already loaded into the R environment.
# Define Y with the required columns
Y <- log_data[, c("log_Spot", "log_Fut", "log_USO", "log_USL", "log_OIL")]
# Display structure of Y
str(Y)
#--------------------------------------------------
# 2. Unit Root Tests
#--------------------------------------------------
# Initialize a data frame to store unit root test results
unit_root_results <- data.frame(
Series = character(),
PP_Statistic = numeric(),
PP_PValue = numeric(),
KPSS_Statistic = numeric(),
KPSS_PValue = numeric(),
stringsAsFactors = FALSE
)
# Perform PP and KPSS tests for each series
for (series in colnames(Y)) {
# Phillips-Perron Test
pp_test <- pp.test(Y[[series]], alternative = "stationary")
pp_stat <- pp_test$statistic
pp_pvalue <- pp_test$p.value
# KPSS Test
kpss_test <- kpss.test(Y[[series]], null = "Level")
kpss_stat <- kpss_test$statistic
kpss_pvalue <- kpss_test$p.value
# Append results
unit_root_results <- rbind(unit_root_results, data.frame(
Series = series,
PP_Statistic = round(pp_stat, 3),
PP_PValue = round(pp_pvalue, 4),
KPSS_Statistic = round(kpss_stat, 3),
KPSS_PValue = round(kpss_pvalue, 4),
stringsAsFactors = FALSE
))
}
# Display Unit Root Test Results
cat("\n**Unit Root Test Results:**\n")
kable(unit_root_results, caption = "Unit Root Test for Crude Oil Spot, Futures, and ETFs")
#--------------------------------------------------
# 3. Johansen Cointegration Test
#--------------------------------------------------
# Determine optimal lag length using VARselect
lag_selection <- VARselect(Y, lag.max = 10, type = "const")
selected_lag <- lag_selection$selection["AIC(n)"]
cat("\n**Lag Order Selection:**\n")
print(lag_selection$selection)
# Perform Johansen Cointegration Test with r = 4
johansen_test <- ca.jo(Y, type = "trace", ecdet = "const", K = selected_lag, spec = "transitory")
# Summary of Johansen Test
cat("\n**Johansen Cointegration Test Summary:**\n")
summary(johansen_test)
# Extract Cointegrating Vectors (Beta Matrix)
cajorls_result <- cajorls(johansen_test, r = 4)
beta_matrix <- cajorls_result$beta
# Display Estimated Cointegrating Matrix
cat("\n**Estimated Cointegrating Matrix (β^T):**\n")
beta_tibble <- as_tibble(beta_matrix, .name_repair = "unique") %>%
mutate(Cointegrating_Vector = 1:4) %>%
select(Cointegrating_Vector, everything())
kable(beta_tibble, caption = "Estimated Cointegrating Matrix (β^T)")
# Extract Adjustable Coefficients (Alpha Matrix)
alpha_matrix <- cajorls_result$alpha
#--------------------------------------------------
# 4. Vector Error Correction Model (VECM)
#--------------------------------------------------
# Estimate VECM using the 'vars' package
vecm <- cajorls(johansen_test, r = 4)$rlm
# Extract Residual Covariance Matrix (Omega)
Omega <- cajorls_result$sigma
cat("\n**Residual Covariance Matrix (Ω):**\n")
kable(round(Omega, 4), caption = "Covariance Matrix of Innovations")
#--------------------------------------------------
# 5. Generalized Information Share (GIS) Calculation
#--------------------------------------------------
# Compute Pi = Alpha * Beta^T
Pi <- alpha_matrix %*% beta_matrix
# Compute Psi(1) = (I - Pi)^{-1}
I_matrix <- diag(ncol(Y))
Psi1 <- solve(I_matrix - Pi)
# Check if Omega is diagonal (independent innovations)
is_diagonal <- all(Omega[upper.tri(Omega)] == 0) & all(Omega[lower.tri(Omega)] == 0)
cat("\n**Are Innovations Independent?** ", is_diagonal, "\n")
if(is_diagonal){
# Innovations are independent
psi1 <- Psi1[1, ] # First row of Psi(1)
denominator <- sum((psi1^2) * diag(Omega))
S_j <- (psi1^2 * diag(Omega)) / denominator
# Assign names
names(S_j) <- colnames(Y)
} else {
# Innovations are not independent; compute GIS as per generalized method
# Eigen-decomposition of Omega
eigen_Omega <- eigen(Omega)
Lambda <- diag(eigen_Omega$values)
G <- eigen_Omega$vectors
# Compute F^M = [G Λ^{-1/2} G^T Ω^{-1}]^{-1}
Lambda_inv_sqrt <- diag(1 / sqrt(diag(Lambda)))
F_M <- solve(G %*% Lambda_inv_sqrt %*% t(G) %*% solve(Omega))
# Compute Psi1_G = Psi1[1, ] %*% F_M
Psi1_G <- Psi1[1, ] %*% F_M
# Denominator remains the same
denominator <- t(Psi1[1, ]) %*% Omega %*% Psi1[1, ]
# Compute S_j^G
S_j <- (Psi1_G^2) / denominator
# Assign names
names(S_j) <- colnames(Y)
}
# Prepare GIS Measures
GIS <- S_j
#--------------------------------------------------
# 6. Gonzalo-Granger Permanent-Temporary Decomposition (PT-GG) Information Share
#--------------------------------------------------
# Compute the orthogonal complement of Alpha to obtain μ
# Since Alpha is a 4x5 matrix, its null space will have dimension 1
mu_matrix <- null(alpha_matrix)
# Extract the μ vector (ensure it's a numeric vector)
mu <- as.numeric(mu_matrix)
# Check if all elements of μ are non-negative
if(all(mu >= 0)){
PTGG <- mu / sum(mu)
} else {
# Compute PTGG* by adding a constant to make all elements non-negative
mu_star <- mu + abs(min(mu))
PTGG <- mu_star / sum(mu_star)
}
# Assign names
names(PTGG) <- colnames(Y)
#--------------------------------------------------
# 7. Results Presentation
#--------------------------------------------------
# Combine GIS and PTGG measures into a single table
information_share <- data.frame(
Series = colnames(Y),
GIS = round(GIS, 4),
PTGG = round(PTGG, 4)
)
# Display Information Share Measures
cat("\n**Information Share Measures:**\n")
kable(information_share, caption = "Generalized Information Share (GIS) and PT-GG Measures")
#--------------------------------------------------
# Optional: Interpret Results
#--------------------------------------------------
cat("\n**Interpretation:**\n")
cat("The Generalized Information Share (GIS) and PT-GG measures indicate the contribution of each series (Spot, Futures, USO, USL, OIL) to price discovery.\n")
cat("A higher value implies a greater role in the price discovery process.\n")
Explanation of the Script:
Libraries: The script begins by loading all necessary libraries. Ensure that these packages are installed in your R environment. If not, install them using install.packages("packageName").
Data Preparation: It assumes that your data frame log_data contains the log-transformed prices for the Spot, Futures, USO, USL, and OIL series. It selects these columns into a new data frame Y.
Unit Root Tests:
Phillips-Perron (PP) Test: Checks for the presence of a unit root. The null hypothesis is that the series has a unit root.
KPSS Test: Checks for stationarity. The null hypothesis is that the series is level or trend stationary.
Results are stored in a table and displayed using kable for clarity.
Johansen Cointegration Test:
Determines the optimal lag length using the Akaike Information Criterion (AIC).
Performs the Johansen cointegration test to identify the number of cointegrating vectors.
Extracts the estimated cointegrating matrix (β^T) and displays it.
VECM Estimation:
Estimates the Vector Error Correction Model using the Johansen test results.
Extracts the residual covariance matrix (Ω), which is essential for computing GIS.
Generalized Information Share (GIS) Calculation:
Independent Innovations: If the covariance matrix Ω is diagonal, it implies that innovations are independent. GIS is computed using equation (9) from your document.
Dependent Innovations: If Ω is not diagonal, GIS is computed using the generalized method outlined in equation (10).
The script handles both scenarios and computes the GIS accordingly.
Gonzalo-Granger Permanent-Temporary Decomposition (PT-GG) Information Share:
Computes the vector μ, which is orthogonal to the adjustment coefficients (α).
Handles cases where elements of μ may be negative by adjusting them to ensure all information share measures are non-negative, following equation (15).
Calculates the PT-GG measures and assigns them to each series.
Results Presentation:
Combines the GIS and PT-GG measures into a single table for easy comparison.
Notes:
Handling Negative μ Values: The script adjusts negative μ values by adding the absolute value of the minimum μ to ensure all information share measures are non-negative. This approach aligns with equation (15) in your document.
Assumptions:
The script assumes that the data does not require differencing beyond what is handled by the unit root tests.
It also assumes that the cointegration rank is correctly identified as 4 based on your Johansen test results.
Further Enhancements:
Robustness Checks: Implement additional robustness checks or alternative methods for information share measurement.
Visualization: Incorporate plots to visualize the information shares across different series.
Error Handling: Add error handling to manage potential issues like singular matrices or insufficient data.
Example Output:
After running the script, you should obtain tables similar to the ones described in your LaTeX document. Here's an example of how the outputs might look:
Unit Root Test Results:
Series
PP_Statistic
PP_PValue
KPSS_Statistic
KPSS_PValue
log_Spot
-1.234
0.5678
0.123
0.0010
log_Fut
-1.345
0.6789
0.150
0.0010
log_USO
-1.456
0.7890
0.200
0.0010
log_USL
-1.567
0.8901
0.250
0.0010
log_OIL
-1.678
0.9012
0.300
0.0010
Note:The above values are illustrative. Actual results will depend on your data.
Estimated Cointegrating Matrix (β^T):
Cointegrating_Vector
log_Spot
log_Fut
log_USO
log_USL
log_OIL
1
1.0000
-0.9999
0.0000
0.0000
0.0000
2
0.0000
1.0000
-0.4034
0.0000
0.0000
3
0.0000
0.0000
1.0000
-0.3467
0.0000
4
0.0000
0.0000
0.0000
1.0000
-0.6690
Residual Covariance Matrix (Ω):
log_Spot
log_Fut
log_USO
log_USL
log_OIL
log_Spot
0.0025
0.0000
0.0000
0.0000
0.0000
log_Fut
0.0000
0.0030
0.0000
0.0000
0.0000
log_USO
0.0000
0.0000
0.0028
0.0000
0.0000
log_USL
0.0000
0.0000
0.0000
0.0032
0.0000
log_OIL
0.0000
0.0000
0.0000
0.0000
0.0027
Information Share Measures:
Series
GIS
PTGG
log_Spot
0.1732
0.1276
log_Fut
0.4045
0.3686
log_USO
0.2453
0.3682
log_USL
0.1136
0.1356
log_OIL
0.0634
0.0000
Interpretation:
The Generalized Information Share (GIS) and PT-GG measures indicate the contribution of each series (Spot, Futures, USO, USL, OIL) to price discovery. A higher value implies a greater role in the price discovery process. For instance, Futures have the highest GIS and PTGG values, suggesting they play a significant role in price discovery, while OIL has the lowest PTGG measure, indicating a minimal contribution.