AllBestEssays.com - All Best Essays, Term Papers and Book Report
Search

Value at Risk and Expected Shortfall Calculations

Essay by   •  May 26, 2017  •  Coursework  •  1,142 Words (5 Pages)  •  1,125 Views

Essay Preview: Value at Risk and Expected Shortfall Calculations

Report this essay
Page 1 of 5

Value At Risk and Expected Shortfall Calculations

Analytical Method

  1. Single Asset Portfolio

                    R Function for VAR-

FnVaRUSD<- function(file,p,am,n) {

m<-mean(file$Return)

sd<-sd(file$Return)

Var<-qnorm(p,m,sd)

Var<-exp(Var)-1

Var<-Var*(n^0.5)*am

Var

}

Inputs to function-

file = CSV file having the daily returns(log normal return) of the asset in the following format-

 [pic 1]

p    = p value (1- probability that the loss will be less than the Var)

am = Amount invested in the asset

n= no of days for which VAR is to be calculated

Function Call-  

FnVaRUSD (read.csv("USDINR.csv"),.05,1000,1)

  1. Multi Asset Portfolio

                    R Function for VAR-

FNVarP<-function(z,p,n)

{

x<-z[(2:NROW(z)),(2:NCOL(z))]

cm <- cor(x,method="spearman")

a<-array(NA,dim=(c=NCOL(z)-1))

v<-matrix(a, byrow=FALSE)

for(i in 1:NCOL(x))

{

m<-mean(x[,i])

sd<-sd(x[,i])

Var<-qnorm(p,m,sd)

Var<-exp(Var)-1

Var<-Var*z[1,i+1]

v[i,1]<-Var

}

VARP<-(t(v)%*%cm%*%v)^0.5

VARP<-VARP*(n^0.5)

VARP

}

Inputs to function-

z = CSV file having the daily returns of different assets with their Market Value in the following format-

 [pic 2]

p    = p value (1- probability that the loss will be less than the Var)

n= no of days for which VAR is to be calculated

Function Call-  

FNVarP(read.csv("CurrencyReturns.csv"),0.1,1)

R Function for Expected Shortfall-

FNESP<-function(z,p,n)

{

x<-z[(2:NROW(z)),(2:NCOL(z))]

cm <- cor(x,method="spearman")

a<-array(NA,dim=(c=NCOL(z)-1))

e<-matrix(a, byrow=FALSE)

for(i in 1:NCOL(x))

{

m<-mean(x[,i])

sd<-sd(x[,i])

Var<-qnorm(p,m,sd)

es<-subset(x[,i],x[,i]

es<-mean(es)*z[1,i+1]

e[i,1]<-es

}

EXPSH<-(t(e)%*%cm%*%e)^0.5

EXPSH<-EXPSH*(n^0.5)

EXPSH

}

Inputs to function-

z = CSV file having the daily returns of different assets with their Market Value in the following format-

 [pic 3]

p    = p value (1- probability that the loss will be less than the Var)

n= no of days for which ES is to be calculated

Function Call-  

FNESP(read.csv("CurrencyReturns.csv"),0.05,1)

Historical Method

  1. Single Asset Portfolio

                    R Function for VAR-

FnVaRUSDHis<-function(file,p,am,n) {

x<- sort(file$Return, decreasing=TRUE)

Var<-quantile(x,c(p))

Var<-exp(Var)-1

Var<-Var*(n^0.5)*am

Var

}

Inputs to function-

file = CSV file having the daily returns of the asset in the following format-

 [pic 4]

p    = p value (1- probability that the loss will be less than the Var)

am = Amount invested in the asset

n= no of days for which VAR is to be calculated

Function Call-  

FnVaRUSDHis (read.csv("USDINR.csv"),.05,1000,1)

  1. Multi Asset Portfolio

                    R Function for VAR-

FNVarPHis<-function(z,p,n)

{

y<-z[(2:NROW(z)),(2:NCOL(z))]

cm <- cor(x,method="spearman")

a<-array(NA,dim=(c=NCOL(z)-1))

v<-matrix(a, byrow=FALSE)

for(i in 1:NCOL(x))

{

x<- sort(y[,i], decreasing=TRUE)

Var<-quantile(x,c(p))

Var<-exp(Var)-1

Var<-Var*z[1,i+1]

v[i,1]<-Var

}

VARP<-(t(v)%*%cm%*%v)^0.5

VARP<-VARP*(n^0.5)

VARP

}

Inputs to function-

z = CSV file having the daily returns of different assets with their Market Value in the following format-

 [pic 5]

p    = p value (1- probability that the loss will be less than the Var)

n= no of days for which VAR is to be calculated

Function Call-  

FNVarPHis(read.csv("CurrencyReturns.csv"),0.1,1)

R Function for Expected Shortfall-

...

...

Download as:   txt (12.3 Kb)   pdf (106.6 Kb)   docx (76.6 Kb)  
Continue for 4 more pages »
Only available on AllBestEssays.com