Also es sollte ca. so aussehen:
Jahr Facebook Amazon Apple Netflix Google
2020 1% 2% 3% 4% 5%
.
.
.
Hier ist der Code:
Code: Alles auswählen
library(tidyquant)
library(timetk)
library(ggplot2)
library(tibble)
library(select)
library(dplyr)
library(corrplot)
library(tidyr)
library(DT)
# Setting our stock symbols to a variable
tickers <- c("FB", "AMZN", "AAPL", "NFLX", "GOOG")
# Dowload the stock price data
multpl_stocks <- tq_get(tickers,
from = "2013-01-01",
to = "2018-03-01",
get = "stock.prices")
multpl_stocks %>%
ggplot(aes(x = date, y = adjusted, color = symbol)) +
geom_line() +
ggtitle("Price chart for multiple stocks")
multpl_stocks %>%
ggplot(aes(x = date, y = adjusted)) +
geom_line() +
facet_wrap(~symbol, scales = "free_y") +
theme_classic() + # using a new theme
labs(x = "Date", y = "Price") +
ggtitle("Price chart FAANG stocks")
#Calculating the yearly returns for multiple stocks
multpl_stock_yearly_returns <- multpl_stocks %>%
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = 'yearly',
col_rename = 'returns')
datatable(multpl_stock_yearly_returns)