View source: R/forecasting_functions.R
predict_portfolio | R Documentation |
This function estimates optimal portfolio weights using a time-varying covariance matrix derived from Local Principal Component Analysis (Local PCA). The procedure is available either as a stand-alone function or as a method in the 'TVMVP' R6 class. It computes the following portfolios:
Global Minimum Variance Portfolio (MVP)
Maximum Sharpe Ratio Portfolio (if max_SR = TRUE
)
Return-Constrained Minimum Variance Portfolio (if min_return
is provided)
predict_portfolio(
obj,
horizon = 1,
max_factors = 3,
kernel_func = epanechnikov_kernel,
min_return = NULL,
max_SR = NULL,
rf = NULL
)
obj |
An object of class TVMVP with the data. |
horizon |
Integer. Investment horizon over which expected return and risk are computed. Default is 1. |
max_factors |
Integer. The number of latent factors to consider in the Local PCA model. Default is 3. |
kernel_func |
Function. Kernel used for weighting observations in Local PCA. Default is |
min_return |
Optional numeric. If provided, the function computes a Return-Constrained Portfolio that targets this minimum return. |
max_SR |
Logical. If TRUE, the Maximum Sharpe Ratio Portfolio is also computed. Default is |
rf |
Numeric. Log risk-free rate. If |
Two usage styles:
#'
# R6 method interface tv <- TVMVP$new() tv$set_data(returns) tv$determine_factors(max_m=5) prediction <- tv$predict_portfolio(horizon = 1, min_return = 0.01, max_SR = TRUE) #' # Function interface prediction <- predict_portfolio(obj, horizon = 5, m = 2, min_return = 0.01, max_SR=TRUE)
The methods can then be used on prediction
to retrieve the weights.
The function estimates a time-varying covariance matrix using Local PCA:
\hat{\Sigma}_{r,t}=\hat{\Lambda}_t \hat{\Sigma}_F \hat{\Lambda}_t' + \tilde{\Sigma}_e
Where \hat{\Lambda}_t
is the factor loadings at time t, \hat{\Sigma}_F
is the factor covariance matrix, and \tilde{\Sigma}_e
is regularized covariance matrix of the idiosyncratic errors.
It forecasts asset-level expected returns using a simple ARIMA model selection procedure and uses these in portfolio optimization. Optimization strategies include:
Global minimum variance (analytical)
Maximum Sharpe ratio (if max_SR = TRUE
)
Minimum variance with expected return constraint (if min_return
is provided)
An object of class PortfolioPredictions
(an R6 object) with:
summary
A data frame of evaluation metrics (expected return, risk, Sharpe ratio) for all computed portfolios.
MVP
A list containing the weights, expected return, risk, and Sharpe ratio for the Global Minimum Variance Portfolio.
max_SR
(Optional) A list with metrics for the Maximum Sharpe Ratio Portfolio.
MVPConstrained
(Optional) A list with metrics for the Return-Constrained Portfolio.
The returned object includes:
$print()
: Nicely prints summary and portfolio access information.
$getWeights(method = c("MVP", "max_SR", "MVPConstrained"))
: Retrieves the weights for the selected portfolio.
Lillrank, E. (2025). A Time-Varying Factor Approach to Covariance Estimation
Fan, Q., Wu, R., Yang, Y., & Zhong, W. (2024). Time-varying minimum variance portfolio. Journal of Econometrics, 239(2), 105339.
set.seed(123)
returns <- matrix(rnorm(200 * 20, mean = 0, sd = 0.02), ncol = 20)
# Initialize object
tv <- TVMVP$new()
tv$set_data(returns)
# Optimize weights and predict returns
result <- predict_portfolio(
tv,
horizon = 5,
m = 3,
min_return = 0.02,
max_SR = TRUE
)
# Print the portfolio performance summary
print(result)
# Access MVP weights
result$getWeights("MVP")
# Access Max Sharpe weights (if computed)
result$getWeights("max_SR")
# Or use R6 method interface
tv$determine_factors(max_m=5)
prediction <- tv$predict_portfolio(horizon = 1, min_return)
prediction
prediction$getWeights("MVPConstrained")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.