Hi John, See responses inline.
On Wed, Feb 5, 2014 at 8:36 PM, John Kaprich <[email protected]> wrote: > I am excited about the potential benefits the PortfolioAnalytics package > provides, but am new to working with the package. > > My objective is to calculate a constrained risk budget for a given CVaR > level. When I run the code below I get the following error: > > Leverage constraint min_sum and max_sum are restrictive, consider relaxing. > e.g. 'full_investment' constraint should be min_sum=0.99 and max_sum=1.01 > Error > in seq.default(from = round(min, rounding), to = round(max, rounding), : > 'from' cannot be NA, NaN or infinite > > > Aren't the defaults for full_investment (min_sum = 0.99 and max_sum = > 1.01) what is being stated in the error message? Or is my objective > too restrictive? It depends on how the constraint was added. add.constraint(portfolio, "leverage") # defaults to min_sum=0.99 and max_sum=1.01 add.constraint(portfolio, "full_investment") # sets min_sum=1 and max_sum=1 > Also, is the Error (seq.default) related to the > full_investment constraint? > I suspect that you either do not have box constraints or your box constraints are -Inf to Inf. We use generatesequence() to generate a set of weights for random portfolios. Even if you are using DEoptim, we generate random portfolios as the initial population for DEoptim. You can either add box constraints or specify a weight_seq in portfolio.spec(). # This is how you would add a weight_seq for a long only portfolio # Adding long only box constraints would implicitly do the same thing init.portf <- portfolio.spec(funds, weight_seq=generatesequence(min=0, max=1, by=0.002)) > > > Also, I read a post in 2010 that stated group constraints were not > compatible with DEoptim. Is this still the case? > Group constraints were added during the GSoC 2013 project and are now supported by DEoptim. > > > Appreciate any help you may be able to provide me and thanks for the > great package. > You're welcome, glad to help. Regards, Ross > > > > Sincerely, > > > > John E. Kaprich > > R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" > Copyright (C) 2013 The R Foundation for Statistical Computing > Platform: x86_64-w64-mingw32/x64 (64-bit) > > R is free software and comes with ABSOLUTELY NO WARRANTY. > You are welcome to redistribute it under certain conditions. > Type 'license()' or 'licence()' for distribution details. > > R is a collaborative project with many contributors. > Type 'contributors()' for more information and > 'citation()' on how to cite R or R packages in publications. > > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for an HTML browser interface to help. > Type 'q()' to quit R. > > [Workspace loaded from ~/RStudio Working Directory/.RData] > > library("doParallel", lib.loc="C:/Program > Files/R/R-3.0.2/library")Loading required package: foreachforeach: simple, > scalable parallel programming from Revolution Analytics > Use Revolution R for scalability, fault tolerance and > more.http://www.revolutionanalytics.comLoading required package: > iteratorsLoading required package: parallel> library("DEoptim", > lib.loc="C:/Program Files/R/R-3.0.2/library") > DEoptim package > Differential Evolution algorithm in R > Authors: D. Ardia, K. Mullen, B. Peterson and J. Ulrich > > library("PortfolioAnalytics", lib.loc="C:/Program > Files/R/R-3.0.2/library")Loading required package: zoo > Attaching package: 'zoo' > The following objects are masked from 'package:base': > > as.Date, as.Date.numeric > Loading required package: xtsLoading required package: PerformanceAnalytics > Package PerformanceAnalytics (1.1.0) loaded. > Econometric tools for performance and risk analysis. > (c) 2004-2012 Peter Carl, Brian G. Peterson. License: > GPLhttp://r-forge.r-project.org/projects/returnanalytics/ > > Attaching package: 'PerformanceAnalytics' > The following object is masked from 'package:graphics': > > legend > > library("timeSeries", lib.loc="C:/Program > Files/R/R-3.0.2/library")Loading required package: timeDate > Attaching package: 'timeDate' > The following objects are masked from 'package:PerformanceAnalytics': > > kurtosis, skewness > > Attaching package: 'timeSeries' > The following object is masked from 'package:zoo': > > time<- > > > ### Import Pricing Data into R ###> > Pricing <- > read.table("RDataAA.txt", header=TRUE, sep="\t", colClasses = > c("character", "numeric", > "numeric","numeric","numeric","numeric","numeric","numeric","numeric","numeric","numeric", > "numeric"))> PricingTS <- timeSeries (Pricing[-1], Pricing[[1]], format = > "%Y/%m/%d")> is.timeSeries(PricingTS)[1] TRUE> > ### Convert Pricing Data > into Percentage Returns ###> > AAReturns <- diff(log(PricingTS))> AARet <- > AAReturns [-1,]> is.timeSeries(AARet)[1] TRUE> > > > > > summary(AARet) LCEquity SCEquity DevFEquity > DevFSCEquity > Min. :-0.0694875 Min. :-0.0910853 Min. :-7.774e-02 Min. > :-0.0932107 > 1st Qu.:-0.0043533 1st Qu.:-0.0059912 1st Qu.:-6.413e-03 1st > Qu.:-0.0060075 > Median : 0.0006532 Median : 0.0009359 Median : 1.117e-03 Median > : 0.0007584 > Mean : 0.0004196 Mean : 0.0004097 Mean : 5.035e-05 Mean > : 0.0001602 > 3rd Qu.: 0.0057196 3rd Qu.: 0.0081454 3rd Qu.: 7.791e-03 3rd > Qu.: 0.0075388 > Max. : 0.0438853 Max. : 0.0645193 Max. : 6.519e-02 Max. > : 0.0801522 > EMEquity CoreFI HYFI > Preferred > Min. :-0.0870541 Min. :-1.252e-02 Min. :-4.344e-02 Min. > :-0.0999697 > 1st Qu.:-0.0088591 1st Qu.:-1.267e-03 1st Qu.:-2.484e-03 1st > Qu.:-0.0017787 > Median : 0.0004951 Median : 1.791e-04 Median : 0.000e+00 Median > : 0.0002802 > Mean :-0.0001952 Mean : 2.672e-05 Mean :-3.520e-06 Mean > :-0.0000758 > 3rd Qu.: 0.0083477 3rd Qu.: 1.372e-03 3rd Qu.: 2.535e-03 3rd > Qu.: 0.0020096 > Max. : 0.0605309 Max. : 8.360e-03 Max. : 2.850e-02 Max. > : 0.0683953 > BankLoans EMSovDebt Commodities > Min. :-4.007e-02 Min. :-2.956e-02 Min. :-0.0562138 > 1st Qu.:-8.200e-04 1st Qu.:-1.923e-03 1st Qu.:-0.0055469 > Median : 0.000e+00 Median : 3.681e-04 Median : 0.0000000 > Mean :-2.058e-05 Mean : 3.062e-05 Mean :-0.0004546 > 3rd Qu.: 1.205e-03 3rd Qu.: 2.383e-03 3rd Qu.: 0.0055249 > Max. : 1.810e-02 Max. : 2.458e-02 Max. : 0.0339187 > > > > > ### Develop Portfolio Constraints ###> > AAFrontier <- > portfolio.spec(assets=colnames(AARet[,1:11]))> AAFrontier <- > add.constraint(AAFrontier, type="full_investment", enabled = TRUE)> > AAFrontier <- add.constraint(AAFrontier, type = "group",+ groups = > list(Equity=c(1,2,3,4,5),+ Foreign = c(3,4,5,10),+ High_Yield = c(7,9)),+ > group_min = c(0,0,0),+ group_max = c(0.2,0.15,0.15))> > ### Develop > Portfolio Objectives ###> > AAFrontier <- add.objective(AAFrontier, type = > "risk_budget",+ name = "CVaR", enabled = TRUE,+ min_prisk=-Inf,+ > max_prisk=0.3)> > ### Optimize Portfolio ###> > AAFrontierDE <- > optimize.portfolio(AARet[,1:11], AAFrontier,+ optimize_method=c("DEoptim"), > search_size = 2000, trace=FALSE)Leverage constraint min_sum and max_sum are > restrictive, > consider relaxing. e.g. 'full_investment' constraint > should be min_sum=0.99 and max_sum=1.01Error in seq.default(from = > round(min, rounding), to = round(max, rounding), : > 'from' cannot be NA, NaN or infinite > > > > > PricingTSGMT > LCEquity SCEquity DevFEquity DevFSCEquity EMEquity CoreFI > HYFI Preferred BankLoans > 2011-03-03 74.21 82.80 61.79 43.84 46.85 104.74 > 40.63 39.42 25.13 > 2011-03-04 73.67 82.44 61.23 43.68 46.90 105.02 > 40.49 39.48 25.08 > 2011-03-07 73.05 81.09 60.64 43.48 46.24 105.07 > 40.57 39.32 25.06 > 2011-03-08 73.67 82.41 60.83 43.46 46.86 104.99 > 40.53 39.43 25.01 > 2011-03-09 73.55 82.08 60.85 43.43 46.95 105.24 > 40.39 39.47 25.06 > 2011-03-10 72.23 79.97 59.34 42.29 45.56 105.61 > 40.23 39.39 25.03 > 2011-03-11 72.70 80.18 59.34 42.23 46.03 105.63 > 40.28 39.45 24.99 > 2011-03-14 72.30 79.75 58.28 41.30 46.30 105.69 > 40.14 39.39 24.92 > 2011-03-15 71.51 79.04 57.06 40.21 45.53 105.73 > 39.87 39.32 24.59 > 2011-03-16 70.25 78.25 55.29 39.32 44.60 106.03 > 39.58 39.22 24.53 > 2011-03-17 71.08 78.42 57.13 40.49 45.15 105.96 > 40.02 39.19 24.67 > 2011-03-18 71.36 79.46 57.92 41.53 45.23 105.92 > 40.23 39.34 24.83 > 2011-03-21 72.46 81.30 59.35 42.66 46.10 105.67 > 40.45 39.41 24.88 > 2011-03-22 72.21 80.87 59.18 42.50 46.24 105.68 > 40.46 39.45 24.90 > 2011-03-23 72.40 81.12 59.25 42.46 46.85 105.63 > 40.39 39.49 24.94 > 2011-03-24 72.81 81.51 60.04 43.06 47.39 105.34 > 40.42 39.47 24.97 > 2011-03-25 73.08 82.22 59.38 42.61 47.34 105.25 > 40.40 39.53 25.02 > 2011-03-28 72.90 82.04 59.35 42.59 47.10 105.20 > 40.40 39.54 25.04 > 2011-03-29 73.38 82.81 59.66 42.85 47.64 105.07 > 40.42 39.53 25.06 > 2011-03-30 73.91 83.88 60.37 43.34 48.25 105.25 > 40.52 39.61 25.11 > 2011-03-31 73.87 84.17 60.08 43.34 48.67 105.13 > 40.51 39.65 25.12 > 2011-04-01 74.19 84.54 60.65 43.43 49.45 104.96 > 40.21 39.57 25.10 > 2011-04-04 74.25 84.73 60.73 43.64 49.87 105.13 > 40.51 39.57 25.19 > 2011-04-05 74.28 85.19 60.58 43.43 49.77 104.91 > 40.40 39.66 25.19 > 2011-04-06 74.46 85.38 61.08 43.59 50.04 104.60 > 40.50 39.65 25.24 > 2011-04-07 74.30 84.87 60.78 43.31 49.99 104.76 > 40.56 39.53 25.28 > 2011-04-08 74.00 83.98 61.28 43.67 50.04 104.56 > 40.51 39.58 25.29 > 2011-04-11 73.77 83.23 61.16 43.58 49.45 104.66 > 40.46 39.48 25.31 > 2011-04-12 73.20 82.14 60.59 43.09 48.52 105.06 > 40.34 39.39 25.28 > 2011-04-13 73.23 82.25 60.77 43.22 48.92 105.17 > 40.56 39.38 25.31 > 2011-04-14 73.27 82.63 61.04 43.70 49.07 105.07 > 40.41 39.37 25.30 > 2011-04-15 73.58 83.51 60.95 43.71 49.14 105.45 > 40.49 39.38 25.27 > 2011-04-18 72.73 82.13 59.70 43.00 47.90 105.63 > 40.29 39.32 25.22 > 2011-04-19 73.11 82.15 60.14 43.39 48.59 105.84 > 40.46 39.47 25.25 > 2011-04-20 74.18 83.83 61.67 44.31 49.74 105.69 > 40.57 39.58 25.28 > 2011-04-21 74.56 84.45 62.07 44.64 50.18 105.76 > 40.71 39.67 25.28 > 2011-04-25 74.48 84.34 62.07 44.77 49.77 105.82 > 40.67 39.74 25.27 > 2011-04-26 75.13 85.18 62.55 44.99 50.20 106.21 > 40.75 39.82 25.26 > 2011-04-27 75.59 85.69 63.33 45.45 50.11 106.12 > 40.73 39.90 25.26 > 2011-04-28 75.83 86.08 63.76 45.82 49.70 106.37 > 40.81 39.96 25.28 > 2011-04-29 76.05 86.39 63.46 45.89 50.00 106.46 > 40.90 40.06 25.28 > 2011-05-02 75.92 85.38 63.87 45.85 50.01 106.20 > 40.64 39.78 25.28 > 2011-05-03 75.59 84.30 63.35 45.44 48.90 106.23 > 40.66 39.83 25.27 > 2011-05-04 75.05 83.21 62.81 45.07 48.09 106.43 > 40.63 39.87 25.27 > 2011-05-05 74.47 82.83 61.57 44.26 47.63 106.67 > 40.49 39.77 25.25 > 2011-05-06 74.74 83.27 61.60 44.33 48.25 106.66 > 40.72 39.82 25.27 > 2011-05-09 75.10 84.24 62.04 44.71 48.34 106.78 > 40.71 39.90 25.28 > 2011-05-10 75.76 85.53 62.63 45.24 48.91 106.59 > 40.78 40.00 25.28 > 2011-05-11 74.99 83.95 61.37 44.41 47.83 106.78 > 40.71 40.02 25.27 > 2011-05-12 75.33 84.69 61.57 44.41 47.97 106.62 > 40.74 40.06 25.25 > 2011-05-13 74.72 83.51 60.61 43.66 46.92 106.79 > 40.63 40.11 25.21 > 2011-05-16 74.24 82.29 60.50 43.54 46.85 107.02 > 40.69 40.06 25.20 > 2011-05-17 74.16 82.03 60.63 43.52 47.00 107.14 > 40.77 40.10 25.20 > 2011-05-18 74.86 83.29 61.00 43.77 47.76 106.97 > 40.84 40.09 25.19 > 2011-05-19 75.01 83.47 61.35 43.88 47.45 106.89 > 40.80 40.12 25.17 > 2011-05-20 74.50 82.86 60.48 43.53 47.07 106.99 > 40.81 40.09 25.16 > 2011-05-23 73.56 81.37 59.08 42.50 46.09 107.08 > 40.66 40.03 25.14 > 2011-05-24 73.53 80.98 59.42 42.78 46.55 107.12 > 40.52 40.03 25.13 > 2011-05-25 73.78 82.00 59.80 43.00 46.65 107.10 > 40.57 40.04 25.09 > 2011-05-26 74.16 83.08 60.36 43.42 47.25 107.33 > 40.57 40.01 25.05 > 2011-05-27 74.50 83.65 60.80 43.86 47.75 107.43 > 40.77 40.07 25.05 > 2011-05-31 75.22 84.84 62.06 44.77 48.53 107.46 > 40.88 40.09 25.08 > 2011-06-01 73.56 82.11 60.59 43.90 47.66 107.61 > 40.31 39.76 25.10 > 2011-06-02 73.49 82.08 60.90 44.31 48.11 107.18 > 40.32 39.64 25.09 > 2011-06-03 72.72 80.88 60.93 44.29 47.87 107.32 > 40.05 39.61 25.06 > 2011-06-06 71.93 79.55 60.14 43.82 47.10 107.34 > 39.96 39.51 25.03 > 2011-06-07 71.93 79.74 60.69 44.09 47.47 107.56 > 40.02 39.51 25.01 > 2011-06-08 71.59 78.85 59.91 43.51 47.13 107.65 > 39.88 39.39 24.98 > 2011-06-09 72.07 79.27 60.53 43.90 47.50 107.49 > 39.92 39.36 24.97 > 2011-06-10 71.06 78.00 59.13 42.95 46.47 107.48 > 39.52 39.30 24.92 > 2011-06-13 71.06 77.78 59.22 42.94 46.39 107.34 > 39.41 39.27 24.88 > 2011-06-14 71.99 79.45 60.27 43.54 47.09 107.05 > 39.73 39.38 24.93 > 2011-06-15 70.75 78.03 58.29 42.32 46.08 107.32 > 39.52 39.23 24.84 > 2011-06-16 70.86 78.21 58.09 41.97 45.73 107.39 > 38.78 38.86 24.74 > 2011-06-17 71.05 78.23 58.66 42.36 45.79 107.49 > 39.38 39.11 24.72 > 2011-06-20 71.42 78.95 58.59 42.05 45.72 107.35 > 39.49 39.14 24.73 > 2011-06-21 72.44 80.66 59.86 42.91 46.56 107.45 > 39.75 39.25 24.76 > 2011-06-22 72.03 80.04 58.15 42.17 45.64 107.38 > 39.42 39.28 24.74 > 2011-06-23 71.87 80.35 57.65 41.87 45.58 107.73 > 39.59 39.27 24.62 > 2011-06-24 71.05 79.94 57.10 41.34 45.50 107.63 > 39.45 39.22 24.70 > 2011-06-27 71.61 80.56 57.57 41.57 46.03 107.44 > 39.47 39.19 24.69 > 2011-06-28 72.57 81.81 58.26 42.18 46.66 107.01 > 39.68 39.44 24.72 > 2011-06-29 73.22 82.20 59.28 42.91 47.09 106.69 > 39.93 39.50 24.75 > 2011-06-30 73.89 82.80 60.14 43.63 47.60 106.67 > 40.22 39.66 24.83 > 2011-07-01 74.98 84.09 60.80 44.05 48.16 106.40 > 40.28 39.47 24.88 > 2011-07-05 74.62 84.04 60.44 43.94 48.14 106.81 > 40.24 39.52 24.92 > 2011-07-06 74.76 84.38 60.06 43.68 47.82 106.87 > 40.16 39.49 24.93 > 2011-07-07 75.54 85.65 60.58 44.06 48.48 106.57 > 40.39 39.57 24.85 > 2011-07-08 75.02 85.13 59.83 43.66 47.93 107.12 > 40.35 39.55 24.90 > 2011-07-11 73.60 83.32 58.02 42.37 46.59 107.41 > 39.96 39.36 24.90 > 2011-07-12 73.28 82.85 57.63 42.04 46.12 107.50 > 39.86 39.23 24.84 > 2011-07-13 73.54 83.59 58.49 42.87 46.87 107.71 > 40.10 39.35 24.87 > 2011-07-14 73.01 82.26 57.98 42.55 46.37 107.44 > 40.15 39.26 24.89 > 2011-07-15 73.42 82.81 58.18 42.66 46.66 107.59 > 40.11 39.30 24.83 > 2011-07-18 72.74 81.48 57.32 41.90 46.12 107.43 > 39.96 39.04 24.77 > 2011-07-19 73.96 83.32 58.18 42.40 46.79 107.66 > 40.19 39.08 24.81 > 2011-07-20 73.93 83.18 58.87 42.80 46.93 107.49 > 40.23 39.15 24.82 > 2011-07-21 74.92 83.94 60.12 43.56 47.68 107.32 > 40.45 39.31 24.82 > 2011-07-22 74.99 84.05 60.18 43.66 47.65 107.55 > 40.44 39.37 24.83 > 2011-07-25 74.55 83.06 59.80 43.67 47.55 107.24 > 40.28 39.19 24.81 > EMSovDebt Commodities > 2011-03-03 26.27 50.97 > 2011-03-04 26.29 51.29 > 2011-03-07 26.36 51.06 > 2011-03-08 26.43 50.70 > 2011-03-09 26.47 50.41 > 2011-03-10 26.44 49.65 > 2011-03-11 26.46 49.38 > 2011-03-14 26.48 49.35 > 2011-03-15 26.32 47.71 > 2011-03-16 26.15 47.75 > 2011-03-17 26.26 49.36 > 2011-03-18 26.33 49.99 > 2011-03-21 26.38 50.11 > 2011-03-22 26.33 50.50 > 2011-03-23 26.39 50.75 > 2011-03-24 26.40 50.87 > 2011-03-25 26.40 51.17 > 2011-03-28 26.32 50.33 > 2011-03-29 26.34 50.39 > 2011-03-30 26.37 50.36 > 2011-03-31 26.42 51.35 > 2011-04-01 26.52 51.49 > 2011-04-04 26.50 51.74 > 2011-04-05 26.51 51.72 > 2011-04-06 26.56 51.93 > 2011-04-07 26.55 51.91 > 2011-04-08 26.59 52.71 > 2011-04-11 26.56 52.10 > 2011-04-12 26.54 51.11 > 2011-04-13 26.55 51.25 > 2011-04-14 26.55 51.54 > 2011-04-15 26.47 51.61 > 2011-04-18 26.41 51.48 > 2011-04-19 26.46 51.77 > 2011-04-20 26.52 52.34 > 2011-04-21 26.51 52.77 > 2011-04-25 26.50 52.67 > 2011-04-26 26.51 52.53 > 2011-04-27 26.60 52.68 > 2011-04-28 26.63 52.41 > 2011-04-29 26.71 53.11 > 2011-05-02 26.77 52.47 > 2011-05-03 26.85 52.09 > 2011-05-04 26.88 51.04 > 2011-05-05 26.88 48.25 > 2011-05-06 26.92 48.22 > 2011-05-09 27.01 49.32 > 2011-05-10 27.05 49.67 > 2011-05-11 27.07 48.14 > 2011-05-12 27.13 48.23 > 2011-05-13 26.96 48.23 > 2011-05-16 27.02 47.90 > 2011-05-17 27.04 48.09 > 2011-05-18 27.06 49.02 > 2011-05-19 27.07 48.51 > 2011-05-20 27.08 48.99 > 2011-05-23 27.01 48.41 > 2011-05-24 26.96 48.75 > 2011-05-25 27.02 49.42 > 2011-05-26 26.96 49.51 > 2011-05-27 26.96 49.99 > 2011-05-31 27.17 50.33 > 2011-06-01 27.08 49.73 > 2011-06-02 27.10 50.15 > 2011-06-03 27.14 50.15 > 2011-06-06 27.13 49.62 > 2011-06-07 27.13 49.87 > 2011-06-08 27.17 50.31 > 2011-06-09 27.17 50.40 > 2011-06-10 27.19 49.92 > 2011-06-13 27.16 49.30 > 2011-06-14 27.17 49.58 > 2011-06-15 27.03 48.69 > 2011-06-16 26.88 48.21 > 2011-06-17 26.90 47.95 > 2011-06-20 26.92 47.90 > 2011-06-21 27.05 48.25 > 2011-06-22 27.02 47.94 > 2011-06-23 27.00 47.18 > 2011-06-24 26.99 46.77 > 2011-06-27 27.03 46.58 > 2011-06-28 27.08 47.36 > 2011-06-29 27.08 47.96 > 2011-06-30 27.09 47.23 > 2011-07-01 27.18 47.21 > 2011-07-05 27.21 47.94 > 2011-07-06 27.12 47.79 > 2011-07-07 27.13 48.53 > 2011-07-08 27.18 48.42 > 2011-07-11 27.18 48.21 > 2011-07-12 27.08 48.77 > 2011-07-13 27.14 49.58 > 2011-07-14 27.21 49.27 > 2011-07-15 27.09 49.65 > 2011-07-18 27.08 49.47 > 2011-07-19 27.02 49.70 > 2011-07-20 27.13 49.63 > 2011-07-21 27.16 49.41 > 2011-07-22 27.17 49.83 > 2011-07-25 27.19 49.70 > > [[alternative HTML version deleted]] > > _______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions > should go. > [[alternative HTML version deleted]] _______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
