目标函数

R 中级投资组合分析

Ross Bennett

Instructor

目标函数

目标函数用于计算目标值。在 PortfolioAnalytics 中,目标函数可以是任何有效的 R 函数。

  • 常见的组合风险度量

    • 标准差、预期短缺、在险价值、风险成分贡献、最大回撤、夏普比率
  • 常见的基准相对绩效度量

    • 信息比率、跟踪误差、超额收益、最大相对回撤
R 中级投资组合分析

自定义目标函数

将用户自定义函数用作目标函数

  • 参数命名:

    • R 表示资产收益

    • weights 表示投资权重

    • musigmam3m4 表示矩

  • 返回单一数值

R 中级投资组合分析
# Annualized sharpe ratio
sr_annualized <- function(R, weights, sigma, scale, rfr){

    # Geometric annualized return
    r <- Return.annualized(Return.portfolio(R, weights), scale = scale)
    # Annual excess return
    re <- r - rfr

    # Annualized portfolio standard deviation
    pasd <- sqrt(as.numeric(t(weights) %*% 
                 sigma %*% weights)) * sqrt(scale)

    return(re / pasd)
}
R 中级投资组合分析
data(edhec)
asset_returns <- edhec[,1:4]

# Setup spec and add constraints port_spec <- portfolio.spec(assets = colnames(asset_returns)) port_spec <- add.constraint(portfolio = port_spec, type = "full_investment") port_spec <- add.constraint(portfolio = port_spec, type = "long_only")
# Add custom objective function port_spec <- add.objective(portfolio = port_spec, type = "return", name = "sr_annualized", arguments = list(scale = 12, rfr = 0.02))
R 中级投资组合分析

让我们来练习!

R 中级投资组合分析

Preparing Video For Download...