0

I am having a question and can't think of a reasonable answer. I hope someone can help me! Many thanks in advance!

I am doing a portfolio optimization maximizing the Sharpe Ratio with a rolling window approach. Afterwards, I am writing the portfolio weights in a new Matrix.

With several datatsets, everything is working fine. Although with two other datasets, one issues arises: Two or three rows get only NA weights.

There should not be an issue with the data, because there are only so few NAs. Furthermore, there can’t be an issue with one row of returns for the portfolio estimation as every row of returns is used several times in a rolling window approach. Do you maybe know why one row in particular could be filled with Nas?

Many thanks in advance and best regards,

Sebastian

# Kenneth French Dates
DateKFStart <- '1963-07' #'1969-07'
DateKFEnd   <- '2004-11' #'2017-06'

R.FF3=R.FF3[paste(DateKFStart, DateKFEnd, sep='/'),]
R.FF5=R.FF5[paste(DateKFStart, DateKFEnd, sep='/'),]
R.KFInd10=R.KFInd10[paste(DateKFStart, DateKFEnd, sep='/'),]
R.KFInd49=R.KFInd49[paste(DateKFStart, DateKFEnd, sep='/'),]
R.KFSibo=R.KFSibo[paste(DateKFStart, DateKFEnd, sep='/'),]

#--------------------#
#### Optimization ####
#--------------------#

#------------------------------#
assets=R.KFInd10               # R.FF3
is.estimation.window='Rolling' # 'Expanding'
M=60                           # Estimation Window Length


# Construct initial portfolio

assetnames=colnames(assets)
returns=assets

w.sharpe=returns*0
r.sharpe.NC=w.sharpe[,1]
colnames(r.sharpe.NC)='r.sharpe.NC'


sharpe.portf <- portfolio.spec(assets = assetnames)

sharpe.portf <- add.constraint(sharpe.portf, type= 'full_investment')
sharpe.portf <- add.constraint(sharpe.portf, type= 'long_only')

sharpe.portf <- add.objective(sharpe.portf, type='risk',   name='StdDev')
sharpe.portf <- add.objective(sharpe.portf, type='return', name='mean'  )

sharpe.portf

  for (n in (M+1):nrow(returns))
  {
  max_sharpe_opt <- optimize.portfolio(R=returns[(n-M):(n-1),],portfolio=sharpe.portf, 
                                       optimize_method='ROI',maxSR=TRUE, message=TRUE,trace=TRUE)
  w.sharpe[n,]=max_sharpe_opt$weights
  }

r.sharpe.NC[,1]=rowSums(returns*w.sharpe)

As already said, I don't know one single explanation. The whole code works for several datasets. And for only 2 two datasets, two rows of weights are NA, the rest works fine. So there should not be an issue with the data?

4

1 回答 1

0

我遇到了同样的问题,我认为这是因为它有时找不到解决方案...尝试“随机”方法,这将花费更多时间,但您会正常得到一些东西...或尝试其他方法优化。

如果你发现了一些关于你的问题的东西,请给我你的解决方案。

max_sharpe_opt <- optimize.portfolio(R=returns[(n-M):(n-1),],portfolio=sharpe.portf, 
                                       optimize_method='random',maxSR=TRUE, message=TRUE)

或者

max_sharpe_opt <- optimize.portfolio(R=returns[(n-M):(n-1),],portfolio=sharpe.portf, 
                                       optimize_method='GenSA',maxSR=TRUE, message=TRUE)
于 2018-03-14T18:10:16.243 回答