Add a new weight model to the portfolioReturns S3 object

add_weight_model(portfolio_object, weight_model, weight_config, new_weights)

Arguments

portfolio_object

A portfolioReturns object

weight_model

Config/Model of the weight model

weight_config

Configuration of the weight model

new_weights

Data frame containing stock_id, date, and the new weights

Value

A portfolioReturns S3 object with the new weight model added

Examples

if (FALSE) {
# Assuming 'pf' is your portfolio_object already created
weight_function <- "ensemble"  # Example model function
weight_config <- list(ensemble_list=c("ols_1","xgb_1","xgb_2"), ensemble_weights=c(0.3,0.3,0.4))
new_weights <- data.frame(stock_id = 1:100, date = c(rep(Sys.Date(), 50), rep(Sys.Date() + 1, 50)), weights = runif(100))
# Add the new model and its weights to the portfolio
pf <- add_weight_model(pf, weight_function, weight_config, new_weights)
print(pf)
}