1
$\begingroup$

This is VaR calculation in excel using variance-covariance method. This is VaR calculation in excel using variance-covariance method.

This is VaR calculation in R.

> VaR(dat,p=0.5,weights = wts,portfolio_method = "component",method="gaussian")
$`VaR`
[1] -0.02144891

> VaR(dat,p=0.95,weights = wts,portfolio_method = "component",method="gaussian")
$`VaR`
[1] 0.1623596

VaR in R and excel is same only for c=0.5.

Can you tell me where I am doing it wrong?

R script

library(PortfolioAnalytics)
library(quantmod)
library(PerformanceAnalytics)
library(zoo)
library(plotly)

# Get data
ibm <- read.csv("IBM.csv", header=TRUE)
msft <- read.csv("MSFT.csv", header=TRUE)
aapl <- read.csv("AAPL.csv", header=TRUE)
tsla <- read.csv("TSLA.csv", header=TRUE)

ibm.close = ibm[c(6)]
msft.close = msft[c(6)]
aapl.close = aapl[c(6)]
tsla.close = tsla[c(6)]

# Assign to dataframe
# Get adjusted prices
prices.data <- merge.zoo(ibm.close,msft.close,aapl.close,tsla.close)
prices.data2 <-  ts(data = prices.data)

# Calculate returns
prices.data2.ret = ROC(prices.data2,type = "discrete")[-1,]

# Set names
colnames(returns.data) <- c("ibm","msft","aapl","tsla")

prices.data2.ret = ROC(prices.data2,type = "discrete")[-1,]

VaR(dat,p=0.95,weights = wts,portfolio_method = "component",method="gaussian")
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.