library(ggthemes)
library(yfR)
library(ggplot2)
library(dplyr)
library(tidyquant)
<- 'daily'
freq.data <-'2000-01-01'
start <-Sys.Date()
end <- yf_get(tickers = "PETR4.SA",
asset first_date = start,
last_date = end,
thresh_bad_data = 0.5,
freq_data = freq.data )
<- asset %>%tq_transmute(select = price_adjusted,
ret_asset mutate_fun = periodReturn,
period = 'daily',
col_rename = 'return',
type = 'log')
$lag <- lag(ret_asset$return)
ret_assetggplot(ret_asset, aes(x= return, y=lag)) +
geom_point()+
labs( y = "Returns PETR4 t-1", x="Returns PETR4 t",title = "Pairs of returns PETR4")+
theme(plot.title = element_text(color="darkblue", size=15, face="bold"),
panel.background = element_rect(fill = "grey95", colour = "grey95"),
axis.title=element_text(size=12,face="bold"),
title=element_text(size=10,face="bold", color="darkblue"),
axis.text.y = element_text(face = "bold", color = "darkblue", size = 10),
axis.text.x = element_text(face = "bold", color = "darkblue", size = 10))+
xlim(-0.2, 0.2) + ylim(-0.2, 0.2)+
geom_hline(yintercept = 0) +
geom_vline(xintercept = 0) + theme_solarized()
6 Market efficiency
This is a book containing all class notes.
The graph below reproduces Figure 13.1 of BMA using data from Petrobras.