pricetable {PMwR} | R Documentation |
Price Table
Description
Create price table
Usage
pricetable(price, ...)
Arguments
price |
a matrix |
... |
further arguments, passed to methods |
Details
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.
pricetable
is a generic function, currently
with methods for numeric vectors (including vectors
with a dim
, aka matrices) and for
zoo
objects.
Value
a numeric matrix with class attribute pricetable
Author(s)
Enrico Schumann
References
Schumann, E. (2023) Portfolio Management with R. https://enricoschumann.net/PMwR/
See Also
Examples
## 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
[Package PMwR version 0.19-5 Index]