---
title: "Projeto"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: [ "twitter", "facebook", "menu"]
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
## Pacotes
library(tidyquant)
library(highcharter)
library(ggthemes)
library(plotly)
## Pegando dados da ibovespa
# Baixando os dados
tickets <- tq_get(c("ITUB4.SA","BBDC3.SA","SANB3.SA","BBAS3.SA"),from = "2015-01-01")
```
Painel Principal
====================================
Inputs {.sidebar}
-------------------------------------
Dashboard simples feito com o pacote `flexdasboad`. Tem como objetivo apresentar estatisticas e graficos básicos dos 4 principais bancos com ações listadas na **B3**. O código para replicação pode ser visto em **</> Source Code** no canto superior direito. Para mais exemplos de dashboards, clique [aqui](https://rmarkdown.rstudio.com/flexdashboard/examples.html)
Column {.tabset .tabset-fade}
-------------------------------------
### Itaú
```{r}
x <- getSymbols("ITUB4.SA",from = "2015-01-01",auto.assign = FALSE)
hchart(x) %>% hc_add_theme(hc_theme_economist())
```
### Bradesco
```{r}
# Grafico dos ativos
x <- getSymbols("BBDC3.SA",from = "2015-01-01",auto.assign = FALSE)
hchart(x) %>% hc_add_theme(hc_theme_economist())
```
### Santander
```{r}
# Grafico dos ativos
x <- getSymbols("SANB3.SA",from = "2015-01-01",auto.assign = FALSE)
hchart(x) %>% hc_add_theme(hc_theme_economist())
```
### Banco do Brasil
```{r}
# Grafico dos ativos
x <- getSymbols("BBAS3.SA",from = "2015-01-01",auto.assign = FALSE)
hchart(x) %>% hc_add_theme(hc_theme_economist())
```
Column
-------------------------------------
### Boxplot
```{r}
g1 <- tickets %>%
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "monthly",
col_rename = "Retornos") %>%
ggplot(aes(x = as.factor(symbol),y = Retornos,fill = symbol)) +
geom_boxplot() + theme_economist() + scale_fill_economist() +
labs(title = "Box Plot dos retornos mensais") +
xlab("") + ylab("") + scale_y_continuous(labels=scales::percent)
g1 %>% ggplotly()
```
### Matriz de correlação
```{r}
library(GGally)
tickets %>%
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "monthly",
col_rename = "Retornos") %>%
spread(symbol,Retornos) %>% select(-date) %>%
ggcorr(label = TRUE)
```
Base de dados
====================
Colums
--------------------------------
### Dados de retorno
```{r}
library(DT)
tickets %>%
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "monthly",
col_rename = "Retornos") %>%
spread(symbol,Retornos) %>%
datatable(extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = c('excel')
)) %>% formatPercentage(c("ITUB4.SA","BBDC3.SA","SANB3.SA","BBAS3.SA"), 2) %>%
formatDate(1, "toDateString") %>%
formatStyle(c("ITUB4.SA","BBDC3.SA","SANB3.SA","BBAS3.SA"),
Color = styleInterval(0, c('red', 'green')))
```
### Dados de preços
```{r}
tickets %>%
datatable(extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = c('excel')
)) %>% formatCurrency(c("open","high","low","close","adjusted")) %>%
formatDate(2, "toDateString")
```