Please use R to solve the following problem. “DHSI.csv” from the data folder on canvas.…
- User
Please use R to solve the following problem. “DHSI.csv” from the data folder on canvas. The file contains daily data of Hang Seng Index from 1987-01-02 to 2023-09-29. Extract the daily close price of DHSI and name the series as “HSI”. Compute log returns of“HSI” and name the series as “DHSILR”.Draw histograms of DHSILR with bin sizes = 20, 100, 500 and 5000.
- Assistant
To solve this problem using R, you can follow the steps given below:
- Read the CSV file and extract the daily close price of DHSI:
# Load the required library library(tidyverse) # Read the CSV file data <- read_csv("data/DHSI.csv") # Extract the daily close price of DHSI HSI <- data$Close- Compute log returns of HSI and name the series as DHSILR:
# Compute log returns of HSI DHSILR <- diff(log(HSI))- Draw histograms of DHSILR with bin sizes = 20, 100, 500, and 5000:
# Set the bin sizes bin_sizes <- c(20, 100, 500, 5000) # Create a new plot window par(mfrow=c(length(bin_sizes), 1)) # Draw histograms for each bin size for (i in 1:length(bin_sizes)) { hist(DHSILR, breaks=bin_sizes[i], main=paste("Bin Size =", bin_sizes[i]), xlab="Log Returns") }This code will read the "DHSI.csv" file, extract the daily close price of DHSI, compute log returns, and draw histograms with different bin sizes.
- User
Please still use R to solve the following problems. Draw histogram of DHSILR with bin size = 100, and superimpose the fitted normal density curve. Draw histogram of DHSILR with bin size = 100, and superimpose the fitted t-density curve. Conduct kernel density estimation of DHSILR with different kernels (Gaussian,rectangular,triangular, and cosine) and plot the results. Try different choices of bandwidths (0.01, 0.001) for kernel density estimation, and compare the results with histogram with bin size of 100. Compute the empirical VaR and the VaR under both normal and t distributions for DHSILRfor levels q = 0.01. Compare and comment. Compute the empirical expected shortfall and the expected shortfall under both normal and t distributions for DHSILR for levels q = 0.01. Compare and comment.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.