Learn R Programming

PortfolioAnalytics (version 2.0.0)

position_limit_constraint: constructor for filter_constraint

Description

This function is called by add.constraint when type="filter" is specified, add.constraint

Usage

position_limit_constraint(
  type = "position_limit",
  filter_name = NULL,
  enabled = TRUE,
  message = FALSE,
  ...
)

Value

an object of class 'position_limit_constraint'

Arguments

type

character type of the constraint

filter_name

either a function to apply, or a name of a function to apply

enabled

TRUE/FALSE

message

TRUE/FALSE. The default is message=FALSE. Display messages if TRUE.

...

any other passthru parameters to specify position limit constraints

Author

Ross Bennett

Details

Allows the user to specify a filter function which will take returns, weights, and constraints as inputs, and can return a modified weights vector as output.

Fundamentally, it could be used to filter out certain assets, or to ensure that they must be long or short.

Typically, filter functions will be called by the random portfolio simulation function or via the fn_map function.

See Also

add.constraint

Examples

Run this code
data(edhec)
ret <- edhec[, 1:4]

pspec <- portfolio.spec(assets=colnames(ret))

pspec <- add.constraint(portfolio=pspec, type="position_limit", max_pos=3)
pspec <- add.constraint(portfolio=pspec, type="position_limit", max_pos_long=3, max_pos_short=1)

Run the code above in your browser using DataLab