View source: R/compute_long_short_returns.R
| compute_long_short_returns | R Documentation |
Calculates long-short returns based on the returns of portfolios. The long-short return is computed as the difference between the returns of the "top" and "bottom" portfolios. The direction of the calculation can be adjusted based on whether the return from the "bottom" portfolio is subtracted from or added to the return from the "top" portfolio.
compute_long_short_returns(
data,
direction = "top_minus_bottom",
data_options = NULL
)
data |
A data frame containing portfolio returns. The data frame must
include columns for the portfolio identifier, date, and return
measurements (as specified in |
direction |
A character string specifying the direction of the
long-short return calculation. It can be either |
data_options |
A list of class |
A data frame with columns for date, return measurement types (from the "ret_measure" column), and the computed long-short returns. The data frame is arranged by date and pivoted to have return measurement types as columns with their corresponding long-short returns.
Other portfolio functions:
assign_portfolio(),
breakpoint_options(),
compute_breakpoints(),
compute_portfolio_returns(),
data_options(),
filter_options(),
filter_sorting_data(),
implement_portfolio_sort(),
portfolio_sort_options()
set.seed(42)
data <- data.frame(
permno = 1:100,
date = rep(
seq.Date(from = as.Date("2020-01-01"), by = "month", length.out = 100),
each = 10
),
mktcap_lag = runif(100, 100, 1000),
ret_excess = rnorm(100),
size = runif(100, 50, 150)
)
portfolio_returns <- compute_portfolio_returns(
data, "size", "univariate",
breakpoint_options_main = breakpoint_options(n_portfolios = 5)
)
compute_long_short_returns(portfolio_returns)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.