[SOLVED] CS代考 library(quantmod)

30 $

File Name: CS代考_library(quantmod).zip
File Size: 244.92 KB

SKU: 8329503237 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


library(quantmod)
getSymbols(‘MSFT’, from = ‘2007-01-01’, to = ‘2021-12-31’)
MSFT <- Ad(MSFT)msftRetC <- monthlyReturn(MSFT, type = ‘log’)Copyright By PowCoder代写加微信 assignmentchef

mu <- mean(msftRetC); sigma.e <- sd(msftRetC) # parameters for modelT <- length(msftRetC); # number of time periods for simulationset.seed(100)e <- rnorm(T, mean = 0, sd = sigma.e) # generate noise termsret <- mu + e # calculate monthly returnret <- xts(ret, index(msftRetC)) # converting into xts format with dates# histogram of simulated returnshist(ret, freq = FALSE, ylim = c(0,6), breaks = 10, col = ‘blue2’)curve(dnorm(x, mu, sigma.e), -0.2, 0.2, add = TRUE, lwd = 2, col = ‘red2’)# Simulating Stock Pricep0 <- as.numeric(log(MSFT[1])) # initial log pricep <- p0 + mu * seq(T) + cumsum(e) # log price evolution over timep <- c(p0, p) # attach the initial log price to the frontP <- exp(p) # going from log-price to pricep <- xts(p, c(index(MSFT)[1], index(msftRetC))) # convert into xts formatP <- xts(P, index(p)) # convert into xts format# Plot Simulated prices:plot(merge(p, P), multi.panel = TRUE, yaxis.same = FALSE, main= “Plot of Simulated Log-Price and Price”)# Plot Actual Prices:plot(merge(log(MSFT), MSFT), multi.panel = TRUE, yaxis.same = FALSE, main= “Plot of Actual Log-Price and Price”)# Try a different seed:set.seed(22)e <- rnorm(T, mean = 0, sd = sigma.e) # generate noise termsret <- mu + e # calculate monthly returnret <- xts(ret, index(msftRetC)) # converting into xts format with dates# histogram of simulated returnshist(ret, freq = FALSE, ylim = c(0,6), breaks = 10, col = ‘blue2’)curve(dnorm(x, mu, sigma.e), -0.2, 0.2, add = TRUE, lwd = 2, col = ‘red2’)# Simulating Stock Pricep0 <- as.numeric(log(MSFT[1])) # initial log pricep <- p0 + mu * seq(T) + cumsum(e) # log price evolution over timep <- c(p0, p) # attach the initial log price to the frontP <- exp(p) # going from log-price to pricep <- xts(p, c(index(MSFT)[1], index(msftRetC))) # convert into xts formatP <- xts(P, index(p)) # convert into xts format# Plot Simulated prices:plot(merge(p, P), multi.panel = TRUE, yaxis.same = FALSE, main= “Plot of Simulated Log-Price and Price”)# Plot Actual Prices:plot(merge(log(MSFT), MSFT), multi.panel = TRUE, yaxis.same = FALSE, main= “Plot of Actual Log-Price and Price”)# Multiple Simulationsset.seed(100)e <- rnorm(T * 10, mean = 0, sd = sigma.e)e <- matrix(e, nrow=T) # organize into 10 sets of T valuesret <- mu + eret <- xts(ret, index(msftRetC)) # convert into xts form with dates# Now generate prices – same as beforep0 <- as.numeric(log(MSFT)[1])p <- p0 + apply(ret, 2, cumsum)p <- rbind(rep(p0, 10), p) # Attach initial pricep <- xts(p, c(index(MSFT)[1], index(msftRetC))) #convert into xts with datesP <- exp(p) # actual priceplot(P, main = “Plot of Simulated Price Paths”)程序代写 CS代考加微信: assignmentchef QQ: 1823890830 Email: [email protected]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS代考 library(quantmod)
30 $