Using R lag function to analyze time series

User Generated

Nxhabybxvln

Computer Science

Description

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`).

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

The solution is attached.Please, give me feedb...


Anonymous
Really useful study material!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Content

Related Tags