Question: Solve the below code exactly in R studio. In the second part of the assignment, you will write an R script to calculate the relative
Solve the below code exactly in R studio.
In the second part of the assignment, you will write an R script to calculate the relative volatility for the three given stocks: enb, baba, and aapl
Files to download: Please download the following files from
D2L "baba.csv", "aapl.csv", "enb.csv"
These CSV files contain the historical trading data for the corresponding stocks trading at NYSE/Nasdaq stock exchange, and each of them has the following information:
Date, Open Price, High Price, Low Price, Close Price, Adj Close, Volume
Your task is to write an R script that will calculate the covariance for each of the stocks to calculate the volatility for the year 2019 using the closing price of the stocks. A higher value of covariance means the stock is more volatile.
How to calculate covariance?
To calculate the covariance, we need to know the mean and the standard deviation (sd). Then using the mean and the standard deviation, we can calculate the covariance (cv) using the following formula:
cv = sd/mean
Your R script should deliver the following:
The script should save the covariance for each of the three stocks to a data frame, and then the data frame should be saved to a CSV file named "covariance.csv" (3 Points)
All the covariances of the three stocks should be plotted on a single plot (2 Points)
Your program should save the stock tickers for the most and the least volatile stocks to a data frame, and then the data frame should be saved to another CSV file named "maxMin.csv" (2 Points)
Make sure the script is well documented. I mean, each line of code should be documented (1 Point)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
