[Returnanalytics-commits] r3322 - pkg/FactorAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 21 03:44:51 CET 2014


Author: efmrforge
Date: 2014-02-21 03:44:50 +0100 (Fri, 21 Feb 2014)
New Revision: 3322

Removed:
   pkg/FactorAnalytics/R/.Rhistory
Log:
Removed .Rhistory 


Deleted: pkg/FactorAnalytics/R/.Rhistory
===================================================================
--- pkg/FactorAnalytics/R/.Rhistory	2014-02-20 23:02:12 UTC (rev 3321)
+++ pkg/FactorAnalytics/R/.Rhistory	2014-02-21 02:44:50 UTC (rev 3322)
@@ -1,512 +0,0 @@
-nrow=6)
-gplot(t(adj.mat),gmode="digraph",label=c(1,2,3,4,5,6),vertex.cex=2,
-arrowhead.cex = 1)
-gplot(t(adj.mat1),gmode="digraph",label=c(1,2,3,4,5,6),vertex.cex=2,
-arrowhead.cex = 1)
-gplot(t(adj.mat1),gmode="digraph",label=c(1,2,3,4,5,6),vertex.cex=2,
-arrowhead.cex = 1)
-gplot(t(adj.mat),gmode="digraph",label=c(1,2,3,4,5,6),vertex.cex=2,
-arrowhead.cex = 1)
-rm(list=ls())
-library(factorAnalytics)
-library(fEcofin)
-ts.berndt<-xts(berndtInvest[,-1],as.Date(berndtInvest[,1]))
-data(stat.fm.data)
-View(sfm.dat)
-install.packages("~/R-project/returnanalytics/pkg/FactorAnalytics/sandbox/fEcofin_2100.77.zip-UWunsafe", repos = NULL)
-install.packages("~/R-project/returnanalytics/pkg/FactorAnalytics/sandbox/fEcofin_2100.77.zip", repos = NULL)
-library(fEcofin)
-? fEconfin
-fEconfin
-help(pakcage=fEconfin)
-help(package=fEconfin)
-help(package=fEcofin)
-data(berndtInvest)
-ts.berndt<-xts(berndtInvest[,-1],as.Date(berndtInvest[,1]))
-berndt<-ts.berndt['1978/1987']
-returns<-berndt[,c(-10,-17)]
-tickers <- names(returns)
-num.tickers <- length(tickers)
-dates <- index(returns)
-num.dates <- length(dates)
-sector<-c("OTHER","OTHER","OIL","TECH","TECH","OIL","OTHER","OTHER",
-"TECH","OIL","OIL","OTHER","TECH","OIL","OTHER")
-stacked.returns <- data.frame(
-DATE=rep(dates,num.tickers),
-TICKER=rep(tickers,each=num.dates),
-RETURN=c(coredata(returns)),
-SECTOR=rep(sector,each=num.dates),
-stringsAsFactors=FALSE)
-head(stacked.returns)
-barra <- fitFundamentalFactorModel(data=stacked.returns,exposure.names="SECTOR",
-datevar="DATE",returnsvar="RETURN",
-assetvar="TICKER",wls=TRUE)
-head(barra$factor.returns)
-barra$beta
-barra.cov <- factorModelCovariance(barra$beta, barra$factor.cov$cov, barra$resid.variance)
-barra.cor <- cov2cor(barra.cov)
-round(barra.cor,2)
-View(stacked.returns)
-returns = berndtInvest[,-c(1,11,18)]
-n.stocks = ncol(returns)
-tech.dum = oil.dum = other.dum = matrix(0,n.stocks,1)
-tech.dum[c(4,5,9,13),] = 1
-oil.dum[c(3,6,10,11,14),] = 1
-other.dum = 1 - tech.dum - oil.dum
-B = cbind(tech.dum,oil.dum,other.dum)
-dimnames(B) = list(colnames(returns),c("TECH","OIL","OTHER"))
-B
-returns = t(returns)
-F.hat = solve(crossprod(B))%*%t(B)%*%returns
-E.hat = returns - B%*%F.hat
-diagD.hat = apply(E.hat,1,var)
-Dinv.hat = diag(diagD.hat^(-1))
-H = solve(t(B)%*%Dinv.hat%*%B)%*%t(B)%*%Dinv.hat
-round(H[,1:8],5)
-apply(H,1,sum)
-F.hat = H%*%returns
-E.hat = returns - B%*%F.hat
-diagD.hat = apply(E.hat,1,var)
-F.hat = t(F.hat)
-F.hat
-round(H[,1:8],5)
-H
-B
-returns
-View(berndtInvest)
-H
-names(barra)
-barra$factor.returns
-H
-F.hat
-head(barra$factor.returns)
-head(F.hat)
-oil.f.ret <- barra$returns[,1]
-oth.f.ret <- barra$returns[,1]+barra$returns[,2]
-tech.f.ret <- barra$returns[,1]+barra$returns[,3]
-head(oil.f.ret)
-oil.f.ret <- barra$factor.returns[,1]
-tech.f.ret <- barra$factor.returns[,1]+ barra$factor.returns[,3]
-oth.f.ret <- barra$factor.returns[,1]+barra$factor.returns[,2]
-head(oil.f.ret)
-head(F.hat)
-head(F.hat)[,2]
-head(barra$factor.returns)
-head(F.hat)
-head(cbind(tech.f.ret,oil.f.ret,oth.f.ret))
-tickers
-cbind(tickers,sector)
-barra$beta
-names(barra)
-? fitFundamentalFactorModel
-barra.cov2 <- barra$factor.cov
-barra.cov2
-barra.cov2 <- barra$returns.cov
-barra.cov2
-barra.cor2 <- cov2cor(barra.cov2)
-barra.cor2 <- cov2cor(barra.cov2$cov)
-cov.ind = B%*%var(F.hat)%*%t(B) + diag(diagD.hat)
-sd = sqrt(diag(cov.ind))
-cor.ind = cov.ind/outer(sd,sd)
-cor.samp <- cor(t(returns))
-View(cor.samp)
-View(barra.cor2)
-data(berndtInvest)
-ts.berndt<-xts(berndtInvest[,-1],as.Date(berndtInvest[,1]))
-berndt<-ts.berndt['1978/1987']
-returns<-berndt[,c(-10,-17)]
-tickers <- names(returns)
-num.tickers <- length(tickers)
-dates <- index(returns)
-num.dates <- length(dates)
-sector<-c("OTHER","OTHER","OIL","TECH","TECH","OIL","OTHER","OTHER",
-"TECH","OIL","OIL","OTHER","TECH","OIL","OTHER")
-stacked.returns <- data.frame(
-DATE=rep(dates,num.tickers),
-TICKER=rep(tickers,each=num.dates),
-RETURN=c(coredata(returns)),
-SECTOR=rep(sector,each=num.dates),
-stringsAsFactors=FALSE)
-head(stacked.returns)
-data=stacked.returns
-exposure.names="SECTOR"
-datevar="DATE",
-datevar="DATE"
-returnsvar="RETURN"
-assetvar="TICKER"
-wls=TRUE
-full.resid.cov=FALSE
-assets = unique(data[[assetvar]])
-timedates = as.Date(unique(data[[datevar]]))
-data[[datevar]] <- as.Date(data[[datevar]])
-if (length(timedates) < 2)
-stop("At least two time points, t and t-1, are needed for fitting the factor model.")
-if (!is(exposure.names, "vector") || !is.character(exposure.names))
-stop("exposure argument invalid---must be character vector.")
-if (!is(assets, "vector") || !is.character(assets))
-stop("assets argument invalid---must be character vector.")
-wls <- as.logical(wls)
-full.resid.cov <- as.logical(full.resid.cov)
-robust.scale = FALSE
-standardized.factor.exposure = FALSE
-numTimePoints <- length(timedates)
-numExposures <- length(exposure.names)
-numAssets <- length(assets)
-# check if exposure.names are numeric, if not, create exposures. factors by dummy variables
-which.numeric <- sapply(data[, exposure.names, drop = FALSE],is.numeric)
-exposures.numeric <- exposure.names[which.numeric]
-# industry factor model
-exposures.factor <- exposure.names[!which.numeric]
-if (length(exposures.factor) > 1) {
-stop("Only one nonnumeric variable can be used at this time.")
-}
-exposures.factor
-regression.formula <- paste("~", paste(exposure.names, collapse = "+"))
-if (length(exposures.factor)) {
-regression.formula <- paste(regression.formula, "- 1")
-data[, exposures.factor] <- as.factor(data[,exposures.factor])
-exposuresToRecode <- names(data[, exposure.names, drop = FALSE])[!which.numeric]
-contrasts.list <- lapply(seq(length(exposuresToRecode)),
-function(i) function(n, m) contr.treatment(n, contrasts = FALSE))
-names(contrasts.list) <- exposuresToRecode
-}    else {
-contrasts.list <- NULL
-}
-# turn characters into formula
-regression.formula <- eval(parse(text = paste(returnsvar,regression.formula)))
-# RETURN ~ BOOK2MARKET
-regression.formula
-wls.classic <- function(xdf, modelterms, conlist, w) {
-assign("w", w, pos = 1)
-model <- try(lm(formula = modelterms, data = xdf, contrasts = conlist,
-weights = w, singular.ok = FALSE))
-if (is(model, "Error")) {
-mess <- geterrmessage()
-nn <- regexpr("computed fit is singular", mess)
-if (nn > 0) {
-cat("At time:", substring(mess, nn), "\n")
-model <- lm(formula = modelterms, data = xdf,
-contrasts = conlist, weights = w)
-}
-else stop(mess)
-}
-}
-wls.classic <- function(xdf, modelterms, conlist, w) {
-assign("w", w, pos = 1)
-model <- try(lm(formula = modelterms, data = xdf, contrasts = conlist,
-weights = w, singular.ok = FALSE))
-if (is(model, "Error")) {
-mess <- geterrmessage()
-nn <- regexpr("computed fit is singular", mess)
-if (nn > 0) {
-cat("At time:", substring(mess, nn), "\n")
-model <- lm(formula = modelterms, data = xdf,
-contrasts = conlist, weights = w)
-}
-else stop(mess)
-}
-tstat <- rep(NA, length(model$coef))
-tstat[!is.na(model$coef)] <- summary(model, cor = FALSE)$coef[,3]
-alphaord <- order(names(model$coef))
-c(length(model$coef), model$coef[alphaord], tstat[alphaord],
-model$resid)
-}
-resids <- by(data = data, INDICES = as.numeric(data[[datevar]]),
-FUN = function(xdf, modelterms, conlist) {
-lm(formula = modelterms, data = xdf, contrasts = conlist,
-singular.ok = TRUE)$resid
-},
-modelterms = regression.formula, conlist = contrasts.list)
-resids <- apply(resids, 1, unlist)
-weights <- if (covariance == "robust")
-apply(resids, 1, scaleTau2)^2
-else apply(resids, 1, var)
-FE.hat <- by(data = data, INDICES = as.numeric(data[[datevar]]),
-FUN = wls.classic, modelterms = regression.formula,
-conlist = contrasts.list, w = weights)
-covariance = "classic"
-wls = TRUE
-regression = "classic"
-if (!wls) {
-if (regression == "robust") {
-# ols.robust
-FE.hat <- by(data = data, INDICES = as.numeric(data[[datevar]]),
-FUN = ols.robust, modelterms = regression.formula,
-conlist = contrasts.list)
-} else {
-# ols.classic
-FE.hat <- by(data = data, INDICES = as.numeric(data[[datevar]]),
-FUN = ols.classic, modelterms = regression.formula,
-conlist = contrasts.list)
-}
-} else {
-if (regression == "robust") {
-# wls.robust
-resids <- by(data = data, INDICES = as.numeric(data[[datevar]]),
-FUN = function(xdf, modelterms, conlist) {
-lmRob(modelterms, data = xdf, contrasts = conlist,
-control = lmRob.control(mxr = 200, mxf = 200,
-mxs = 200))$resid
-}, modelterms = regression.formula, conlist = contrasts.list)
-resids <- apply(resids, 1, unlist)
-weights <- if (covariance == "robust")
-apply(resids, 1, scaleTau2)^2
-else apply(resids, 1, var)
-FE.hat <- by(data = data, INDICES = as.numeric(data[[datevar]]),
-FUN = wls.robust, modelterms = regression.formula,
-conlist = contrasts.list, w = weights)
-}
-else {
-# wls.classic
-resids <- by(data = data, INDICES = as.numeric(data[[datevar]]),
-FUN = function(xdf, modelterms, conlist) {
-lm(formula = modelterms, data = xdf, contrasts = conlist,
-singular.ok = TRUE)$resid
-},
-modelterms = regression.formula, conlist = contrasts.list)
-resids <- apply(resids, 1, unlist)
-weights <- if (covariance == "robust")
-apply(resids, 1, scaleTau2)^2
-else apply(resids, 1, var)
-FE.hat <- by(data = data, INDICES = as.numeric(data[[datevar]]),
-FUN = wls.classic, modelterms = regression.formula,
-conlist = contrasts.list, w = weights)
-}
-}
-FE.hat
-FE.hat[1]
-FE.hat[[1]]
-(length(exposures.factor))
-exposures.factor
-length(levels(data[,exposures.factor]))
-(length(exposures.factor)>0)
-if (length(exposures.factor)>0) {
-numCoefs <- length(exposures.numeric) + length(levels(data[,exposures.factor]))
-ncols <- 1 + 2 * numCoefs + numAssets
-fnames <- c(exposures.numeric, paste(exposures.factor,
-levels(data[, exposures.factor]), sep = ""))
-cnames <- c("numCoefs", fnames, paste("t", fnames, sep = "."),
-assets)
-} else {
-numCoefs <- 1 + length(exposures.numeric)
-ncols <- 1 + 2 * numCoefs + numAssets
-cnames <- c("numCoefs", "(Intercept)", exposures.numeric,
-paste("t", c("(Intercept)", exposures.numeric), sep = "."),
-assets)
-}
-FE.hat.mat <- matrix(NA, ncol = ncols, nrow = numTimePoints,
-dimnames = list(as.character(timedates), cnames))
-for (i in 1:length(FE.hat)) {
-names(FE.hat[[i]])[1] <- "numCoefs"
-nc <- FE.hat[[i]][1]
-names(FE.hat[[i]])[(2 + nc):(1 + 2 * nc)] <- paste("t",
-names(FE.hat[[i]])[2:(1 + nc)], sep = ".")
-if (length(FE.hat[[i]]) != (1 + 2 * nc + numAssets))
-stop(paste("bad count in row", i, "of FE.hat"))
-names(FE.hat[[i]])[(2 + 2 * nc):(1 + 2 * nc + numAssets)] <- assets
-idx <- match(names(FE.hat[[i]]), colnames(FE.hat.mat))
-FE.hat.mat[i, idx] <- FE.hat[[i]]
-}
-coefs.names <- colnames(FE.hat.mat)[2:(1 + numCoefs)]
-# estimated factors returns ordered by time
-f.hat <- xts(x = FE.hat.mat[, 2:(1 + numCoefs)], order.by = timedates)
-# check for outlier
-gomat <- apply(coredata(f.hat), 2, function(x) abs(x - median(x,
-na.rm = TRUE)) > 4 * mad(x, na.rm = TRUE))
-if (any(gomat, na.rm = TRUE) ) {
-cat("\n\n*** Possible outliers found in the factor returns:\n\n")
-for (i in which(apply(gomat, 1, any, na.rm = TRUE))) print(f.hat[i,
-gomat[i, ], drop = FALSE])
-}
-tstats <- xts(x = FE.hat.mat[, (2 + nc):(1 + 2 * nc)], order.by = timedates)
-# residuals for every asset ordered by time
-resids <- xts(x = FE.hat.mat[, (2 + 2 * numCoefs):(1 + 2 *
-numCoefs + numAssets)], order.by = timedates)
-Cov.factors <- covClassic(coredata(f.hat), distance = FALSE,na.action = na.omit)
-resid.vars <- apply(coredata(resids), 2, var, na.rm = TRUE)
-D.hat <- if (full.resid.cov) {
-covClassic(coredata(resids), distance = FALSE, na.action = na.omit)
-}  else { diag(resid.vars) }
-B.final <- matrix(0, nrow = numAssets, ncol = numCoefs)
-colnames <-  coefs.names
-B.final
-B.final[, match("(Intercept)", colnames, 0)]
-B.final[, match("(Intercept)", colnames, 0)] <- 1
-B.final
-numeric.columns <- match(exposures.numeric, colnames, 0)
-# only take the latest beta to compute FM covariance
-B.final[, numeric.columns] <- as.matrix(data[ (data[[datevar]] == timedates[numTimePoints]), exposures.numeric])
-rownames(B.final) = assets
-colnames(B.final) = colnames(f.hat)
-B.final
-(length(exposures.factor))
-if (length(exposures.factor)>0) {
-B.final[, grep(exposures.factor, x = colnames)][cbind(seq(numAssets),
-(data[ data[[datevar]] == timedates[numTimePoints],
-exposures.factor]))] <- 1
-}
-B.final
-cov.returns <- B.final %*% Cov.factors$cov %*% t(B.final) +
-if (full.resid.cov) { D.hat$cov
-}  else { D.hat  }
-mean.cov.returns = tapply(data[[returnsvar]],data[[assetvar]], mean)
-Cov.returns <- list(cov = cov.returns, mean=mean.cov.returns, eigenvalues = eigen(cov.returns,
-only.values = TRUE, symmetric = TRUE)$values)
-# report residual covaraince if full.resid.cov is true.
-if (full.resid.cov) {
-Cov.resids <- D.hat
-}
-else {
-Cov.resids <- diag(resid.vars)
-}
-f.hat
-head(barra$factor.returns)
-barra <- fitFundamentalFactorModel(data=stacked.returns,exposure.names="SECTOR",
-datevar="DATE",returnsvar="RETURN",
-assetvar="TICKER",wls=TRUE,full.resid.cov=FALSE)
-head(barra$factor.returns)
-head(f.hat)
-(!(length(exposures.factor)>0))
-setwd("C:/Users/Yi-An Chen/Documents/R-project/returnanalytics/pkg/FactorAnalytics/R")
-source(fitFundamentalFactorModel)
-source("fitFundamentalFactorModel.r")
-barra <- fitFundamentalFactorModel(data=stacked.returns,exposure.names="SECTOR",
-datevar="DATE",returnsvar="RETURN",
-assetvar="TICKER",wls=TRUE,full.resid.cov=FALSE)
-names(barra)
-head(barra$factor.returns)
-barra$beta
-data(berndtInvest)
-ts.berndt<-xts(berndtInvest[,-1],as.Date(berndtInvest[,1]))
-berndt<-ts.berndt['1978/1987']
-returns<-berndt[,c(-10,-17)]
-tickers <- names(returns)
-num.tickers <- length(tickers)
-dates <- index(returns)
-num.dates <- length(dates)
-sector<-c("OTHER","OTHER","OIL","TECH","TECH","OIL","OTHER","OTHER",
-"TECH","OIL","OIL","OTHER","TECH","OIL","OTHER")
-stacked.returns <- data.frame(
-DATE=rep(dates,num.tickers),
-TICKER=rep(tickers,each=num.dates),
-RETURN=c(coredata(returns)),
-SECTOR=rep(sector,each=num.dates),
-stringsAsFactors=FALSE)
-head(stacked.returns)
-setwd("C:/Users/Yi-An Chen/Documents/R-project/returnanalytics/pkg/FactorAnalytics/R")
-barra <- fitFundamentalFactorModel(data=stacked.returns,exposure.names="SECTOR",
-datevar="DATE",returnsvar="RETURN",
-assetvar="TICKER",wls=TRUE,full.resid.cov=FALSE)
-names(barra)
-head(barra$factor.returns)
-setwd("C:/Users/Yi-An Chen/Documents/R-project/returnanalytics/pkg/FactorAnalytics/R")
-source("fitFundamentalFactorModel.r")
-barra <- fitFundamentalFactorModel(data=stacked.returns,exposure.names="SECTOR",
-datevar="DATE",returnsvar="RETURN",
-assetvar="TICKER",wls=TRUE,full.resid.cov=FALSE)
-names(barra)
-head(barra$factor.returns)
-barra$beta
-barra.cov <- factorModelCovariance(barra$beta, barra$factor.cov$cov, barra$resid.variance)
-barra.cor <- cov2cor(barra.cov)
-round(barra.cor,2)
-returns = berndtInvest[,-c(1,11,18)]
-n.stocks = ncol(returns)
-tech.dum = oil.dum = other.dum = matrix(0,n.stocks,1)
-tech.dum[c(4,5,9,13),] = 1
-oil.dum[c(3,6,10,11,14),] = 1
-other.dum = 1 - tech.dum - oil.dum
-B = cbind(tech.dum,oil.dum,other.dum)
-dimnames(B) = list(colnames(returns),c("TECH","OIL","OTHER"))
-B
-returns = t(returns)
-barra_ols = lm(returns ~ -1 + B)
-sbarra_ols = summary(barra_ols)
-e.hat = resid(barra_ols)
-e.var = apply(e.hat,1,var)
-e.var.inv = e.var^-1
-barra_fgls = lm(returns ~ -1 + B, weights = e.var.inv)
-sbarra_fgls = summary(barra_fgls)
-f.hat = coef(barra_fgls)
-f.hat
-e.hat_fgls = resid(barra_fgls)
-e.var_fgls = apply(e.hat_fgls,1,var)
-cov.ind.lm = B %*% var(t(f.hat)) %*% t(B) + diag(e.var_fgls)
-all.equal(cov.ind,cov.ind.lm)
-cor.ind.lm <- cov2cor(cov.ind.lm)
-round(cor.ind.lm,2)
-cov.ind.lm = B %*% var(t(f.hat)) %*% t(B) + diag(e.var_fgls)
-all.equal(cov.ind,cov.ind.lm)
-F.hat = solve(crossprod(B))%*%t(B)%*%returns
-# compute N x T matrix of industry factor model residuals
-E.hat = returns - B%*%F.hat
-# compute residual variances from time series of errors
-diagD.hat = apply(E.hat,1,var)
-Dinv.hat = diag(diagD.hat^(-1))
-# multivariate FGLS regression to estimate K x T matrix of factor returns
-H = solve(t(B)%*%Dinv.hat%*%B)%*%t(B)%*%Dinv.hat
-round(H[,1:8],5)
-# note: rows of H sum to one
-apply(H,1,sum)
-# create factor mimicking portfolios
-F.hat = H%*%returns
-E.hat = returns - B%*%F.hat
-diagD.hat = apply(E.hat,1,var)
-F.hat = t(F.hat)
-all.equal(cov.ind,cov.ind.lm)
-cov.ind = B%*%var(F.hat)%*%t(B) + diag(diagD.hat)
-sd = sqrt(diag(cov.ind))
-cor.ind = cov.ind/outer(sd,sd)
-cor.samp <- cor(t(returns))
-all.equal(cov.ind,cov.ind.lm)
-cor.ind.lm <- cov2cor(cov.ind.lm)
-round(cor.ind.lm,2)
-barra_ols = lm(returns ~ -1 + B)
-sbarra_ols = summary(barra_ols)
-e.hat = resid(barra_ols)
-e.var = apply(e.hat,1,var)
-# e.var.inv = e.var^-1
-e.var.inv = e.var
-barra_fgls = lm(returns ~ -1 + B, weights = e.var.inv)
-sbarra_fgls = summary(barra_fgls)
-f.hat = coef(barra_fgls)
-e.hat_fgls = resid(barra_fgls)
-e.var_fgls = apply(e.hat_fgls,1,var)
-cov.ind.lm = B %*% var(t(f.hat)) %*% t(B) + diag(e.var_fgls)
-all.equal(cov.ind,cov.ind.lm)
-barra.cov <- factorModelCovariance(barra$beta, barra$factor.cov$cov, barra$resid.variance)
-all.equal(cov.ind.lm,barra.cov)
-? lm
-setwd("C:/Users/Yi-An Chen/Documents/R-project/returnanalytics/pkg/FactorAnalytics/R")
-source("fitFundamentalFactorModel.r")
-barra <- fitFundamentalFactorModel(data=stacked.returns,exposure.names="SECTOR",
-datevar="DATE",returnsvar="RETURN",
-assetvar="TICKER",wls=TRUE,full.resid.cov=FALSE)
-head(barra$factor.returns)
-barra.cov <- factorModelCovariance(barra$beta, barra$factor.cov$cov, barra$resid.variance)
-barra.cor <- cov2cor(barra.cov)
-round(barra.cor,2)
-barra_ols = lm(returns ~ -1 + B)
-sbarra_ols = summary(barra_ols)
-e.hat = resid(barra_ols)
-e.var = apply(e.hat,1,var)
-e.var.inv = e.var^-1
-barra_fgls = lm(returns ~ -1 + B, weights = e.var.inv)
-sbarra_fgls = summary(barra_fgls)
-f.hat = coef(barra_fgls)
-e.hat_fgls = resid(barra_fgls)
-e.var_fgls = apply(e.hat_fgls,1,var)
-cov.ind.lm = B %*% var(t(f.hat)) %*% t(B) + diag(e.var_fgls)
-all.equal(cov.ind,cov.ind.lm)
-cor.ind.lm <- cov2cor(cov.ind.lm)
-round(cor.ind.lm,2)
-all.equal(barra.cov,cov.ind.lm)
-barra.cov2 <- barra$returns.cov
-barra.cor2 <- cov2cor(barra.cov2$cov)
-all.equal(barra.cov2,cov.ind.lm)
-barra.cov2
-barra.cov2$cov
-barra.cor2 <- cov2cor(barra.cov2$cov)
-barra.cov2 <- barra$returns.cov$cov
-barra.cor2 <- cov2cor(barra.cov2)
-all.equal(barra.cov2,cov.ind.lm)



More information about the Returnanalytics-commits mailing list