I am observing the annual returns of the FANG stocks from 2013 to 2016. FANG stocks are the technology companies, Facebook, Amazon, Netflix and Google. I will like to study the perfomance of each stock in each year by only looking at the return rates. The data will be acquired from Yahoo Finance.
library(tidyverse)
## -- Attaching packages ----------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.1 v purrr 0.3.3
## v tibble 2.1.3 v dplyr 0.8.3
## v tidyr 1.0.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts -------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(tidyquant)
## Loading required package: lubridate
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Registered S3 method overwritten by 'xts':
## method from
## as.zoo.xts zoo
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
##
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
## Loading required package: quantmod
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Version 0.4-0 included new data defaults. See ?getSymbols.
## == Need to Learn tidyquant? ============================================================
## Business Science offers a 1-hour course - Learning Lab #9: Performance Analysis & Portfolio Optimization with tidyquant!
## </> Learn more at: https://university.business-science.io/p/learning-labs-pro </>
library(MyPackage)# this is the package created, contains the function to obtain annual rates for stock over a ten year period.
data("FANG")
FANG_returns_yearly <- FANG %>%
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "yearly",
col_rename = "yearly.returns")
FANG_returns_yearly %>%
ggplot(aes(x = year(date), y = yearly.returns, fill = symbol)) +
geom_bar(position = "dodge", stat = "identity") +
labs(title = "FANG: Annual Returns",
y = "Returns", x = "Year", color = "") +
scale_y_continuous(labels = scales::percent) +
theme_tq() +
scale_fill_tq()
I can tell that in the year 2013, Netflix had a 300% annual return rate. So for investors that bought in and cashed out that year, they found a handsome return. The year 2016 had the lowest return rates for all the 4 companies.
Using the the get_annual_returns function I will obtain the annual returns of the company Apple, INC. The ticker symbol is APPL.
APPL<-get_annual_returns("AAPL")
APPL %>%
ggplot(aes(x=date, y= yearly.returns))+
geom_bar(fill='lightblue', stat="identity")+
labs(title = "APPL", y = "Year", x = "Year")
TESLA<-get_annual_returns("TSLA")
TESLA %>%
ggplot(aes(x=date, y= yearly.returns))+
geom_bar(fill='lightpink', stat="identity")+
labs(title = "Tesla", y = "Year", x = "Year")
I analzyed the annual returns of two companies from different sectors, Apple inc. and Tesla over a ten year period starting from 2008-01-01 to 2018-12-31. Tesla is from Consumer Cyclical sector while Apple is from the technology sector. Year 2009 provided the highest annual return for Apple with 0.904. Year 2013 provided the highest annual return for Tesla with 1.49. Apple also have more years with negative annual returns compared to Tesla. Apple have 3 years of negative returns to Tesla’s one.