Create portfolioReturns S3 object
create_portfolios(data, label)
Data frame containing stock_id, date, and the specified label column
Column name of the label column
A portfolioReturns S3 object
data <- tibble::tibble(
stock_id = 1:100,
date = c(rep(Sys.Date(), 50), rep(Sys.Date() + 1, 50)),
return_label = runif(100)
)
# Create the returnPrediction object
pf <- create_portfolios(data, "return_label")
# Check the initial setup
print(pf)
#> $weight_models
#> list()
#>
#> $weights
#> # A tibble: 100 × 2
#> stock_id date
#> <int> <date>
#> 1 1 2024-05-22
#> 2 2 2024-05-22
#> 3 3 2024-05-22
#> 4 4 2024-05-22
#> 5 5 2024-05-22
#> 6 6 2024-05-22
#> 7 7 2024-05-22
#> 8 8 2024-05-22
#> 9 9 2024-05-22
#> 10 10 2024-05-22
#> # ℹ 90 more rows
#>
#> $actual_returns
#> # A tibble: 100 × 3
#> stock_id date actual_return
#> <int> <date> <dbl>
#> 1 1 2024-05-22 0.0808
#> 2 2 2024-05-22 0.834
#> 3 3 2024-05-22 0.601
#> 4 4 2024-05-22 0.157
#> 5 5 2024-05-22 0.00740
#> 6 6 2024-05-22 0.466
#> 7 7 2024-05-22 0.498
#> 8 8 2024-05-22 0.290
#> 9 9 2024-05-22 0.733
#> 10 10 2024-05-22 0.773
#> # ℹ 90 more rows
#>
#> $portfolio_returns
#> # A tibble: 2 × 1
#> date
#> <date>
#> 1 2024-05-22
#> 2 2024-05-23
#>
#> attr(,"class")
#> [1] "portfolioReturns"