Price Table
Create price table
pricetable(price, ...)
price |
a matrix |
... |
further arguments, passed to methods |
pricetable
is a helper function for extracting
prices of particular instrument at specified dates.
For this, it first creates a table that merges series
passed via ... and appends a class attribute. A [
method then allows to extract prices. Importantly, if
you ask for a subset of m rows and n columns, the
result will be a matrix of size m times n, even if
times or instruments are missing.
a numeric matrix with class attribute pricetable
Enrico Schumann
Schumann, E. (2020) Portfolio Management with R. http://enricoschumann.net/R/packages/PMwR/
## quickly creating a pricetable pricetable(1:3) pricetable(1:3, instrument = c("A", "B", "C")) ### ... and the same pricetable(c(A = 1, B = 2, C = 3)) ## subsetting examples m <- 3 n <- 2 price <- array(c(1:m, 1:m + 100), dim = c(m,n)) colnames(price) <- LETTERS[1:n] pt <- pricetable(price, timestamp = 1:m) ## A B ## 1 1 101 ## 2 2 102 ## 3 3 103 pt[ , "A"] ## A ## 1 1 ## 2 2 ## 3 3 pt[ , c("X", "A", "X")] ## X A X ## 1 NA 1 NA ## 2 NA 2 NA ## 3 NA 3 NA pt[ , c("X", "A", "X"), missing = 0] ## X A X ## 1 0 1 0 ## 2 0 2 0 ## 3 0 3 0 pt[c(0, 1.5, 4), , missing = "locf"] ## A B ## 0 NA NA ## 1.5 2 102 ## 4 3 103
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.