1

当可以访问无风险资产时,我正在尝试使用R PortfolioAnalytics 包来计算有效边界的切线投资组合的权重。

下面使用 edhec 数据集显示了一个有趣且可复制的实验:

library(ROI)
library(PortfolioAnalytics)

data(edhec)
R <- edhec[, 1:5]
# change the column names for better legends in plotting
colnames(R) <- c("CA", "CTAG", "DS", "EM", "EQM")
funds <- colnames(R)

# Mean returns for each asset
(assetMeanReturns <- colMeans(R))

(rf <- min(assetMeanReturns) / 2.0)

# Initialise the portfolio specification using names of assets
portfolio <- portfolio.spec(assets=funds)
portfolio <- add.constraint(portfolio, type="full_investment")
portfolio <- add.constraint(portfolio=portfolio, type="box", min=-1, max=1)
portfolio <- add.objective(portfolio=portfolio, type="risk", name="StdDev")

iterations <-20
results <- matrix(nrow = iterations, ncol = 8)

for (i in 1:iterations) {
  efficientFrontier <- create.EfficientFrontier(R=R, portfolio=portfolio, type="mean-sd", n.portfolios=4+i)
  (means <- efficientFrontier$frontier[,c("mean")] * 100)
  (stddevs <- efficientFrontier$frontier[,c("StdDev")] * 100)
  (sharpeRatios <- (means - rf*100) / stddevs)
  (tangencyPortfolio <- efficientFrontier$frontier[sharpeRatios == max(sharpeRatios),])
  tangencyPortfolioDetails <- efficientFrontier$frontier[sharpeRatios == max(sharpeRatios),1:ncol(efficientFrontier$frontier)]
  results[i,] <- efficientFrontier$frontier[sharpeRatios == max(sharpeRatios),1:ncol(efficientFrontier$frontier)]  
}

results

此代码沿有效前沿计算投资组合,沿垂直预期收益轴的步距相等,然后根据每个有效前沿投资组合的均值和标准差选择使夏普比率最大化的投资组合。

让我感到困惑的是,没有更直接的方式来获得这个投资组合和

这种方法没有找到实际的切线投资组合。相反,它会将最接近于切线投资组合的有效边界上的投资组合标记为实际切线投资组合,给定在计算有效边界时选择的预定 E(回报)步长。

当您沿着有效投资组合增加 E(回报)步长时,切线投资组合权重的变化表明这种方法是多么不精确。

现在,我将在给定预期回报的情况下优化投资组合,并根据以下代码片段直接在给定无风险回报率的情况下最大化夏普比率:

# Define the sharpe ratio calculation function - that nests a portfolio optimisation problem.
frontierPortfolioSharpeRatio <- function(expectedReturn) {
  testPortfolio <- add.constraint(portfolio=portfolio, type="return", return_target=expectedReturn)
  optimisedTestPortfolio <- optimize.portfolio(R=R, portfolio=testPortfolio, optimize_method="ROI", trace=TRUE)
  return <- t(optimisedTestPortfolio$weights) %*% assetMeanReturns
  sharpeRatio <- (return - rf) /optimisedTestPortfolio$objective_measures$StdDev
  -sharpeRatio
}

# Get the sharpe ratio of portfolio that minimises variance given a required rate of return
# Initial guess of tangency portfolio required return is minimum variance portfolio expected return. Try others.
results <- optim(mean(assetMeanReturns), frontierPortfolioSharpeRatio, method="BFGS")

tangencyPortfolioRequiredReturn <- results$par
tangencyPortfolioDefinition <- add.constraint(portfolio=portfolio, type="return", return_target=tangencyPortfolioRequiredReturn)
tangencyPortfolio <- optimize.portfolio(R=R, portfolio=tangencyPortfolioDefinition, optimize_method="ROI", trace=TRUE)
(tangencyPortfolioReturn <- t(tangencyPortfolio$weights) %*% assetMeanReturns)
tangencyPortfolio$objective_measures
(sharpeRatio <- (tangencyPortfolioReturn - rf) /tangencyPortfolio$objective_measures$StdDev)
tangencyPortfolio$weights
plot(tangencyPortfolio, risk.col="StdDev", return.col="mean", main="Tangency Portfolio", chart.assets=TRUE)

任何有关如何使用 PortfolioAnalytics 更直接地执行此操作的见解将不胜感激。

杰夫小号

4

0 回答 0