build.constraints {PortfolioProbe} | R Documentation

## Build Constraints for Optimization

### Description

Builds a bounds object suitable for the input linear constraints, and ensures that the constraints are in a suitable form.

### Usage

    build.constraints(x, bounds = NULL)

### Arguments

`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 `x` are put into the output `bounds` matrix.

### Value

a list with the following components:

`lin.constraints` | a matrix or data frame similar to the input `x`. This always has column names so that the constraints can be identified.
`bounds` | a matrix with two columns and as many rows as constraints represented by the input `x`. Numeric columns of `x` embody one constraint. Columns that are factors or character or logical represent as many constraints as there are unique values in the column.

### Details

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.

### Revision

This help was last revised 2012 June 10.

### See Also

`constraints.realized`, `trade.optimizer`,

### Examples

    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')))

[Package PortfolioProbe version 1.06 Index]