[R] error in VaR calculation
Joshua Ulrich
josh.m.ulrich at gmail.com
Tue Jun 25 16:48:37 CEST 2013
r != R (you mis-typed the first argument to VaR). This works:
library(PerformanceAnalytics)
data(sample_matrix)
x <- Return.calculate(as.xts(sample_matrix))
VaR(R=x, p=0.99, method="historical")
Best,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
On Tue, Jun 25, 2013 at 7:35 AM, G Girija <girijagun at gmail.com> wrote:
> The code is as follows:
>
>
>
> monthreturns<-read.zoo('monthlyReturn date.csv',sep=",",header=T)
>
> monthreturns<-as.xts(monthreturns,order.by
> =index(monthreturns),frequency=NULL)*W0
>
> head(monthreturns)
>
> dim(monthreturns)
>
>
>
> portnames<-c('acc','cipla','cmc','idbi','ifci') ----portfolio names (5
> stocks)
>
> mu.vec<-c(0.1,0.2,0.2,0.4,0.1)
>
> names(mu.vec)<-portnames
>
> covmatr<-cov(monthreturns,use='complete')
>
> sigma.matr<-sqrt(covmatr)
>
> head(sigma.matr)
>
> dim(sigma.matr)
>
>
>
> library(PerformanceAnalytics)
>
> VaR(r=monnthreturns,p=0.99,method='historical',mu=mu.vec,sigma=sigma.matr,weights=NULL)*W0
>
>
>
> *But here I am getting the following error: *
>
>>
> VaR(r=monnthreturns,p=0.99,method='historical',mu=mu.vec,sigma=sigma.matr,weights=NULL)*W0
>
> Error in VaR(r = monnthreturns, p = 0.99, method = "historical", mu =
> mu.vec, :
>
> number of items in weights not equal to number of items in the mean vector
>
> * *
>
> *could anyone help*
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list