# Cotações
ativos <- c("VALE3.SA", "PETR4.SA") # Localizar e Substituir o nome do ativo por outros
inicio <- as.Date("2010-01-04")
fim <- as.Date("2020-12-30")
cotacao <- ativos %>%
tq_get(get = "stock.prices", from = inicio, to = fim) %>%
mutate(adjusted = na.locf(adjusted))
# Retornos
df_retornos <- cotacao %>%
group_by(symbol) %>%
select(date, adjusted) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "daily",
type = "log",
col_rename = "retorno") %>%
spread(key = symbol, value = retorno)
Quandl.api_key('TC1ow5j6G7s4SFHTzgDz') # Acrescentando a chave da API - Comando necessário pra acessar o Quandl
selic_diaria <- as.data.frame(Quandl("BCB/11", type = "xts")/100) # Importando a serie do selic do Bacen
df_selic <- selic_diaria %>%
rownames_to_column() %>%
tibble() %>%
rename("date" = rowname, "selic" = V1) %>%
mutate(selic = na.locf(selic))
df_selic$date <- as.Date(df_selic$date)
df_retornos <- df_retornos %>%
left_join(df_selic, by = "date")
MKT_Factor <- read_excel("D:/Dropbox/UFMG/Programação/R/Métodos/Trabalho Final/Market_Factor.xls")
HML_Factor <- read_excel("D:/Dropbox/UFMG/Programação/R/Métodos/Trabalho Final/HML_Factor.xls")
SMB_Factor <- read_excel("D:/Dropbox/UFMG/Programação/R/Métodos/Trabalho Final/SMB_Factor.xls")
MKT <- MKT_Factor %>% select(date, Rm_minus_Rf) %>% rename("MKT" = Rm_minus_Rf)
MKT$date <- as.Date(MKT$date)
HML <- HML_Factor %>% select(date, HML)
HML$date <- as.Date(HML$date)
SMB <- SMB_Factor %>% select(date, SMB)
SMB$date <- as.Date(SMB$date)
df <- df_retornos %>%
transmute("date" = date,
"VALE3-Rf" = VALE3.SA - selic,
"PETR4-Rf" = PETR4.SA - selic) %>%
left_join(HML, by = "date") %>%
left_join(SMB, by = "date") %>%
left_join(MKT, by = "date")
##### ------ CAPM ------ #####
capm_a <- lm(`VALE3-Rf` ~ MKT, data = df)
summary(capm_a)
##
## Call:
## lm(formula = `VALE3-Rf` ~ MKT, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.264529 -0.010302 -0.000175 0.010420 0.109574
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0001020 0.0004143 -0.246 0.806
## MKT 1.1171724 0.0292169 38.237 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0216 on 2716 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.3499, Adjusted R-squared: 0.3497
## F-statistic: 1462 on 1 and 2716 DF, p-value: < 2.2e-16
capm_b <- lm(`PETR4-Rf` ~ MKT, data = df)
summary(capm_b)
##
## Call:
## lm(formula = `PETR4-Rf` ~ MKT, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.169081 -0.009702 -0.000241 0.010054 0.120967
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0005073 0.0003749 -1.353 0.176
## MKT 1.5914358 0.0264382 60.195 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01954 on 2716 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.5716, Adjusted R-squared: 0.5714
## F-statistic: 3623 on 1 and 2716 DF, p-value: < 2.2e-16
##### ------ Fama-French ------ #####
ffrench_a <- lm(`VALE3-Rf` ~ MKT + HML + SMB, data = df)
summary(ffrench_a)
##
## Call:
## lm(formula = `VALE3-Rf` ~ MKT + HML + SMB, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.266522 -0.010353 -0.000198 0.010145 0.118703
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0001518 0.0003998 -0.380 0.704
## MKT 0.9890758 0.0295762 33.442 < 2e-16 ***
## HML 0.7731212 0.0553759 13.961 < 2e-16 ***
## SMB -0.3945782 0.0509501 -7.744 1.35e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.02084 on 2714 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.3955, Adjusted R-squared: 0.3948
## F-statistic: 591.8 on 3 and 2714 DF, p-value: < 2.2e-16
ffrench_b <- lm(`PETR4-Rf` ~ MKT + HML + SMB, data = df)
summary(ffrench_b)
##
## Call:
## lm(formula = `PETR4-Rf` ~ MKT + HML + SMB, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.176089 -0.009571 -0.000146 0.009764 0.117317
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0004992 0.0003691 -1.353 0.176
## MKT 1.5223555 0.0273048 55.754 <2e-16 ***
## HML 0.4623317 0.0511231 9.044 <2e-16 ***
## SMB -0.0228563 0.0470372 -0.486 0.627
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01924 on 2714 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.5853, Adjusted R-squared: 0.5848
## F-statistic: 1277 on 3 and 2714 DF, p-value: < 2.2e-16
O modelo CAPM inicialmente rejeita a hipótese nula do teste de Breusch-Pagan, o que o caracteriza como heterocedástico
bptest(capm_b)
##
## studentized Breusch-Pagan test
##
## data: capm_b
## BP = 30.239, df = 1, p-value = 3.819e-08
O modelo de Fama-French inicialmente rejeita a hipótese nula, o que o caracteriza como heterocedástico
bptest(ffrench_b)
##
## studentized Breusch-Pagan test
##
## data: ffrench_b
## BP = 70.237, df = 3, p-value = 3.798e-15
O teste de Breusch-Godfrey indica que há correlação serial no modelo CAPM, rejeitando a hipótese nula.
bgtest(capm_b)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: capm_b
## LM test = 3.9944, df = 1, p-value = 0.04565
Já o teste de Breusch-Godfrey indica que não haveria correlação serial no modelo Fama-French, aceitando a hipótese nula.
bgtest(ffrench_b)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: ffrench_b
## LM test = 2.6885, df = 1, p-value = 0.1011
outliers_capm_b <- which(apply(influence.measures(capm_b)$is.inf, 1, any))
outliers_ffrench_b <- which(apply(influence.measures(ffrench_b)$is.inf, 1, any))
capm_b_corrigido <- lm(`PETR4-Rf` ~ MKT, data = df[-outliers_capm_b, ])
summary(capm_b_corrigido)
##
## Call:
## lm(formula = `PETR4-Rf` ~ MKT, data = df[-outliers_capm_b, ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.168424 -0.009130 -0.000203 0.009570 0.113486
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0006104 0.0003301 -1.849 0.0645 .
## MKT 1.5962569 0.0285102 55.989 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01659 on 2525 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.5539, Adjusted R-squared: 0.5537
## F-statistic: 3135 on 1 and 2525 DF, p-value: < 2.2e-16
ffrench_b_corrigido <- lm(`PETR4-Rf` ~ MKT + HML + SMB, data = df[-outliers_ffrench_b, ])
summary(ffrench_b_corrigido)
##
## Call:
## lm(formula = `PETR4-Rf` ~ MKT + HML + SMB, data = df[-outliers_ffrench_b,
## ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.156644 -0.009423 -0.000140 0.009336 0.109589
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0003876 0.0003167 -1.224 0.221
## MKT 1.4401823 0.0299337 48.112 <2e-16 ***
## HML 0.4524963 0.0512213 8.834 <2e-16 ***
## SMB -0.0889611 0.0459495 -1.936 0.053 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01586 on 2505 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.5642, Adjusted R-squared: 0.5637
## F-statistic: 1081 on 3 and 2505 DF, p-value: < 2.2e-16
O modelo CAPM rejeita a hipótese nula do teste de Breusch-Pagan, o que o caracteriza como heterocedástico
bptest(capm_b_corrigido)
##
## studentized Breusch-Pagan test
##
## data: capm_b_corrigido
## BP = 27.818, df = 1, p-value = 1.333e-07
O modelo de Fama-French rejeita a hipótese nula, o que o caracteriza como heterocedástico
bptest(ffrench_b_corrigido)
##
## studentized Breusch-Pagan test
##
## data: ffrench_b_corrigido
## BP = 21.033, df = 3, p-value = 0.0001037
O teste de Breusch-Godfrey em ambos os modelos indica que agora não há correlação serial, por aceitarem a hipótese nula.
bgtest(capm_b_corrigido)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: capm_b_corrigido
## LM test = 0.0076624, df = 1, p-value = 0.9302
bgtest(ffrench_b_corrigido)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: ffrench_b_corrigido
## LM test = 0.75677, df = 1, p-value = 0.3843
Ambos os testes mostraram que não há normalidade na distribuição dos resíduos de ambos os modelos (FF e CAPM)
jarqueberaTest(residuals(capm_b_corrigido))
##
## Title:
## Jarque - Bera Normalality Test
##
## Test Results:
## STATISTIC:
## X-squared: 11471.1409
## P VALUE:
## Asymptotic p Value: < 2.2e-16
##
## Description:
## Mon Jul 12 22:49:34 2021 by user: Bruno Marcelino
jarqueberaTest(residuals(ffrench_b_corrigido))
##
## Title:
## Jarque - Bera Normalality Test
##
## Test Results:
## STATISTIC:
## X-squared: 3103.6141
## P VALUE:
## Asymptotic p Value: < 2.2e-16
##
## Description:
## Mon Jul 12 22:49:34 2021 by user: Bruno Marcelino
Transformação logarítmica (não aplicável a variáveis negativas)
Natureza das variáveis
Outliers (já retirados)
Regressão com Defasagem
capm_teste <- dynlm(`PETR4-Rf` ~ MKT + HML + SMB + L(`PETR4-Rf`), data = df[-outliers_capm_b,])
summary(capm_teste)
## Warning in summary.lm(capm_teste): essentially perfect fit: summary may be
## unreliable
##
## Time series regression with "numeric" data:
## Start = 1, End = 2527
##
## Call:
## dynlm(formula = `PETR4-Rf` ~ MKT + HML + SMB + L(`PETR4-Rf`),
## data = df[-outliers_capm_b, ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.093e-17 -8.200e-19 -3.300e-19 1.600e-19 8.350e-16
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -6.181e-19 3.321e-19 -1.861e+00 0.0628 .
## MKT 1.455e-15 4.378e-17 3.323e+01 < 2e-16 ***
## HML 3.874e-16 5.083e-17 7.620e+00 3.56e-14 ***
## SMB -1.300e-19 4.571e-17 -3.000e-03 0.9977
## L(`PETR4-Rf`) 1.000e+00 2.030e-17 4.927e+16 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.668e-17 on 2522 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 1, Adjusted R-squared: 1
## F-statistic: 1.4e+33 on 4 and 2522 DF, p-value: < 2.2e-16
bptest(capm_teste)
##
## studentized Breusch-Pagan test
##
## data: capm_teste
## BP = 1.6982, df = 4, p-value = 0.791
O modelo gerado pode até ser considerado homocedástico, porém há diversos problemas como o fato de o R^2 = 1. Não há possibilidade de continuar os cálculos pedidos com o novo modelo.
O teste RESET indicou que no caso do modelo CAPM, há má especificação das formas funcionais. Isso pode gerar heterocedasticidade
resettest(capm_b_corrigido, power = c(2,3,4))
##
## RESET test
##
## data: capm_b_corrigido
## RESET = 44.926, df1 = 3, df2 = 2522, p-value < 2.2e-16
Testando para várias potências, chegamos à conclusão de que a variável MKT^4 é muito significante
Alterando a forma funcional do modelo, a heterocedasticidade foi corrigida. Entretanto, o teste RESET ainda indica que há melhores formas funcionais. Paramos por aqui pois nosso objetivo foi atingido.
capm_b_corrigido <- lm(`PETR4-Rf` ~ MKT + I(MKT^4), data = df[-outliers_capm_b, ])
summary(capm_b_corrigido)
##
## Call:
## lm(formula = `PETR4-Rf` ~ MKT + I(MKT^4), data = df[-outliers_capm_b,
## ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.158737 -0.008998 -0.000365 0.009490 0.114081
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.624e-04 3.229e-04 -1.432 0.152
## MKT 1.536e+00 2.840e-02 54.075 <2e-16 ***
## I(MKT^4) -1.031e+03 9.415e+01 -10.950 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01621 on 2524 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.5741, Adjusted R-squared: 0.5738
## F-statistic: 1701 on 2 and 2524 DF, p-value: < 2.2e-16
resettest(capm_b_corrigido, power = c(2,3,4)) # não corrigiu forma funcional
##
## RESET test
##
## data: capm_b_corrigido
## RESET = 5.5186, df1 = 3, df2 = 2521, p-value = 0.0008933
bptest(capm_b_corrigido) # corrigiu heterocedasticidade
##
## studentized Breusch-Pagan test
##
## data: capm_b_corrigido
## BP = 0.40288, df = 2, p-value = 0.8176
resettest(ffrench_b_corrigido, power = c(2,3,4,5,6)) # formas funcionais bem especificadas
##
## RESET test
##
## data: ffrench_b_corrigido
## RESET = 2.3029, df1 = 5, df2 = 2500, p-value = 0.0424
O método coeftest retorna os erros-padrão robustos (erros-padrão de White) atrelados a todos os coeficientes. Isso faz com que seus indicadores de significância sejam alterados, teoricamente em conjunto com a heterocedasticidade. Entretanto, não é possível armazenar esses dados em um objeto de classe “linear model” de forma a aplicar os próximos testes, por isso temos que descartá-lo.
coeftest(ffrench_b_corrigido, vcov. = vcovHC)
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.00038760 0.00031635 -1.2252 0.2206
## MKT 1.44018231 0.03943979 36.5160 < 2.2e-16 ***
## HML 0.45249633 0.05995316 7.5475 6.173e-14 ***
## SMB -0.08896109 0.05912069 -1.5047 0.1325
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
O método lmrob cria regressões que aceitam o parâmetro que define a matriz de covariâncias a ser utilizada, que é a matriz de White. A partir daí, cria-se um objeto que teoricamente corrige a heterocedasticidade, e que será utilizado nos próximos passos.
ffrench_b_corrigido <- lmrob(`PETR4-Rf` ~ MKT + HML + SMB, data = df[-outliers_ffrench_b,], cov = ".vcov.w")
summary(ffrench_b_corrigido)
##
## Call:
## lmrob(formula = `PETR4-Rf` ~ MKT + HML + SMB, data = df[-outliers_ffrench_b,
## ], cov = ".vcov.w")
## \--> method = "MM"
## Residuals:
## Min 1Q Median 3Q Max
## -0.156865 -0.009279 -0.000212 0.009418 0.110744
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0004608 0.0002979 -1.547 0.122
## MKT 1.4247478 0.0289937 49.140 < 2e-16 ***
## HML 0.3784316 0.0489543 7.730 1.54e-14 ***
## SMB -0.0580234 0.0443167 -1.309 0.191
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Robust residual standard error: 0.01381
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.5861, Adjusted R-squared: 0.5856
## Convergence in 11 IRWLS iterations
##
## Robustness weights:
## 7 observations c(1928,1929,1931,2342,2345,2346,2347)
## are outliers with |weight| = 0 ( < 4e-05);
## 224 weights are ~= 1. The remaining 2278 ones are summarized as
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.01688 0.86120 0.95090 0.89220 0.98550 0.99900
## Algorithmic parameters:
## tuning.chi bb tuning.psi refine.tol
## 1.548e+00 5.000e-01 4.685e+00 1.000e-07
## rel.tol scale.tol solve.tol eps.outlier
## 1.000e-07 1.000e-10 1.000e-07 3.986e-05
## eps.x warn.limit.reject warn.limit.meanrw
## 1.819e-12 5.000e-01 5.000e-01
## nResample max.it best.r.s k.fast.s k.max
## 500 50 2 1 200
## maxit.scale trace.lev mts compute.rd fast.s.large.n
## 200 0 1000 0 2000
## psi subsampling cov
## "bisquare" "nonsingular" ".vcov.w"
## compute.outlier.stats
## "SM"
## seed : int(0)
As correções para heterocedasticidade e correlação serial não foram capazes de fazer a distribuição dos resíduos de ambos os modelos (FF e CAPM) se tornar normal.
jarqueberaTest(resid(capm_b_corrigido))
##
## Title:
## Jarque - Bera Normalality Test
##
## Test Results:
## STATISTIC:
## X-squared: 5097.4389
## P VALUE:
## Asymptotic p Value: < 2.2e-16
##
## Description:
## Mon Jul 12 22:49:34 2021 by user: Bruno Marcelino
jarqueberaTest(resid(ffrench_b_corrigido))
##
## Title:
## Jarque - Bera Normalality Test
##
## Test Results:
## STATISTIC:
## X-squared: 3216.1014
## P VALUE:
## Asymptotic p Value: < 2.2e-16
##
## Description:
## Mon Jul 12 22:49:34 2021 by user: Bruno Marcelino
outliers_capm_a <- which(apply(influence.measures(capm_a)$is.inf, 1, any))
outliers_ffrench_a <- which(apply(influence.measures(ffrench_a)$is.inf, 1, any))
capm_a_corrigido <- lm(`VALE3-Rf` ~ MKT, data = df[-outliers_capm_a, ])
summary(capm_a_corrigido)
##
## Call:
## lm(formula = `VALE3-Rf` ~ MKT, data = df[-outliers_capm_a, ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.264607 -0.009687 0.000121 0.010076 0.085728
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0005354 0.0003616 -1.481 0.139
## MKT 1.0844186 0.0314316 34.501 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0181 on 2504 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.3222, Adjusted R-squared: 0.3219
## F-statistic: 1190 on 1 and 2504 DF, p-value: < 2.2e-16
ffrench_a_corrigido <- lm(`VALE3-Rf` ~ MKT + HML + SMB, data = df[-outliers_ffrench_a, ])
summary(ffrench_a_corrigido)
##
## Call:
## lm(formula = `VALE3-Rf` ~ MKT + HML + SMB, data = df[-outliers_ffrench_a,
## ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.267294 -0.009785 0.000067 0.009628 0.085303
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0004227 0.0003472 -1.217 0.224
## MKT 0.8685674 0.0328644 26.429 < 2e-16 ***
## HML 0.8132065 0.0552988 14.706 < 2e-16 ***
## SMB -0.3173880 0.0499114 -6.359 2.41e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0173 on 2480 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.3678, Adjusted R-squared: 0.3671
## F-statistic: 481 on 3 and 2480 DF, p-value: < 2.2e-16
# Correlação Serial
bgtest(capm_a_corrigido) # não há correl serial
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: capm_a_corrigido
## LM test = 0.08302, df = 1, p-value = 0.7732
bgtest(ffrench_a_corrigido) # não há correl serial
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: ffrench_a_corrigido
## LM test = 0.11187, df = 1, p-value = 0.738
# Heterocedasticidade
bptest(capm_a_corrigido) # Homocedástico
##
## studentized Breusch-Pagan test
##
## data: capm_a_corrigido
## BP = 0.48538, df = 1, p-value = 0.486
bptest(ffrench_a_corrigido) # Homocedástico
##
## studentized Breusch-Pagan test
##
## data: ffrench_a_corrigido
## BP = 4.1325, df = 3, p-value = 0.2475
O teste foi feito por meio da estatística F, em que o modelo restrito trata o coeficiente beta analisado como sendo fixo.
Em todos os testes aceitamos o modelo irrestrito, ou seja, a hipótese de que o beta = 1 não é significante.
linearHypothesis(capm_a_corrigido, "MKT=1") # não significante
## Linear hypothesis test
##
## Hypothesis:
## MKT = 1
##
## Model 1: restricted model
## Model 2: `VALE3-Rf` ~ MKT
##
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 2505 0.82272
## 2 2504 0.82036 1 0.0023633 7.2134 0.007284 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
linearHypothesis(capm_b_corrigido, c("MKT=1")) # não significante
## Linear hypothesis test
##
## Hypothesis:
## MKT = 1
##
## Model 1: restricted model
## Model 2: `PETR4-Rf` ~ MKT + I(MKT^4)
##
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 2525 0.75710
## 2 2524 0.66353 1 0.093576 355.95 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
linearHypothesis(ffrench_a_corrigido, "MKT=1") # não significante
## Linear hypothesis test
##
## Hypothesis:
## MKT = 1
##
## Model 1: restricted model
## Model 2: `VALE3-Rf` ~ MKT + HML + SMB
##
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 2481 0.74725
## 2 2480 0.74246 1 0.0047882 15.994 6.54e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
linearHypothesis(ffrench_b_corrigido, "MKT=1") # não significante
## Linear hypothesis test
##
## Hypothesis:
## MKT = 1
##
## Model 1: restricted model
## Model 2: `PETR4-Rf` ~ MKT + HML + SMB
##
## Res.Df Df Chisq Pr(>Chisq)
## 1 2506
## 2 2505 1 214.61 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(capm_a_corrigido) # Beta = 1.08
##
## Call:
## lm(formula = `VALE3-Rf` ~ MKT, data = df[-outliers_capm_a, ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.264607 -0.009687 0.000121 0.010076 0.085728
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0005354 0.0003616 -1.481 0.139
## MKT 1.0844186 0.0314316 34.501 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0181 on 2504 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.3222, Adjusted R-squared: 0.3219
## F-statistic: 1190 on 1 and 2504 DF, p-value: < 2.2e-16
summary(capm_b_corrigido) # Beta = 1.54
##
## Call:
## lm(formula = `PETR4-Rf` ~ MKT + I(MKT^4), data = df[-outliers_capm_b,
## ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.158737 -0.008998 -0.000365 0.009490 0.114081
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.624e-04 3.229e-04 -1.432 0.152
## MKT 1.536e+00 2.840e-02 54.075 <2e-16 ***
## I(MKT^4) -1.031e+03 9.415e+01 -10.950 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01621 on 2524 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.5741, Adjusted R-squared: 0.5738
## F-statistic: 1701 on 2 and 2524 DF, p-value: < 2.2e-16
summary(ffrench_a_corrigido) # Beta = 0.87
##
## Call:
## lm(formula = `VALE3-Rf` ~ MKT + HML + SMB, data = df[-outliers_ffrench_a,
## ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.267294 -0.009785 0.000067 0.009628 0.085303
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0004227 0.0003472 -1.217 0.224
## MKT 0.8685674 0.0328644 26.429 < 2e-16 ***
## HML 0.8132065 0.0552988 14.706 < 2e-16 ***
## SMB -0.3173880 0.0499114 -6.359 2.41e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0173 on 2480 degrees of freedom
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.3678, Adjusted R-squared: 0.3671
## F-statistic: 481 on 3 and 2480 DF, p-value: < 2.2e-16
summary(ffrench_b_corrigido) # Beta = 1.42
##
## Call:
## lmrob(formula = `PETR4-Rf` ~ MKT + HML + SMB, data = df[-outliers_ffrench_b,
## ], cov = ".vcov.w")
## \--> method = "MM"
## Residuals:
## Min 1Q Median 3Q Max
## -0.156865 -0.009279 -0.000212 0.009418 0.110744
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0004608 0.0002979 -1.547 0.122
## MKT 1.4247478 0.0289937 49.140 < 2e-16 ***
## HML 0.3784316 0.0489543 7.730 1.54e-14 ***
## SMB -0.0580234 0.0443167 -1.309 0.191
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Robust residual standard error: 0.01381
## (9 observations deleted due to missingness)
## Multiple R-squared: 0.5861, Adjusted R-squared: 0.5856
## Convergence in 11 IRWLS iterations
##
## Robustness weights:
## 7 observations c(1928,1929,1931,2342,2345,2346,2347)
## are outliers with |weight| = 0 ( < 4e-05);
## 224 weights are ~= 1. The remaining 2278 ones are summarized as
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.01688 0.86120 0.95090 0.89220 0.98550 0.99900
## Algorithmic parameters:
## tuning.chi bb tuning.psi refine.tol
## 1.548e+00 5.000e-01 4.685e+00 1.000e-07
## rel.tol scale.tol solve.tol eps.outlier
## 1.000e-07 1.000e-10 1.000e-07 3.986e-05
## eps.x warn.limit.reject warn.limit.meanrw
## 1.819e-12 5.000e-01 5.000e-01
## nResample max.it best.r.s k.fast.s k.max
## 500 50 2 1 200
## maxit.scale trace.lev mts compute.rd fast.s.large.n
## 200 0 1000 0 2000
## psi subsampling cov
## "bisquare" "nonsingular" ".vcov.w"
## compute.outlier.stats
## "SM"
## seed : int(0)
Analisando os betas do fator de mercado para ambas as ações, tanto o modelo de Fama-French quanto o modelo CAPM propuseram que, de maneira significante, a ação da PETR4 está mais exposta ao risco sistêmico, por apresentar maior beta (que representa a maior influência do fator mercado no retorno da ação).
Anova(capm_b_corrigido, ffrench_b_corrigido)
## Anova Table (Type II tests)
##
## Response: PETR4-Rf
## Sum Sq Df F value Pr(>F)
## MKT 0.76871 1 4030.01 < 2.2e-16 ***
## I(MKT^4) 0.03152 1 165.24 < 2.2e-16 ***
## Residuals 0.47782 2505
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
linearHypothesis(ffrench_b_corrigido, "(Intercept) = 0")
## Linear hypothesis test
##
## Hypothesis:
## (Intercept) = 0
##
## Model 1: restricted model
## Model 2: `PETR4-Rf` ~ MKT + HML + SMB
##
## Res.Df Df Chisq Pr(>Chisq)
## 1 2506
## 2 2505 1 2.392 0.122
Podemos notar como o resíduo se comporta antes e após a retirada de dos outliers no modelo de Fama-French
graf <- par(no.readonly = TRUE)
par(mfrow=c(2,1))
plot((ffrench_a$residuals) ,main= "Modelo com Outliers", xlab="tempo", ylab="Resíduos" ,col=2)
plot((ffrench_a_corrigido$residuals) ,main= "Modelo sem Outliers", xlab="tempo", ylab="Resíduos",col=3 )
Notamos que após a retirada dos Outliers os erros padrões se apresentam de forma mais comportada em torno do 0. Isso reforça, agora de forma visual, que ao fazer o teste de correlação serial na Questão 2 o modelo não apresentava média igual a O. Isso foi corrigido com a retirada dos Outliers, porém ainda poderia ser melhorado.
graf <- par(no.readonly = TRUE)
par(mfrow=c(2,1))
plot((ffrench_a$residuals)^2 ,main= "Modelo com Outliers", xlab="tempo", ylab="Resíduos quadráticos" ,col=2)
plot((ffrench_a_corrigido$residuals)^2 ,main= "Modelo sem Outliers", xlab="tempo", ylab="Resíduos quadráticos",col=3 )
O mesmo ocorre com o outro ativo (Fama-French B)
graf <- par(no.readonly = TRUE)
par(mfrow=c(2,1))
plot((ffrench_b$residuals) ,main= "Modelo com Outliers", xlab="tempo", ylab="Resíduos" ,col=2)
plot((ffrench_b_corrigido$residuals) ,main= "Modelo sem Outliers", xlab="tempo", ylab="Resíduos",col=3 )
Notamos que após a retirada dos Outliers os erros padrões se apresentam de forma mais comportada em torno do 0. Isso reforça, agora de forma visual, que ao fazer o teste de correlação serial na questão 2 o modelo não apresentava média igual a O. Isso foi corrigido com a retirada dos outliers, porém ainda poderia ser melhorado.
graf <- par(no.readonly = TRUE)
par(mfrow=c(2,1))
plot((ffrench_b$residuals)^2 ,main= "Modelo com Outliers", xlab="tempo", ylab="Resíduos quadráticos" ,col=2)
plot((ffrench_b_corrigido$residuals)^2 ,main= "Modelo sem Outliers", xlab="tempo", ylab="Resíduos quadráticos",col=3 )
varProp =lm(`PETR4-Rf` ~ MKT, weigh= 1/abs(MKT) ,data = df)
outliers_varProp <- which(apply(influence.measures(varProp)$is.inf, 1, any))
varProp_corrigido <- lmrob(`PETR4-Rf` ~ MKT + HML + SMB, data = df[-outliers_varProp,], cov = ".vcov.w")
graf <- par(no.readonly = TRUE)
par(mfrow=c(3,1))
plot((ffrench_b$residual)^2 ,main= "Modelo com Outliers", xlab="tempo", ylab="Resíduos quadráticos" ,col=1)
plot((ffrench_b_corrigido$residuals)^2 ,main= "Modelo sem Outliers", xlab="tempo", ylab="Resíduos quadráticos" ,col=2)
plot((residuals(varProp_corrigido)^2),main= "Modelo com variância proporcional ao erro", xlab="tempo", ylab="Resíduos quadráticos" ,col=3)