Learn R Programming

AssetPricing (version 0.0-10)

plot.flap: Plot a list of asset pricing functions.

Description

Plot a list of functions --- in particular optimal price functions or expected value functions or derivatives of the expected value functions. These are functions of residual time. The indices of the list correspond to the number of items available for sale and possibly (for optimal price functions) the size of the arriving group of customers.

Usage

## S3 method for class 'flap':
plot(x,xlim=NULL,ylim=NULL,lty=NULL,cols=NULL,
             xlab=NULL,ylab=NULL,main=NULL,main.panel= NULL,
             groups=NULL,add=FALSE,gloss=FALSE,glind=NULL,
             extend=0.3,col.gloss=1,cex.gloss=0.8,mfrow=NULL,...)

Arguments

x
An object of class flap such as a component of an object produced by vsolve(), or xsolve().
xlim
The x limits of the plot. Defaults to the tlim attribute of the object x. If this attribute does not exist and xlim is not supplied then an error is given.
ylim
The y limits of the plot. Defaults to the ylim attribute of the object x. If this attribute does not exist and ylim is not supplied then an error is given.
lty
A vector of line types. It will be replicated to have a length equal to the number of rows of groups (see below). Defaults to having all entries of the vector equal to 1, i.e. solid lines.
cols
A vector of colours for the plotted lines. It will be replicated to have a length equal to the number of rows of groups (see below). Defaults to having all entries of the vector equal to 1, i.e. black.
xlab
A text string giving a label for the x axis (or axes). Defaults to the null string. Ignored if add is TRUE.
ylab
A text string giving a label for the y axis (or axes). Defaults to the null string. Ignored if add is TRUE.
main
A text string giving an overall title for the plot or for each page of plots if there is more than one. Defaults to the null string and is ignored if add is TRUE.
main.panel
A text string which is replicated np times (where np is the total number of panels) or a vector of text strings of length equal to np. Note that np will be equal to the number of u
groups
A data frame with one, two or three columns, named group, q and j. The total number of rows should be less than or equal to the total number of entries of the function list x. Only those function
add
Logical scalar; should the plot be added to an existing plot?
gloss
Either a logical scalar (should a ``marginal gloss'' be added to the plot? --- if TRUE then the gloss is constructed internally; see Details) or a vector of character strings of which the marginal gloss is to consist.
glind
A logical vector indicating which entries of gloss should actually be used (plotted). I.e. marginal gloss is added for the graphs of functions whose corresponding values in the entries of glind are TRUE. Igno
extend
A scalar, between 0 and 1, indicating how much the x-axis should be extended (to the right) in order to accommodate the marginal gloss.
col.gloss
Scalar specifying the colour in which the marginal gloss is to be added, e.g. "red" (or equivalently 2). The default, i.e. 1, is black.
cex.gloss
Character expansion (cex) specifier for the marginal gloss.
mfrow
The dimensions of the array(s) of panels in which the functions are plotted.
...
Extra arguments to be passed to plot (effectively to plot.function() or to plot.stepfun()).

Value

  • None. This function exists only for its side effect, i.e. the production of a plot or plots.

Details

If the argument groups is specified then:
  • it mustalwayshave a columnq. The values in this column should be integers between1andqmax(see below).
  • ifjmax(see below) is greater than 1 it must also have a columnj. The entries of this column should be integers between1andjmax.
  • ifjmaxis equal to1then columnjneed not be present. In this case, it is internally set equal to a column of1-s.
  • if thegroupcolumn is present its entries should be (consecutive) positive integers running from1to the total number of groups.
  • if thegroupcolumn is not present then this column is internally set equal to a column of1-s i.e. there is a single group of traces.

The value of qmax is the maximum number of items that are available for sale in the time period under consideration. It may be obtained as attr(x,"qmax").

The value of jmax is, when double indexing applies, the maximum size of an arriving group of customers, and is otherwise equal to 1. It may be obtained as attr(x,"jmax"). Note that double indexing can only apply when x is a list of price functions. Hence double indexing does not apply when x is a list of expected value functions or of their derivatives). In these cases jmax is equal to 1.

If groups is not specified then it defaults to a data frame with number of rows equal to the length of x, The group column has entries all equal to 1, i.e. there is a single group of traces. The q and j columns contain all possible (valid) combinations of stock size and customer group size.

If gloss is FALSE then no marginal gloss is plotted. If gloss is TRUE then the marginal gloss is created from the values of the q and j entries in the columns of groups using paste().

Note that if add is TRUE then the gloss may not actually appear in the plot, since it is placed at the right hand edge of the plot and may consequently be outside of the plotting region. Thus if you wish to use a gloss when adding to an existing plot you will probably need to take steps to ensure that there is room in the right hand margin for the plot to appear, or possibly set par(xpd=NA).

If double indexing applies then x[[i]] corresponds to a stock size of q and a customer group size of j where i = (j-1)*(qmax - j/2) + q.

To get traces plotted in individual panels (one trace per panel) set the group column of groups to be 1:n where n is the total number of traces being plotted.

This package uses a modified version of plot.stepfun() rather than the one which appears in package:stats. The modification causes plot.stepfun() to treat the xlim argument in a manner similar to the way in which it is treated by plot.function. Note that plot.stepfun() is not exported from this package.

References

Banerjee, P. K. and Turner, T. R. A flexible model for the pricing of perishable assets. Omega, vol. 40, number 5, 2012, pages 533 -- 540, doi: 10.1016/j.omega.2011.10.001.

See Also

xsolve() vsolve(),

Examples

Run this code
S <- expression(exp(-kappa*x/(1+gamma*exp(-beta*t))))
attr(S,"parvec") <- c(kappa=10/1.5,gamma=9,beta=1)
LAMBDA <- function(tt){
    if(tt<0 | tt> 1) stop("Time out of range.\n")
    36*(1-tt)
}
OUT <- xsolve(S=S,lambda=LAMBDA,gprob=(5:1)/15,tmax=1,qmax=30,
                  nstep=1000,alpha=0.5,type="dip",nverb=20)
GLND <- rep(FALSE,30)
GLND[c(1:5,10,15,20,30)] <- TRUE
plot(OUT$v,xlab="residual time",ylab="expected revenue",
     gloss=TRUE,glind=GLND)
GRPS <- data.frame(group=rep(1:6,each=5),q=1:30)
GLND <- c(TRUE,FALSE,TRUE,FALSE,TRUE,rep(c(rep(FALSE,4),TRUE),5))
plot(OUT$v,groups=GRPS,xlab="residual time",ylab="expected revenue",
     gloss=TRUE,glind=GLND)
GRPS <- data.frame(group=rep(1:5,each=6),j=rep(1:5,each=6))
GRPS$q <- with(GRPS,pmax(j,rep(c(1,6,11,16,21,26),5)))
GLND <- rep(c(TRUE,TRUE,rep(FALSE,3),TRUE),5)
plot(OUT$x,groups=GRPS,mfrow=c(3,2),gloss=TRUE,glind=GLND)
# Pretty messy looking:
GRPS$group <- 1
GLND <- unlist(lapply(1:5,function(k){(1:6)==k}))
plot(OUT$x,groups=GRPS,gloss=TRUE,glind=GLND,cols=GRPS$j)

Run the code above in your browser using DataLab