Skip to content

PortfolioAnalytics Package Questions on Initial Weights & Group Constraints

3 messages · Brian G. Peterson, Ed Herranz

#
Dear R-sig-finance Group,

I have 3 of questions about the PortfolioAnalytics package:

1) I'm using DEOptim optimization.  And I use the following initialization:

  i.portf <- portfolio.spec(assets=allInstruments,
                            weight_seq=generatesequence(min = 0.001,
                                                        max = 0.06,
                                                        by = 0.002))
I believe that the initial portfolios are generated randomly using
random_portfolios.   However, if I wanted to specifically pre-set one of
the portfolios to a given set of predefined weights, would that be possible
with DEOPtim?

2) I'm using group constraints to specify the sum of weights by group.  For
example on Sectors:

  for( jj in 1:length(uniqueSectors)){
    group_indices <- which(sectors == uniqueSectors[jj])
    groupsum <- sum(benchmark_weights[group_indices])
    groupmax <- 0.1 + groupsum
    groupmin <- -0.1 + groupsum

    groupmins[jj]   <- groupmin
    groupmaxs[jj]   <- groupmax
    grouplist[[jj]] <- group_indices
  }

    i.portf <- add.constraint(portfolio=i.portf,
                              type="group",
                              groups=grouplis,
                              group_min=groupmins,
                              group_max=groupmaxs,
                              group_labels=groupnames)

  There is nothing stopping me from making two separate add.constraint()
group calls by splitting the initial groups' constraints into 2

    i.portf <- add.constraint(portfolio=i.portf,
                              type="group",
                              groups=grouplist[1:5],
                              group_min=groupmins[1:5],
                              group_max=groupmaxs[1:5],
                              group_labels=groupnames[1:5])
    i.portf <- add.constraint(portfolio=i.portf,
                              type="group",
                              groups=grouplist[5:10],
                              group_min=groupmins[5:10],
                              group_max=groupmaxs[5:10],
                              group_labels=groupnames[5:10])

What is the difference when I split the group constraints into two instead
of 1?  Based on my tests these two are not the same; it seems that
splitting the group constraints into 2 is less restrictive(?) than if I
just have one group add.constraint()

3) There is a maximum position constraint--for example

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

Is there a reason that a minimum position constraint was not/cannot be
implemented?

Thanks & Regards,
-Ed
1 day later
#
On 01/26/2018 03:05 PM, Ed Herranz wrote:
You are correct that the initial population is generated via 
random_portfolios.

There are two ways to accomplish what you want, the first will work for 
only one 'special' seed portfolio, the second would work for any number 
of special seeds.

In the first method, when you call portfolio.spec, instead of just 
specifying the names of the assets, you also specify the weights using a 
named vector.  This will include your current seed portfolio as the 
second portfolio in the seed matrix sent to DEoptim as an initial 
population.

In the second method, you simply call random_portfolios by hand, 
specifying the number of portfolios to be slightly shorter than the 
number of portfolios that will be in each generation.  then add your 
seeds to this object, and specify your new matrix of weights including 
your seeds as the rp= parameter to optimize.portfolios.  You'll see that 
in many of our vignettes or seminar materials on PortfolioAnalytics we 
generate a random portfolio seed once, and then reuse it across many 
different scenarios.  You would be doing the same thing, only including 
your special seed portfolios in the initial population.
I discussed this with Ross Bennett, who added the group constraint code 
to PortfolioAnalytics, and we are of the opinion that the two 
formulations should be the same.  So any variation you are seeing may be 
random.  This could be verified by using the same seed population rp as 
described above.

Ross also noticed that both your groups contain asset 5, which may not 
be what you intended.
I think a minimum position box constraint will do what you want, but 
otherwise no, we'd need to look at the code and think about it some more 
as to why it was implemented the way that it was.

Regards,

Brian
#
Thank you Brian. I did not mean to put the same group in both calls; that
was a typo.

On Sun, Jan 28, 2018 at 6:47 AM Brian G. Peterson <brian at braverock.com>
wrote: