#' Underlying class
#'
#' Abstract class
#'
#' @author elh
Underlying <- setClass(
# Name of the class
"Underlying",
# Define the slots
slots = c(
grid = "numeric",
path = "numeric"
),
# Test whether grid and path have the same size
validity=function(object)
{
if(length(grid)!=length(path)) stop("Grid and Path can't be with different size.")
return(T)
},
contains=c("VIRTUAL")
)
setMethod(
f = "asset",
signature = "Underlying",
definition = function(this,...)
{
stop("abstract method")
}
)
setMethod(
f = "phi",
signature = "Underlying",
definition = function(this, maturity)
{
stop("abstract method")
}
)
setMethod(
f = "display",
signature = "Underlying",
definition = function(this)
{
require(ggplot2)
df <- data.frame(grid = this@grid, path = this@path)
return(ggplot(df, aes(x=grid))+geom_point(aes(y=path)))
}
)
setMethod(
f = "concatenate",
signature = c("Underlying","Underlying"),
definition = function(u1, u2)
{
if(tail(u1@grid, n=1) > head(u2@grid, n=1))
stop(paste("incoherent grid - tail of", deparse(substitute(u1)), "is greater than head of", deparse(substitute(u2))))
else if(tail(u1@grid, n=1) < head(u2@grid, n=1))
warnings("grid gap")
else
stopifnot(tail(u1@path, n=1) == head(u2@path, n=1))
u1@grid <- union(u1@grid, u2@grid)
u1@path <- union(u1@path, u2@path)
return(u1)
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.