Question: Identify a preferred public company whose financial data is available on Yahoo Finance PepsiCo, Inc. (PEP). Then identify two additional companies that are in the

Identify a preferred public company whose financial data is available on Yahoo Finance PepsiCo, Inc. (PEP). Then identify two additional companies that are in the same industry (peers or competitors) Keurig Dr Pepper Inc. (KDP) and The Coca-Cola Company (KO).

edit the R code provided to: Calculate risk measures Prepare tables and graphs

Answer the following:

1. Include a brief description of the three selected companies and the reason for their selection.

2. Comment and compare the dispersion of the three companies and the portfolio based on the Range and Interquartile Range measures. Your answer should include: interpretation of each measure and distinction between the two measures.

3. Comment and compare the dispersion of the three companies and the portfolio based on the measures of Standard Deviation and Absolute Deviation. Your answer should include: interpretation of each measure and distinction between the two measures.

4. Calculate, interpret and compare the coefficient of variation of the three companies and the portfolio. In this answer you must include the section of your R code that allows you to do the computation.

5. Comment and compare the dispersion of the three companies and the portfolio based on the SemiDeviation and "Downside Deviation" measures. Your answer should include: interpretation of each measure and distinction between the two measures.

6. Select which of the previously calculated measures best measures risk. Justify your selection.

7. Interpret the results of the graph that presents the "Annualized Return" versus "Annualized Risk" of the three companies.

8. Comment and compare the linear relationship between each of the three companies versus the portfolio based on the Covariance and Correlation measures. Your answer should include: interpretation of each measure and distinction between the two measures.

9. Calculate and interpret the linear relationship between the companies using the correlation coefficient. Here you need to calculate the correlation between company pairs. For example: company 1 vs company 2, company 1 vs company 3, etc. In this answer you must include the section of your R code that allows you to do the computation.

10. Comment and compare the correlation results in questions 8 and 9 above.

#####1. Install the Packages if necessary####

if(!require("tidyverse")) install.packages("tidyverse")

if(!require("tidyquant")) install.packages("tidyquant")

if(!require("lubridate")) install.packages("lubridate")

if(!require("PerformanceAnalytics")) install.packages("PerformanceAnalytics")

if(!require("openxlsx")) install.packages("openxlsx")

#####2. Load the Packages####

library(tidyverse)

library(tidyquant)

library(lubridate)

library(PerformanceAnalytics)

library(openxlsx)

#####3. Data Wrangling####

######3.1.Asset Prices (Stocks) ########

Daily_Price <- c("PEP","KDP","KO") %>%

tq_get(get = "stock.prices",

from = "2017-01-01",

to = "2022-06-30")

######3.2.Asset Returns (Stocks) ########

Daily_Ret <- c("PEP","KDP","KO") %>%

tq_get(get = "stock.prices",

from = "2017-01-01",

to = "2022-06-30") %>%

group_by(symbol) %>%

tq_transmute(select = adjusted,

mutate_fun = periodReturn,

period = "daily",

col_rename = "dRet")

Monthly_Ret <- c("PEP","KDP","KO") %>%

tq_get(get = "stock.prices",

from = "2017-01-01",

to = "2022-06-30") %>%

group_by(symbol) %>%

tq_transmute(select = adjusted,

mutate_fun = periodReturn,

period = "monthly",

col_rename = "mRet")

######3.3.Baseline Returns (Portfolio) ########

Monthly_Ret_Port <- "XLK" %>%

tq_get(get = "stock.prices",

from = "2017-01-01",

to = "2022-06-30") %>%

tq_transmute(select = adjusted,

mutate_fun = periodReturn,

period = "monthly",

col_rename = "Rb")

######3.4.Join (Merge) ########

Monthly_Ret_Join <- left_join(Monthly_Ret,Monthly_Ret_Port,by="date")

######3.5.Reshape ########

Daily_Ret_Wide <- pivot_wider(Daily_Ret,names_from = symbol, values_from = dRet)%>%

mutate(Period = if_else(date<=ymd("2019-12-31"),"Pre-Covid","Post-Covid"))

Monthly_Ret_Wide <- pivot_wider(Monthly_Ret,names_from = symbol, values_from = mRet) %>% left_join(.,Monthly_Ret_Port,by="date")

Monthly_Ret_Wide_TS <- read.zoo(Monthly_Ret_Wide, format = "%Y-%m-%d")

#####4. Analysis####

######4.1.Tables####

Table_summary <- table.Stats(Monthly_Ret_Wide_TS) %>%

tibble::rownames_to_column(.,"Statistic")

Table_var <- table.Variability(Monthly_Ret_Wide_TS) %>%

tibble::rownames_to_column(.,"Statistic")

Table_semi <- SemiSD(Monthly_Ret_Wide_TS, method = "full") %>%

as_tibble(.) %>%

mutate(Statistic="Semi-Deviation") %>%

dplyr::select(Statistic,everything())

Table_semi2 <- DownsideDeviation(Monthly_Ret_Wide_TS, method = "full") %>%

as_tibble(.) %>%

mutate(Statistic="Downside-Deviation (MAR=0%)") %>%

dplyr::select(Statistic,everything())

Table_summary2 <- table.AnnualizedReturns(Monthly_Ret_Wide_TS) %>% tibble::rownames_to_column(.,"Statistic")

Table_cor <- Monthly_Ret_Join %>%

group_by(symbol) %>%

summarise(Num_of_Months=n(),

mRet_Mean=mean(mRet, na.rm= TRUE),

mRet_SD=sd(mRet, na.rm= TRUE),

Rb_SD=sd(Rb, na.rm= TRUE),

Cov_mRet_Rb=cov(x=mRet,y=Rb, use="pairwise.complete.obs"), Cor_mRet_Rb=cor(x=mRet,y=Rb, use="pairwise.complete.obs"), Cor_mRet_Rb2=Cov_mRet_Rb/(mRet_SD*Rb_SD))

######4.2.Graphs####

chart.Boxplot(Monthly_Ret_Wide_TS)

chart.RiskReturnScatter(Monthly_Ret_Wide_TS)

chart.SnailTrail(Monthly_Ret_Wide_TS, legend.loc = "topleft")

#####5.Export & Communicate####

######5.1.Tables####

wb <- createWorkbook()

addWorksheet(wb,"Daily_Prices")

writeData(wb, sheet = "Daily_Prices", x = Daily_Price)

addWorksheet(wb,"Daily_Returns")

writeData(wb, sheet = "Daily_Returns", x = Daily_Ret_Wide)

addWorksheet(wb,"Monthly_Returns")

writeData(wb, sheet = "Monthly_Returns", x = Monthly_Ret_Wide)

addWorksheet(wb,"T1_summary")

writeData(wb, sheet = "T1_summary", x = Table_summary)

addWorksheet(wb,"T2_variability")

writeData(wb, sheet = "T2_variability", x = Table_var)

addWorksheet(wb,"T3_semi")

writeData(wb, sheet = "T3_semi", x = Table_semi)

addWorksheet(wb,"T4_semi2")

writeData(wb, sheet = "T4_semi2", x = Table_semi2)

addWorksheet(wb,"T5_summary2")

writeData(wb, sheet = "T5_summary2", x = Table_summary2)

saveWorkbook(wb, "FING6702_Mod6_R_Tables.xlsx",

overwrite = TRUE) remove(wb)

######5.2.Charts####

jpeg("FING6702_Mod6_R_Graph1.jpeg", quality = 75)

chart.Boxplot(Monthly_Ret_Wide_TS)

dev.off()

jpeg("FING6702_Mod6_R_Graph2.jpeg", quality = 75)

chart.RiskReturnScatter(Monthly_Ret_Wide_TS)

dev.off()

jpeg("FING6702_Mod6_R_Graph3.jpeg", quality = 75)

chart.SnailTrail(Monthly_Ret_Wide_TS, legend.loc = "topleft")

dev.off()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!