# \donttest{
set.seed(123)
returns <- matrix(rnorm(200 * 20, mean = 0, sd = 0.02), ncol = 20)
# Initialize object
tv <- TVMVP$new()
tv$set_data(returns)
# Optimize weights and predict returns
result <- predict_portfolio(
tv,
horizon = 5,
m = 3,
min_return = 0.02,
max_SR = TRUE
)
# Print the portfolio performance summary
print(result)
# Access MVP weights
result$getWeights("MVP")
# Access Max Sharpe weights (if computed)
result$getWeights("max_SR")
# Or use R6 method interface
tv$determine_factors(max_m=5)
prediction <- tv$predict_portfolio(horizon = 1, min_return)
prediction
prediction$getWeights("MVPConstrained")
# }
Run the code above in your browser using DataLab