plot.AssetPricing {AssetPricing} | R Documentation |
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. Such a list is assumed to occur as
a component of an object produced by xsolve()
of
vsolve()
. The functions in the list 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 'AssetPricing'
plot(x,witch=c("price","expVal","vdot"),
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 |
witch |
A text string indicating which of the three possible components
of |
xlim |
The |
ylim |
The |
lty |
A vector of line types. It will be replicated to have a length
equal to the number of rows of |
cols |
A vector of colours for the plotted lines. It will be replicated
to have a length equal to the number of rows of |
xlab |
A text string giving a label for the |
ylab |
A text string giving a label for the |
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 |
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 unique entries of |
groups |
A data frame with one, two or three columns, named |
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 |
glind |
A logical vector indicating which entries of
|
extend |
A scalar, between 0 and 1, indicating how much
the |
col.gloss |
Scalar specifying the colour in which the
marginal gloss is to be added, e.g. |
cex.gloss |
Character expansion ( |
mfrow |
The dimensions of the array(s) of panels in which
the functions are plotted. If this argument is left as |
... |
Extra arguments to be passed to |
Details
If the argument groups
is specified then:
it must always have a column
q
. The values in this column should be integers between1
andqmax
(see below).if
jmax
(see below) is greater than 1 it must also have a columnj
. The entries of this column should be integers between1
andjmax
.if
jmax
is equal to1
then columnj
need not be present. In this case, it is internally set equal to a column of1
-s.if the
group
column is present its entries should be (consecutive) positive integers running from1
to the total number of groups.if the
group
column 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[[witch]]
is a list of price
functions, i.e. when witch
is equal to price
.
Hence “double indexing” does not apply when witch
is equal to expVal
or to vdot
. 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[[witch]]
, 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 function (i.e. plot.AssetPricing()
calls upon an
“internal” function plot.flap()
to do the hard
yakka. (Note that flap
stands for dQuotefunction list
for asset pricing.)
The function plot.flap()
makes use of 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. On the advice of Kurt Hornik (31/03/2018) I
created a new generic plot()
function in this package
(i.e. AssetPricing
) with default method equal to
graphics::plot()
, so as to properly accommodate the
existence of this modified plot.stepfun()
method.
Value
None. This function exists only for its side effect, i.e. the production of a plot or plots.
Author(s)
Rolf Turner r.turner@auckland.ac.nz http://www.stat.auckland.ac.nz/~rolf
References
P. K. Banerjee, and T. R. Turner (2012). A flexible model for the pricing of perishable assets. Omega 40:5, 533–540. DOI https://doi.org/10.1016/j.omega.2011.10.001
Rolf Turner, Pradeep Banerjee and Rayomand Shahlori (2014). Optimal Asset Pricing. Journal of Statistical Software 58:11, 1–25. DOI https://doi.org/10.18637/jss.v058.i11
See Also
Examples
## Not run:
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) 0 else 36*(1-tt)
}
OUT <- xsolve(S=S,lambda=LAMBDA,gprob=(5:1)/15,tmax=1,qmax=30,
alpha=0.5,type="dip",verbInt=2)
GLND <- rep(FALSE,30)
GLND[c(1:5,10,15,20,30)] <- TRUE
plot(OUT,witch="e",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,witch="e",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,witch="p",groups=GRPS,mfrow=c(3,2),gloss=TRUE,glind=GLND,xlab="price")
# Pretty messy looking:
GRPS$group <- 1
GLND <- unlist(lapply(1:5,function(k){(1:6)==k}))
plot(OUT,witch="p",groups=GRPS,gloss=TRUE,glind=GLND,cols=GRPS$j,xlab="price")
## End(Not run)