using r lag function to analyze time series

Import the sp.csv file on Canvas Module. It contains information about the SP500 index for 1426 trading days.

Create a new variable return, defined as the percentage change of a day’s Adjusted Close compared to last trading day’s Adjusted Close. That is, return(t) = 100* (Adj Close(t) – Adj Close(t-1))/Adj Close(t-1).

Calculate the five number summary (Links to an external site.)Links to an external site. of the return using the summary() function.

Hint: The easiest way to get the previous trading day’s Adj Close value is using the lag() function in the tidyverse (or dplyr, which is a part of the tidyverse) package. Import the package first before using the lag() function.

To extract a variable that contains space (such as Adj Close) from a data frame, use sp$`Adj Close`).

Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.