loss.fit.dist: Fits density for loss density

Description Usage Arguments Value See Also Examples

Description

Fits a chosen density to loss data and draws plot of empirical and fitted density.

Usage

1
2
3
loss.fit.dist(densfun, x, start = NULL, name = NULL, qq = FALSE, period, ylim = c(), xlim = c(),
	 col = "red", from = 0.1^15, to = 1 - 0.1^15, length.out = 10000, by = NULL, kernel = NULL,
	 n = NULL, draw.diff = F, draw.max = F,xlog.scale = FALSE,...)

Arguments

densfun

a character string or a function returning a density evaluated at its first argument. Distributions "beta", "cauchy", "chi-squared", "exponential", "f", "gamma", "geometric", "log-normal" (or "lognormal"), "logistic", "normal", "weibull" and "inverse gaussian" are recognised, case being ignored.

x

an object with two columns (losses in second column) or vector of losses

start

a named list giving the parameters to be optimized with initial values (it can be omitted for the named distributions and must be for others)

name

if densfun is not a named function, name will be in the main of the plot drawn

qq

if TRUE, a qqplot is drawn

period

could be "none" (losses are not aggregated), "days", "weeks", "months" or "quarters" (in last four cases loss are aggregated by days, weeks, months or quarters respectively); if missing, "none"

ylim

optional

xlim

optional

col

fitted density colour (default red)

from

start value of p values in numeric vector of probabilities given to compute empirical and theoretical quantiles ; values in [0,1], 0.1^15 default; p = seq(from, to, length.out, by)

to

end value of p values in numeric vector of probabilities given to compute empirical and theoretical quantiles; values in [0,1], 1 - 0.1^15 default; p = seq(from, to, length.out, by)

length.out

desired length of the sequence p, 10000 default; p = seq(from, to, length.out, by)

by

step in numeric vector of probabilities p = seq(from, to, length.out, by); NULL default

kernel

smoothing kernel to be used; see density

n

the number of equally spaced points at which the density is to be estimated; see density (if not given, default density n is used)

draw.diff

logical; draw differences between empirical and estimated density values?

draw.max

logical; draw maximal differences between empirical and estimated density values?

xlog.scale

a logical value (see log in plot.default). If TRUE, a x logarithmic scale is in use

...

arguments passed to fitdistr (in fact, to optim)

Value

loglik

the log-likelihood (from fitdistr)

param

fitted parameters (from fitdistr)

sd

estimated standard errors (from fitdistr)

q.e

vector of x emprical quantiles

q.t

vector of theoretical quantiles from fitted distribution

ad

absolute differences between empirical and fitted density values

teor.dens

fitted density values

emp.dens

empirical density values

maxdiff

maximum difference between empirical and fitted density values

meandiff

mean difference between empirical and fitted density values

See Also

fitdistr, optim, qqplot, period.loss

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
data(loss.data.object)
x<- read.loss(5,5,loss.data.object)

# first example:

mx<-x[,2]


par(mfrow=c(2,2))
loss.fit.dist("gamma",x)
loss.fit.dist("gamma",mx,col="blue") # no difference between mx and x
loss.fit.dist("gamma",mx,col = "darkgreen",qq=T)

# second example:


par(mfrow=c(2,1))
a = loss.fit.dist("inverse gaussian",col = "blue",x,qq=T)# there are emprical and theoretical quantiles

# third example: 

loss.fit.dist("exponential",x)

#  fourth example:

st<- list(shape=0.7882,scale = 11533) 
par(mfrow=c(2,1))
loss.fit.dist("weibull",x,start = st) # fitting weibull distribution with given start
loss.fit.dist("weibull",x) # and without start

# fifth example:

par(mfrow=c(2,1))
sta<-list(sd = 3,mean = 0.5)
a1 = loss.fit.dist(dnorm,x,start = sta,name = "normal!") # of course "normal" is recognised distribution
# but supplying pars for the normal distribution is not supported!
# so it can be only that way
a2 = loss.fit.dist(dnorm,x,start = sta,name = "normal!",col = "blue")
# method is optim argument
# compare parameters
a1$param
a2$param 

# sixth example:

sta<-list(sd = 3,mean = 0.5)
loss.fit.dist(dnorm,x,start = sta,name = "normal!") 
a = loss.fit.dist(dnorm,x,start = sta,name = "normal!",qq = TRUE);summary(a)
head(cbind(a$q.e,a$q.t))

barryrowlingson/opVaR documentation built on May 11, 2019, 7:24 p.m.