| build.constraints {PortfolioProbe} | R Documentation |
Builds a bounds object suitable for the input linear constraints, and ensures that the constraints are in a suitable form.
build.constraints(x, bounds = NULL)
x |
required. Vector, matrix, data frame or list giving the information about the constraint(s) for each asset. See the Details section for more. |
bounds |
optional matrix of bounds.
The rows correspond to the constraints.
Rows from this matrix that match constraint names that are
created for |
a list with the following components:
lin.constraints |
a matrix or data frame similar to the input |
bounds |
a matrix with two columns and as many rows as
constraints represented by the input |
Numeric linear constraints are created with numeric data. Categorical linear constraints (and count constraints) are created with a factor, character data or logical data.
A data frame is required as the input x if more than one type of data
is given.
A list of named vectors may be given. The advantage of this is that the vectors need not be in the same order or have the exact same set of assets. The function will return an object for the assets that are in all of the components of the list.
This help was last revised 2012 June 10.
constraints.realized,
trade.optimizer,
my.sc <- matrix(c("energy", "telecom", "energy", "Germany", "France",
"France"), nrow=3, ncol=2, dimnames=list(c("Asset 1", "Asset 2",
"Asset 3"), c("Sector", "Country")))
my.constr <- build.constraints(my.sc)
my.constr$bounds[,1] <- c(-.05, -.10, 0, .05)
my.constr$bounds[,2] <- c(.15, .15, .20, .55)
random.portfolio(100, prices,
lin.constraints=my.constr$lin.constraints,
lin.bounds=my.constr$bounds,
gross.value=1e6, net.value=c(-1e5, 6e5))
my.constr2 <- build.constraints(list(NumCon=c(A=23, B=72, C=12),
Country=c(C='Estonia', B='Latvia', D='Estonia')))