RPubs will retire in June 2027. Your existing documents will stay accessible through December 31, 2031
and Connect Cloud is the recommended home for new publishing. Read the blog post

Recently Published

HTML
rcasimiro
Document
Coursera project
HOMEWORK CHAPTER 09
HTML
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 = "ROI") 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"))
HTML
LUSC B,T, M and Cold tumor
adeno B,T,M and Cold tumor
Publish Document
HTML