Learn R Programming

AssetPricing (version 0.1-2)

buildS: Build a piecewise linear price sensitivity function

Description

Builds a price sensitivity function which is piecewise linear in price, in an automated manner, with built-in checks for possible infelicities.

Usage

buildS(alpha, beta, kn, tmax)

Arguments

alpha
A list of functions of t giving the constant terms of the linear functions comprising the price sensitivity function.
beta
A list of functions of t giving the slopes of the linear functions comprising the price sensitivity function.
kn
The knots (with respect to price) of the piecewise linear price sensitivity function. The zero knot (which is always the first knot) is not included in kn.
tmax
The maximum time value to which the price sensitivity function is to be applied. Needed for internal consistency checks.

Value

  • A function of two variables x and t, which is a price sensitivity function. The argument x represents price and the argument t represents (residual) time. The value of the function is interpreted as the probability that a customer arriving at time t will purchase an item offered at price x.

Details

The price sensitivity function is assumed to be of the form $$S(x,t) = \alpha_k(t) + \beta_k(t)x$$ for $x_{k-1} \leq x \leq x_k$ where $x_1, x_2, \ldots, x_K$ are the (non-zero) knots of the function. It is assumed that $x_0 = 0$. The variable x represents price and the variable t represents residual time.

The function is defined over the rectangle $[0,x_K] \times [0,t_{\rm max}]$.

Checks are done to make sure that [object Object],[object Object],[object Object],[object Object]

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()

Examples

Run this code
lambda <- function(t) {
      tn <- 1:4
      A <- matrix(c(0,12,12,12,
              0,-16,16,64,
              20,30,30,0),nrow=4)
      B <- matrix(c(12,0,0,0,
               0,16,0,-16,
               0,-10,-10,0),nrow=4)
      s <- cut(t,breaks=c(0,tn),include.lowest=TRUE,labels=tn)
      s <- as.numeric(levels(s)[s])
      M <- matrix(A[s,] + B[s,]*t,ncol=ncol(A))
      M[!is.finite(M)] <- 0
      M
   }

   alpha <- vector("list",4)
   beta  <- vector("list",4)
   alpha[[1]] <- with(list(lambda=lambda),
	function(t) {
	A <- c(1,1,1)
        lll <- lambda(t)
        dnm <- apply(lll,1,sum)
        dnm[dnm==0] <- 1
        lll%*%A/dnm
   })
   beta[[1]] <- with(list(lambda=lambda),
	function(t) {
	B <- c(0,0,0)
        lll <- lambda(t)
        dnm <- apply(lll,1,sum)
        dnm[dnm==0] <- 1
        lll%*%B/dnm
   })
   alpha[[2]] <- with(list(lambda=lambda),
	function(t) {
	A <- c(1.495,1,1)
        lll <- lambda(t)
        dnm <- apply(lll,1,sum)
        dnm[dnm==0] <- 1
        lll%*%A/dnm
   })
   beta[[2]] <- with(list(lambda=lambda),
	function(t) {
	B <- c(-0.2475,0,0)
        lll <- lambda(t)
        dnm <- apply(lll,1,sum)
        dnm[dnm==0] <- 1
        lll%*%B/dnm
   })
   alpha[[3]] <- with(list(lambda=lambda),
	function(t) {
	A <- c(0.01,2.485,1)
        lll <- lambda(t)
        dnm <- apply(lll,1,sum)
        dnm[dnm==0] <- 1
        lll%*%A/dnm
   })
   beta[[3]] <- with(list(lambda=lambda),
	function(t) {
	B <- c(0,-0.2475,0)
        lll <- lambda(t)
        dnm <- apply(lll,1,sum)
        dnm[dnm==0] <- 1
        lll%*%B/dnm
   })
   alpha[[4]] <- with(list(lambda=lambda),
	function(t) {
	A <- c(0.01,0.01,3.475)
        lll <- lambda(t)
        dnm <- apply(lll,1,sum)
        dnm[dnm==0] <- 1
        lll%*%A/dnm
   })
   beta[[4]] <- with(list(lambda=lambda),
	function(t) {
	B <- c(0,0,-0.2475)
        lll <- lambda(t)
        dnm <- apply(lll,1,sum)
        dnm[dnm==0] <- 1
        lll%*%B/dnm
   })
   kn <- c(2,6,10,14)
   S  <- buildS(alpha,beta,kn,4)
   x  <- seq(0,14,length=41)
   t  <- seq(0,4,length=41)
   z  <- S(x,t)
persp(x,t,z,theta=150,phi=40,d=4,xlab="price",ylab="time",
         zlab="probability",ticktype="detailed")

Run the code above in your browser using DataLab