Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- portfolio=pspec, type="group",
- groups=list(groupA=c(1, 2, 3),
- grouB=4),
- group_min=c(0.1, 0.15),
- group_max=c(0.85, 0.55)
- if (!is.portfolio(portfolio)) {
- stop("portfolio passed in is not of class portfolio")
- }
- if (!hasArg(type))
- stop("you must supply a type of constraints to create")
- assets <- portfolio$assets
- tmp_constraint = NULL
- switch(type, box = {
- tmp_constraint <- box_constraint(assets = assets, type = type,
- enabled = enabled, message = message, ... = ...)
- }, long_only = {
- tmp_constraint <- box_constraint(assets = assets, type = type,
- enabled = enabled, message = message, min = 0, max = 1,
- ... = ...)
- }, group = {
- tmp_constraint <- group_constraint(assets = assets, type = type,
- enabled = enabled, message = message, ... = ...)
- }, weight = , leverage = , weight_sum = {
- tmp_constraint <- weight_sum_constraint(type = type,
- enabled = enabled, message = message, ... = ...)
- }, full_investment = {
- tmp_constraint <- weight_sum_constraint(type = type,
- min_sum = 1, max_sum = 1, enabled = enabled, message = message,
- ... = ...)
- }, dollar_neutral = , active = {
- tmp_constraint <- weight_sum_constraint(type = type,
- min_sum = 0, max_sum = 0, enabled = enabled, message = message,
- ... = ...)
- }, turnover = {
- tmp_constraint <- turnover_constraint(type = type, enabled = enabled,
- message = message, ... = ...)
- }, diversification = {
- tmp_constraint <- diversification_constraint(type = type,
- enabled = enabled, message = message, ... = ...)
- }, position_limit = {
- tmp_constraint <- position_limit_constraint(assets = assets,
- type = type, enabled = enabled, message = message,
- ... = ...)
- }, return = {
- tmp_constraint <- return_constraint(type = type, enabled = enabled,
- message = message, ... = ...)
- }, factor_exposure = , factor_exposures = {
- tmp_constraint <- factor_exposure_constraint(assets = assets,
- type = type, enabled = enabled, message = message,
- ... = ...)
- }, transaction = , transaction_cost = {
- tmp_constraint <- transaction_cost_constraint(assets = assets,
- type = type, enabled = enabled, message = message,
- ... = ...)
- }, leverage_exposure = {
- tmp_constraint <- leverage_exposure_constraint(type = type,
- enabled = enabled, message = message, ... = ...)
- }, null = {
- return(portfolio)
- })
- if (is.constraint(tmp_constraint)) {
- if (!hasArg(indexnum) | (hasArg(indexnum) & is.null(indexnum)))
- indexnum <- length(portfolio$constraints) + 1
- tmp_constraint$call <- match.call()
- portfolio$constraints[[indexnum]] <- tmp_constraint
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement