Question: Using R, please calculate simple returns for AAPL and GOOGL stocks for all months for 2020, 2021 and 2022. Report the month and year for
Using R, please calculate simple returns for AAPL and GOOGL stocks for all months for 2020, 2021 and 2022. Report the month and year for each stock in which they gave maximum simple return. In case of a tie, report earliest month. (6 points)
Q3. (25 Points Total) For the following questions, use the stock datasets below. # Install and load necessary libraries install. packages ( "PerformanceAnalytics", lib="../work/") install. packages ( "xts", lib="../work/") install . packages ( "lubridate", lib="../work/") install . packages ( "tidyverse", lib="../work/") install . packages ( "data. table", lib="../work/") library (PerformanceAnalytics, lib. loc="../work/") library (xts, lib. loc="../work/" library (lubridate, lib. loc="../work/") library (tidyverse, lib. loc="../work/") library (data. table, lib. loc="../work/")\fhead (ticker_aapl, 10) A data.frame: 10 x 4 Date Close Dividends Stock.Splits 1 2019-12-31 71.92057 0.0000 0 2 2020-01-31 75.80502 0.0000 0 3 2020-02-28 67.11005 0.1925 0 4 2020-03-31 62.42836 0.0000 0 5 2020-04-30 72.12809 0.0000 0 6 2020-05-29 78.26578 0.2050 0 7 2020-06-30 89.80106 0.0000 0 8 2020-07-31 104.63007 0.0000 0 9 2020-08-31 127.28973 0.2050 4 10 2020-09-30 114.23917 0.0000 0tail (ticker_googl) A data.frame: 6 x 4 Date Close Dividends Stock.Splits 32 2022-07-29 116.32 0 20 33 2022-08-31 108.22 0 0 34 2022-09-30 95.65 0 35 2022-10-31 94.51 0 oo oo 36 2022-11-30 100.99 0 37 2022-12-30 88.23 Ouse aapl.csv & googl.csv for the following question. These two datasets have the following columns: Date: Month end date Close: closing price Dividends: dividend in $ to share holders. Keep in mind not every company gave dividends in sample period. Stock.Splits: if no stock split happened, value is 0, if a stock split happened then one stock was split into the value provided in this column. You may not have to use this column as closing price has already been adjusted for stock split. Keep in mind not every company split it's stock in sample period. A. Please calculate simple returns for AAPL and GOOGL stocks for all months for 2020, 2021 and 2022. Report the month and year for each stock in which they gave maximum simple return. In case of a tie, report earliest month. (6 points) Do not forget to remove NA values as necessary. shift function may help in calculating simple return but you are free to use your method/function in R. Here is a quick reference: (https://www.rdocumentation.orglpackages/data.table/versions/1.11.4ltopics/shift). # SOLUTION BEGINS HERE # SOLUTION ENDS HERE Example: Calculating Stock Returns for Charles Schwab Date Price Dividend Stock Split Return September 1991 31.125 October 1991 37.750 $0.06 =(37.750 + 0.06) / 31.25 - 1 = 20.99% November 1991 32.750 =(32.750) / 37.750 - 1 = -13.25% December 1991 30.375 3 for 2 =(30.375 * 1.5 / 32.750) - 1 = 39.12%
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
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!