View source: R/performance_analytics.R
| analyze_by_period | R Documentation |
Aggregates portfolio results by calendar period and computes standard statistics
for each period. Provide at least one of returns or values.
analyze_by_period(
dates,
returns = NULL,
values = NULL,
period = c("monthly", "quarterly", "yearly"),
na_rm = TRUE
)
dates |
Date vector aligned to |
returns |
Numeric simple returns aligned to |
values |
Numeric equity values aligned to |
period |
"monthly", "quarterly", or "yearly". |
na_rm |
Logical; remove NAs inside per-period aggregations. |
data.frame with period keys and columns: ret, start_value, end_value, n_obs.
data(sample_prices_weekly)
mom12 <- PortfolioTesteR::calc_momentum(sample_prices_weekly, lookback = 12)
sel5 <- PortfolioTesteR::filter_top_n(mom12, n = 5)
w_eq <- PortfolioTesteR::weight_equally(sel5)
pr <- PortfolioTesteR::portfolio_returns(w_eq, sample_prices_weekly)
val <- 1e5 * cumprod(1 + pr$portfolio_return)
out <- analyze_by_period(
dates = pr$Date,
returns = pr$portfolio_return,
values = val,
period = "monthly"
)
head(out)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.