R로 배우는 중급 포트폴리오 분석
Ross Bennett
Instructor
목표 함수는 목표 값을 계산합니다. PortfolioAnalytics에서는 목표 함수가 유효한 R 함수이면 됩니다.
일반적인 포트폴리오 위험 지표
일반적인 벤치마크 대비 성과 지표
사용자 정의 함수를 목표 함수로 사용
인자 이름:
자산 수익률은 R
포트폴리오 비중은 weights
순서통계량은 mu, sigma, m3, m4
단일 값을 반환
# 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)
}
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로 배우는 중급 포트폴리오 분석