Build a Rebalance Infrastrucure
construct_rebalance_infrastructure.Rd
Prepares a snoop_rolling
object before passing it through rebalance_portfolio
.
Usage
construct_rebalance_infrastructure(
.data,
.by = c("day", "week", "month", "year")
)
Arguments
- .data
A tabular (non-tidy)
tibble
.- .by
A
string
with the periodicity to compute the rebalance. One of:day
,week
,month
oryear
.
Examples
stocks <- tibble::tibble(
time = as.Date('2009-01-01') + 0:99,
X = rnorm(100, 0, 1),
Y = rnorm(100, 0, 2),
Z = rnorm(100, 0, 4)
)
roll <- construct_rolling_infrastructure(stocks, .initial = 50)
const <- construct_rebalance_infrastructure(roll)
const
#> # A tibble: 50 × 3
#> .date .analysis .assessment
#> <date> <list> <list>
#> 1 2009-02-20 <tibble [50 × 3]> <tibble [1 × 3]>
#> 2 2009-02-21 <tibble [50 × 3]> <tibble [1 × 3]>
#> 3 2009-02-22 <tibble [50 × 3]> <tibble [1 × 3]>
#> 4 2009-02-23 <tibble [50 × 3]> <tibble [1 × 3]>
#> 5 2009-02-24 <tibble [50 × 3]> <tibble [1 × 3]>
#> 6 2009-02-25 <tibble [50 × 3]> <tibble [1 × 3]>
#> 7 2009-02-26 <tibble [50 × 3]> <tibble [1 × 3]>
#> 8 2009-02-27 <tibble [50 × 3]> <tibble [1 × 3]>
#> 9 2009-02-28 <tibble [50 × 3]> <tibble [1 × 3]>
#> 10 2009-03-01 <tibble [50 × 3]> <tibble [1 × 3]>
#> # … with 40 more rows
# Contains information under the hood:
class(const)
#> [1] "snoop_rebalance" "tbl_df" "tbl" "data.frame"