Recently Published
Mateo_2024_ICES_ASC
Results & Discussion
Storm Data Analysis
This project involves exploring the U.S. National Oceanic and Atmospheric
Administration's (NOAA) storm database.
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 = "CVaR")#added
#port_2_max_ret <- add.objective(portfolio=port_2_max_ret, type = "risk_adjusted_return", name = "SharpeRatio", risk_free_rate = risk_free_rate)
# 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")
# 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
initial_portfolio <- portfolio.spec(assets = colnames(returns_date_droped_dividened2))
# Add objectives - here we minimize risk (VAR)
initial_portfolio <- add.objective(portfolio = initial_portfolio, type = "risk", name = "VaR")
initial_portfolio <- add.objective(portfolio = initial_portfolio, type = "return", name = "mean")
initial_portfolio <- add.objective(portfolio = initial_portfolio, type = "risk-adjusted", name = "SortinoRatio")
# Add constraints - fully invested portfolio with no short sales
initial_portfolio <- add.constraint(portfolio = initial_portfolio, type = "long_only")
initial_portfolio <- add.constraint(portfolio = initial_portfolio, type = "full_investment")
initial_portfolio <- add.constraint(portfolio = initial_portfolio, type = "box", min = 0, max = 1)
# Optimize the portfolio to minimize risk
optimal_portfolio <- optimize.portfolio(R = returns_date_droped_dividened2,
portfolio = initial_portfolio, optimize_method = "DEoptim")
# View the optimal weights
optimal_weights <- extractWeights(optimal_portfolio)
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"))
mtcars - Project
mtcars - Project
Política de Privacidade
Política de Privacidade elaborada para app no Meta para Desenvolvedores