目標函式

R 中級投資組合分析

Ross Bennett

Instructor

目標函式

目標函式會計算目標值。在 PortfolioAnalytics 中,目標函式可以是任何有效的 R 函式。

  • 常見的投資組合風險衡量

    • 標準差、期望短缺(ES)、在險價值(VaR)、風險成分貢獻、最大回落、Sharpe 比率
  • 常見的相對基準績效衡量

    • 資訊比率、追蹤誤差、超額報酬、最大相對回落
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...