R/a2sf.R

Defines functions a2sf

Documented in a2sf

a2sf <- function(x,tt,xlim,npts=1000) {
#
# Convert a function built by approx() to a step function.
#
if(missing(tt)) {
	if(missing(xlim))
		stop("One of tt and xlim must be specified.\n")
	tt <- seq(xlim[1],xlim[2],length=npts)
}
y <- x(tt)
dy <- diff(y)
iii <- which(dy!=0)
if(length(iii)==0) {
	knots <- range(tt)
	values <- c(y[1],y[1],y[1])
} else {
	knots <- tt[iii]
	values <- c(y[1],y[1+iii])
}
stepfun(x=knots,y=values)
}

Try the AssetPricing package in your browser

Any scripts or data that you put into this service are public.

AssetPricing documentation built on Oct. 8, 2021, 1:07 a.m.