Recently Published
HTML
Long Branch
Document
Contoh pengolahan data Sakernas Agustus 2023
NGOs in Araruama
Leaflet map with the current NGOs in the city of Araruama-Brazil
testeo topicos
es weno
dummying
test dummy
HTML
port_2_max_ret <- portfolio.spec(assets = colnames(returns_date_droped_dividened2))
# Add objectives - here we minimize risk (VAR)
port_2_max_ret <- add.objective(portfolio = port_2_max_ret, type = "risk", name = "StdDev")#added
port_2_max_ret <- add.objective(portfolio = port_2_max_ret, type = "return", name = "mean")
# Add constraints - fully invested portfolio with no short sales
port_2_max_ret <- add.constraint(portfolio = port_2_max_ret, type = "long_only")
port_2_max_ret <- add.constraint(portfolio = port_2_max_ret, type = "full_investment")
port_2_max_ret <- add.constraint(portfolio = port_2_max_ret, type = "box", min = 0, max = 1)
# Optimize the portfolio to minimize risk
optimal_portfolio_2 <- optimize.portfolio(R = returns_date_droped_dividened2,
portfolio = port_2_max_ret, optimize_method = "DEoptim")
# expected_return_optimal_portfolio_2 <- sum(optimal_portfolio_2$weights * colMeans(returns_date_droped_dividened2))
# expected_risk_optimal_portfolio_2 <- sqrt(t(weights) %*% cov(returns_df) %*% weights)
#
# annualized_return_optimal_portfolio_2 <- Return.annualized(expected_return_optimal_portfolio_2, scale = 252)
#
# # Step 2: Annualize the risk
# trading_days <- 252 # Number of trading days in a year
# annualized_risk_tan <- tanRisk * sqrt(trading_days)
optimal_weights <- extractWeights(optimal_portfolio_2)
asset_names <- names(optimal_weights)
weights_df <- data.frame(Asset = asset_names, Weight = optimal_weights)
plot_ly(data = weights_df, x = ~Asset, y = ~Weight, type = 'bar') %>%
layout(title = "Interactive Portfolio Weights",
xaxis = list(title = "Asset"),
yaxis = list(title = "Weight"))