Intermediate Portfolio Analysis in R
Ross Bennett
Instructor
General portfolio optimization problem workflow in PortfolioAnalytics
:
Portfolio specification
Add constraints and objectives
Run optimization
Analyze optimization results
portfolio.spec(assets = NULL, ...)
# Character vector of assets
portfolio.spec(assets = c("SP00", "DJIA", "Nasdaq", "FTSE100", "DAX", "CAC40"))
# Named vector of assets with initial weights
initial_weights <- c("SP500" = 0.5, "FTSE100" = 0.3, "NIKKEI" = 0.2)
portfolio.spec(assets = initial_weights)
# Scalar of number of assets
portfolio.spec(assets = 4)
add.constraint(portfolio,
type = c("weight_sum", "box", "full_investment",...),
...)
# Initialize portfolio specification
p <- portfolio.spec(assets = 4)
# Add full investment constraint
p <- add.constraint(portfolio = p, type = "weight_sum",
min_sum = 1, max_sum = 1)
# Add box constraint
p <- add.constraint(portfolio = p, type = "box",
min = 0.2, max = 0.6)
add.objective(portfolio,
type = c("return", "risk", ...),
name,
arguments = NULL,
... )
# Initialize portfolio specification
p <- portfolio.spec(assets = 4)
# Add mean return objective
p <- add.objective(portfolio = p, type = "return",name = "mean")
# Add expected shortfall risk objective
p <- add.objective(portfolio = p, type = "risk", name = "ES",
arguments = list(p= 0.9, method = "gaussian")
Intermediate Portfolio Analysis in R