Question

In: Computer Science

Using the R code below, calculate daily log returns and assign the name ‘returnlogs’ library(quantmod) getSymbols("MSFT",...

Using the R code below, calculate daily log returns and assign the name ‘returnlogs’

library(quantmod) getSymbols("MSFT", src = "yahoo", from='2017-01-03', to='2018-12-31')

b) MSFTAduestedj <- MSFT$MSFT.Adjusted

Solutions

Expert Solution

'R' code to calculate daily log return. 
#Install the packages that are essential for calculation
#install.packages("quantmod")
library(quantmod)
#install.packages("ggplot2")
library("ggplot2")
# Download the data by using function getsymb, where MSFT is argument
msft <- getsymb("MSFT", src = "yahoo", from = "2017-01-03", to = "2018-12-31", auto.assign = FALSE)
# Command use to read the base file from the folder
msft <- read.csv("MSFT.csv")
msft[,1] <- as.Date(msft[,1])
msft <- xts(msft)
msft <- msft[,-1]
#Visualization of price
head(msft)
tail(msft)
summary(msft)
str(msft)
# calculate 2 average of 1 day with 30 days window 
msft_m <- subset(msft, index(msft) >= "2017-01-01")
msft_m1 <- mean(msft_m[,5], 1, fill = list_cpc(na, 0, na), align = "right")
msft_m30 <- mean(msft_m[,5], 30, fill = list_cpc(na, 0, na), align = "right")
msft_m$m1 <- core_data(msft_m1)
msft_m$m30 <- core_data(msft_m30)

# Returning logs

returnlogs <- diff(log(msft[,6]))
returnlogs <- returnlogs[-1,]
# Return for different period
dailyReturn(msft)
weeklyReturn(msft)
monthlyReturn(msft)
quarterlyReturn(msft)
yearlyReturn(msft)

# Summary statistics, we will get the summary report in the following format.

summary(msft)

##    MSFT.Open MSFT.High MSFT.Low MSFT.Close MSFT.Volume   MSFT$MSFT.Adjusted 
## 2017-May-23     8.8      8.92    8.75      8.82   22071         8.84
## 2017-May-24     9.0      9.22    8.90      9.09   25863         9.09
## 2017-May-25     9.08     9.26    8.82      8.90   30557         8.90
## 2017-May-26     8.75     9.04    8.73      8.96   22845         8.96
## 2017-May-30     8.86     8.93    8.70      8.71   21082         8.71
## 2017-May-31     8.68     8.78    8.45      8.49   23066         8.49
##      Index             MSFT$MSFT.Adjusted    
##  Min.     :2017-Jan-03     Min.     :-0.1862  
##  1st qtr. :2017-Feb-08     1st qtr. :-0.0153  
##  Med      :2017-March-17   Med      :-0.0027  
##  Avg      :2017-March-17   Avg      :-0.0016  
##  3rd qtr. :2017-April-24   3rd qtr. : 0.0159  
##  Max.     :2017-May-31     Max.     : 0.0687



Related Solutions

Sub HW4_1_1() 'a. Using the properties window in the VB editor assign ' the code name...
Sub HW4_1_1() 'a. Using the properties window in the VB editor assign ' the code name wsEx2 to the sheet with tab name Sheet1. 'b. Using VBA code and the code name for worksheet Sheet1, ' make this worksheet the active sheet. 'c. Declare a range variable and assign to this variable ' the range from A2 to A10 in the worksheet Sheet1. 'd. Write VBA code to create a range name and call it “Scores”. ' This range name...
Below are the holding period returns for the past five years for Microsoft (MSFT) and the...
Below are the holding period returns for the past five years for Microsoft (MSFT) and the S&P 500 Date MSFT S&500 2017 15% 8% 2016 7% 9% 2015 25% 12% 2014 15% 7% 2013 6% 5% a. Calculate the average arithmetic return and standard deviation for MSFT and the S&P500. b. Assuming you are a risk averse investor and expect the next 12 months to be similar to the past twelve months. If you had to make a choice between...
Complete the R code using Rstudio so that it calculates and returns the estimates of β,...
Complete the R code using Rstudio so that it calculates and returns the estimates of β, the intercept and regression weight of the logistic regression of approximate GPA on Rouder-Srinivasan preference. ## Data Preference <- c( 0, 0, 0, 0, 0, 1, 1, 1, 1) # 0: Rouder; 1: Srinivasan GPA <- c(2.0, 2.5, 3.0, 3.5, 4.0, 2.5, 3.0, 3.5, 4.0) Count <- c( 4, 5, 21, 22, 8, 2, 1, 4, 7) # Define the deviance function deviance <-...
Below is what I usually eat daily. Answer the following questions on the food log below....
Below is what I usually eat daily. Answer the following questions on the food log below. What are the functions of each nutrient? Did you consume enough or too much of each (deficiencies / excesses)? What are the health benefits of each, as well as the risks to health if too much or too little are consumed? Did you select good sources of each (fried vs baked, simple vs complex carbs, saturated vs unsaturated fats, etc.)? What would be your...
Answer IN R CODE to get the following. Using the data below, Create a scatterplot of...
Answer IN R CODE to get the following. Using the data below, Create a scatterplot of y vs x Fit a simple linear regression model using y as the response and plot the regression line (with the data) Test whether x is a significant predictor and create a 95% CI around the slope coefficient. Report and interpret the coefficient of determination. For x=20, create a CI for E(Y|X=20). For x=150, can you use the model to estimate E(Y|X=150)? Discuss. Does...
Answer IN R CODE please. Using the data below, Create a scatterplot of y vs x...
Answer IN R CODE please. Using the data below, Create a scatterplot of y vs x (show this) and fit it a simple linear regression model using y as the response and plot the regression line (with the data). Show this as well. Test whether x is a significant predictor and create a 95% CI around the slope coefficient. What does the coefficient of determinations represent? For x=20, create a CI for E(Y|X=20). Show this. For x=150, can you use...
Using R calculate the following properties of the Data Set given below: (a) The average (mean)...
Using R calculate the following properties of the Data Set given below: (a) The average (mean) value for each of the four features (b) (b) the standard deviation for each of the features (c) repeat steps (a) and (b) but separately for each type of flower (d) (d) draw four box plots, one for each feature, such that each figure shows three boxes, one for each type of flower. Properly label your axes in all box plots. Data Set {...
Matlab Code Write a procedure to calculate the log discriminant function for a given multi-variate Gaussian...
Matlab Code Write a procedure to calculate the log discriminant function for a given multi-variate Gaussian distribution and prior probability
Q-1) a client wants to log into a server by using username and password first name...
Q-1) a client wants to log into a server by using username and password first name a suitable http mechanism like cookie or session to make it happen and then make a signal flow diagram to show that how does it happen
JavaScript Given the following object, log every property name and value to the console using a...
JavaScript Given the following object, log every property name and value to the console using a loop. let myObj = { id: 12 name: 'My Object', class: 'obj', height: 65, likeJavascript: true, data: [1, 53, 23] };
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT