pmExpectation: Methods: Partial Moments Expectation

Description Usage Arguments Value Note Author(s) References Examples

Description

Implements methods for calculating the partial moments either analytically for a given distribution, by sample given the data or resampling with either the bootstrap or jackknife.
The analytical method, which implements both a quadrature based integration and a trapezium approximation, requires that the user provide the name of the distribution for which a density method exists (‘d’ followed by the distribution name) as well as a fit object which should be the second argument to the density method. The sample method is straightforward, requiring only a dataset of differences or returns. This function is vectorized so that it can take in a multivariate dataset, distribution list or any combination of the two (see the examples for more details).

Usage

1
2
3
pmExpectation(data, f, method="sample", fit, threshold, moment=0, type="lower", 
			standardize=FALSE, analytical = "quadrature", n.boot=1000, subdivisions=1000, 
			tailThresh= 10, data.names)

Arguments

data

A data matrix or vector only required when using the sample method.

f

A character vector of distribution names for which density methods exist and takes a fit object as a second argument.

method

A character vector containing the method of calculating the expectation. Valid methods are “analytical”, “sample”, “boot” for the bootstrap and “jack” for the jackknife estimation methods.

fit

The fit object if any method chosen is “analytical”. If there are multiple distributions specified this should be a list with the fit objects.

threshold

A numeric vector of thresholds for calculating the expectation. Optionally, this can be a single number indicating that all calculations use the same threshold.

moment

A positive numeric vector of moments for calculating the expectation. Optionally, this can be a single number indicating that all calculations use the same moment. It is a bad idea to mix moments for multivariate datasets if you are then planning to use the results in portfolio optimization.

type

A character vector indicating which tail is being calculated for the expectation. Valid choices are “lower” and “upper”. Optionally, this can be a single character indicating that all calculations use the same tail.

standardize

A logical vector indicating whether to standardize the result. Standardization raises raises the partial moment to the power of 1/moment. Optionally, this can be a single logical entry indicating that all calculations are standardized or not. If you are planning to pass the object later to the portolio optimizer (via first calculating the co-moment matrix), this should be set to TRUE and the same for all the dataset.

analytical

A character vector indicating the method to use for the analytical method. Valid choices are “quadrature” and “trapezium”.

n.boot

No. of bootstrap replications for the “boot” method.

subdivisions

(Optional) A numeric vector indicating the number of subdivisions to use for the analytical method. Additionally, this can be a single number indicating that all analytical calculations use the same number of subdivisions.

tailThresh

(Optional) A numeric vector indicating the tail (Inf) cutoff to use for integration. Optionally, this can be a single number indicating that all calculations use the same number. This is sometimes required for some density functions which have problem dealing with Inf and -Inf.

data.names

(Optional) A character vector of data names. If only the sample method is used and this is not provided, the function will look to the colnames of the data matrix for names.

Value

An object of class PME

Note

Has method for show. The object can then be passed to the pcmExpectation to generate the partial co-moment matrix used in the quadratic portfolio optimization routine pmSolver. For single datasets see the pmoments method.

Author(s)

Alexios Ghalanos

References

Fishburn, P.C., Decision and Value Theory, 1964, Wiley, New York
Fishburn, P.C., Mean-Risk Analysis with Risk Associated with Below-Target Returns, 1977, American Economic Review, 67, 116-126

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
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
## Not run: 

# First we prepare the analytical solution:
library(RBestFit)
data(djiaret)
# Fit and Test for bestfiting distributions
dow30fit<-apply(as.matrix(djiaret), 2, FUN=function(x) bestfit(x, c("spd",
"ghypuv","Normal2mix"),test="AD", type="univariate"))
# extract the bestfitted distribution object
bdist<-lapply(dow30fit,FUN=function(x) getbestfit(x))
# extract the bestfitted distribution names
bdistnames<-sapply(dow30fit,FUN=function(x) (x@bestfitted),simplify=TRUE)
##############################################
# Partial Moments Expectations (pmExpectation)
##############################################
#--------------------------------------------------------------------
# Test1: 1 Dataset, 1 Method ( "sample" ), many moments
lpm1<-pmExpectation(data=as.matrix(djiaret[,1]), method="sample", 
		threshold=-0.01, moment=c(0:10), type="lower", 
		standardize=TRUE, data.names = colnames(djiaret)[1])

show(lpm1)
plot(lpm1)
#----------------------------------------------------------------------------------
# Test2: 1 Dataset, 1 Method ( "analytical/quadraure" ), many moments, 
# one distribution (bestfitted)
# REM: fit must be a list object
lpm2<-pmExpectation(f=bdistnames[2], method="analytical", fit=list(bdist[[2]]), 
		threshold=-0.01, moment=c(0:10), type="lower", standardize=TRUE, 
		data.names = colnames(djiaret)[2])

show(lpm2)
plot(lpm2)
#----------------------------------------------------------------------------------
# Test3: 1 Dataset, 1 Method ( "analytical/quadraure" ), 1 moments, many distributions
# rem fit must be a list object
# Note: You cannot have multiple moments for multiple analytic distributions
# in that case you should run seperate routines.
fx=dow30fit[[2]]@distributions
fitx = lapply(dow30fit[[2]]@gof@test,FUN=function(x) x$fit)
# check to see that fit object is list:
is(fitx) # ok

lpm3<-pmExpectation(f=fx, method="analytical", fit=fitx, threshold=-0.01, 
		moment=1, type="lower", standardize=TRUE, 
		data.names = colnames(djiaret)[2])

show(lpm3)
plot(lpm3)
#----------------------------------------------------------------------------------
# Test4: 1 Dataset, 1 Method ( "analytical/trapezium" ), many moments
# rem fit must be a list object
lpm4<-pmExpectation(f=bdistnames[2], method="analytical", analytical="trapezium", 
		fit=list(bdist[[2]]), threshold=-0.01, moment=c(0:10), 
		type="lower", standardize=TRUE, data.names = colnames(djiaret)[2])

show(lpm4)
plot(lpm4)
#----------------------------------------------------------------------------------
# Test5: 1 Dataset, 1 Method ( "analytical/trapezium" ), 1 moments, many distributions
# rem fit must be a list object
fx=dow30fit[[2]]@distributions
fitx = lapply(dow30fit[[2]]@gof@test,FUN=function(x) x$fit)

lpm5<-pmExpectation(f=fx, method="analytical", analytical="trapezium", 
		fit=fitx, threshold=-0.01, moment=1, type="lower", 
		standardize=TRUE, data.names = colnames(djiaret)[2])

show(lpm5)
plot(lpm5)
#----------------------------------------------------------------------------------
# Test6: 1 Dataset, 1 Method ( "boot" ), many moments
# rem fit must be a list object
lpm6<-pmExpectation(data=as.matrix(djiaret[,1]), method="boot", threshold=-0.01, 
		moment=c(0:10), type="lower", standardize=TRUE, 
		data.names = colnames(djiaret)[1])

show(lpm6)
plot(lpm6)
#----------------------------------------------------------------------------------
# Test7: 1 Dataset, 1 Method ( "jack" ), many moments
# rem fit must be a list object
lpm7<-pmExpectation(data=as.matrix(djiaret[,1]), method="jack", threshold=-0.01, 
		moment=c(0:10), type="lower", standardize=TRUE, 
		data.names = colnames(djiaret)[1])

show(lpm7)
plot(lpm7)
#----------------------------------------------------------------------------------
# Test8: Many Dataset, 1 Method ( "boot" ), one moment
# rem fit must be a list object
lpm8<-pmExpectation(data=as.matrix(djiaret), method="boot", threshold=-0.01, 
		moment=0, type="lower", standardize=TRUE, 
		data.names = colnames(djiaret))

show(lpm8)
plot(lpm8)
#----------------------------------------------------------------------------------
# Test9: Many Dataset, Many Methods, one moment
lpm9<-pmExpectation(f=bdistnames, data=as.matrix(djiaret), 
		method=c(rep("sample",10),rep("analytical",10),rep("boot",10)), 
		fit=bdist, threshold=-0.01, moment=2, type="lower", 
		standardize=TRUE, data.names = colnames(djiaret))

show(lpm9)
plot(lpm9)
#----------------------------------------------------------------------------------
# Test10: One Dataset, Many Methods, One Moment
fx=dow30fit[[1]]@distributions
fitx = lapply(dow30fit[[1]]@gof@test,FUN=function(x) x$fit)

lpm10<-pmExpectation(f=fx, data=as.matrix(djiaret[,1]), method=c("sample",
		"analytical","boot"), fit=fitx, threshold=-0.01, moment=2, 
		type="lower", standardize=TRUE, analytical = "quadrature",
		data.names = colnames(djiaret)[1]))
show(lpm10)
plot(lpm10)
#----------------------------------------------------------------------------------
# Test11: One Dataset, Many Methods, Many Moments
fx=dow30fit[[1]]@distributions
fitx = lapply(dow30fit[[1]]@gof@test,FUN=function(x) x$fit)

lpm11<-pmExpectation(f=fx, data=as.matrix(djiaret[,1]), method=c("sample",
		"analytical","boot"), fit=fitx, threshold=-0.01, moment=c(0,1,
		2,3,3.5,4), type="lower", standardize=TRUE,
		data.names = colnames(djiaret)[1])
show(lpm11)
plot(lpm11)
#----------------------------------------------------------------------------------
# Extractor Functions are effectively as.data.frame(PME)
# examples:
as.data.frame(lpm1)
as.data.frame(lpm2)
as.data.frame(lpm3)
as.data.frame(lpm4)
as.data.frame(lpm5)
as.data.frame(lpm11)

## End(Not run)

pmoments documentation built on May 2, 2019, 4:42 p.m.