Advertisement
Guest User

fail

a guest
Apr 16th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. portfolio=pspec, type="group",
  2. groups=list(groupA=c(1, 2, 3),
  3. grouB=4),
  4. group_min=c(0.1, 0.15),
  5. group_max=c(0.85, 0.55)
  6.  
  7. if (!is.portfolio(portfolio)) {
  8. stop("portfolio passed in is not of class portfolio")
  9. }
  10. if (!hasArg(type))
  11. stop("you must supply a type of constraints to create")
  12. assets <- portfolio$assets
  13. tmp_constraint = NULL
  14. switch(type, box = {
  15. tmp_constraint <- box_constraint(assets = assets, type = type,
  16. enabled = enabled, message = message, ... = ...)
  17. }, long_only = {
  18. tmp_constraint <- box_constraint(assets = assets, type = type,
  19. enabled = enabled, message = message, min = 0, max = 1,
  20. ... = ...)
  21. }, group = {
  22. tmp_constraint <- group_constraint(assets = assets, type = type,
  23. enabled = enabled, message = message, ... = ...)
  24. }, weight = , leverage = , weight_sum = {
  25. tmp_constraint <- weight_sum_constraint(type = type,
  26. enabled = enabled, message = message, ... = ...)
  27. }, full_investment = {
  28. tmp_constraint <- weight_sum_constraint(type = type,
  29. min_sum = 1, max_sum = 1, enabled = enabled, message = message,
  30. ... = ...)
  31. }, dollar_neutral = , active = {
  32. tmp_constraint <- weight_sum_constraint(type = type,
  33. min_sum = 0, max_sum = 0, enabled = enabled, message = message,
  34. ... = ...)
  35. }, turnover = {
  36. tmp_constraint <- turnover_constraint(type = type, enabled = enabled,
  37. message = message, ... = ...)
  38. }, diversification = {
  39. tmp_constraint <- diversification_constraint(type = type,
  40. enabled = enabled, message = message, ... = ...)
  41. }, position_limit = {
  42. tmp_constraint <- position_limit_constraint(assets = assets,
  43. type = type, enabled = enabled, message = message,
  44. ... = ...)
  45. }, return = {
  46. tmp_constraint <- return_constraint(type = type, enabled = enabled,
  47. message = message, ... = ...)
  48. }, factor_exposure = , factor_exposures = {
  49. tmp_constraint <- factor_exposure_constraint(assets = assets,
  50. type = type, enabled = enabled, message = message,
  51. ... = ...)
  52. }, transaction = , transaction_cost = {
  53. tmp_constraint <- transaction_cost_constraint(assets = assets,
  54. type = type, enabled = enabled, message = message,
  55. ... = ...)
  56. }, leverage_exposure = {
  57. tmp_constraint <- leverage_exposure_constraint(type = type,
  58. enabled = enabled, message = message, ... = ...)
  59. }, null = {
  60. return(portfolio)
  61. })
  62. if (is.constraint(tmp_constraint)) {
  63. if (!hasArg(indexnum) | (hasArg(indexnum) & is.null(indexnum)))
  64. indexnum <- length(portfolio$constraints) + 1
  65. tmp_constraint$call <- match.call()
  66. portfolio$constraints[[indexnum]] <- tmp_constraint
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement