n this CT assignment, we will use R software to analyze a dataset GoogleAmazonStock.xlsx.
It contains daily closing stock prices for Google and Amazon from 8/22/2017 to 8/22/2018. When we examine stock prices (or other financial assets) we often transform them into a (simple) return series. The return series are computed by the formula: (present price/past price) - 1. The dataset contains both stock prices and return series.
1. Using R, construct time series (line) plots for both stock prices and return series. R functions ts.plot or plot can create the plot.
How do you create a plot in R from an XLS file that overlays Google.Return and Amazon.Return by Date?
I would like to use Time Series, but this xls file is not recognized as a time series file
Example Data Set:
Date | Google.Close | Amazon.Close | Google.Return | Amazon.Return |
8/22/2017 | 924.690002 | 966.900024 | ||
8/23/2017 | 927 | 958 | 0.002498132 | -0.0092047 |
8/24/2017 | 921.280029 | 952.450012 | -0.006170411 | -0.0057933 |
8/25/2017 | 915.890015 | 945.26001 | -0.005850571 | -0.007549 |
R CODE:
d<- read.csv("C:/Users/Ayushi/Desktop/ts.csv")
plot.ts(d$Google.Return)
windows()
plot.ts(d$Amazon.Return)
R OUTPUT:
Comment:
Enter the data in excel sheet and convert it to csv format. Then in R code, you enter the path of the excel file. Here I have entered mine.
Hopefully this will help you. In case of any query, do comment. If you are satisfied with the answer, give it a like. Thanks.
Get Answers For Free
Most questions answered within 1 hours.