Title: | Rolling Optimizations |
---|---|
Description: | Analytical computation of rolling optimizations for time-series data. |
Authors: | Jason Foster |
Maintainer: | Jason Foster <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0 |
Built: | 2024-11-17 03:24:57 UTC |
Source: | https://github.com/jasonjfoster/rolloptim |
Analytical computation of rolling optimizations for time-series data.
rolloptim
is a package that provides analytical computation of rolling optimization for time-series data.
Jason Foster
Markowitz, H.M. (1952). "Portfolio Selection." The Journal of Finance, 7(1), 77–91.
Tam, A. (2021). "Lagrangians and Portfolio Optimization." https://www.adrian.idv.hk/2021-06-22-kkt/.
A function for computing rolling optimizations to maximize mean.
roll_max_mean(mu, total = 1, lower = 0, upper = 1)
roll_max_mean(mu, total = 1, lower = 0, upper = 1)
mu |
matrix. Rows are means and columns are variables. |
total |
numeric. Sum of the weights. |
lower |
numeric. Lower bound of the weights. |
upper |
numeric. Upper bound of the weights. |
An object of the same class and dimension as mu
with the rolling
optimizations to maximize mean.
if (requireNamespace("roll", quietly = TRUE)) { n_vars <- 3 n_obs <- 15 x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars) mu <- roll::roll_mean(x, 5) # rolling optimizations to maximize mean roll_max_mean(mu) }
if (requireNamespace("roll", quietly = TRUE)) { n_vars <- 3 n_obs <- 15 x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars) mu <- roll::roll_mean(x, 5) # rolling optimizations to maximize mean roll_max_mean(mu) }
A function for computing rolling optimizations to maximize utility.
roll_max_utility(mu, sigma, lambda = 1, total = 1, lower = 0, upper = 1)
roll_max_utility(mu, sigma, lambda = 1, total = 1, lower = 0, upper = 1)
mu |
matrix. Rows are means and columns are variables. |
sigma |
cube. Slices are covariance matrices. |
lambda |
numeric. Risk aversion parameter. |
total |
numeric. Sum of the weights. |
lower |
numeric. Lower bound of the weights. |
upper |
numeric. Upper bound of the weights. |
An object of the same class and dimension as mu
with the rolling
optimizations to maximize utility.
if (requireNamespace("roll", quietly = TRUE)) { n_vars <- 3 n_obs <- 15 x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars) mu <- roll::roll_mean(x, 5) sigma <- roll::roll_cov(x, width = 5) # rolling optimizations to maximize utility roll_max_utility(mu, sigma, lambda = 1) }
if (requireNamespace("roll", quietly = TRUE)) { n_vars <- 3 n_obs <- 15 x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars) mu <- roll::roll_mean(x, 5) sigma <- roll::roll_cov(x, width = 5) # rolling optimizations to maximize utility roll_max_utility(mu, sigma, lambda = 1) }
A function for computing rolling optimizations to minimize residual sum of squares.
roll_min_rss(xx, xy, total = 1, lower = 0, upper = 1)
roll_min_rss(xx, xy, total = 1, lower = 0, upper = 1)
xx |
cube. Slices are crossproducts of |
xy |
cube. Slices are crossproducts of |
total |
numeric. Sum of the weights. |
lower |
numeric. Lower bound of the weights. |
upper |
numeric. Upper bound of the weights. |
An object of the same class and dimension as x
with the rolling
optimizations to minimize residual sum of squares.
if (requireNamespace("roll", quietly = TRUE)) { n_vars <- 3 n_obs <- 15 x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars) y <- rnorm(n_obs) xx <- roll::roll_crossprod(x, x, 5) xy <- roll::roll_crossprod(x, y, 5) # rolling optimizations to minimize residual sum of squares roll_min_rss(xx, xy) }
if (requireNamespace("roll", quietly = TRUE)) { n_vars <- 3 n_obs <- 15 x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars) y <- rnorm(n_obs) xx <- roll::roll_crossprod(x, x, 5) xy <- roll::roll_crossprod(x, y, 5) # rolling optimizations to minimize residual sum of squares roll_min_rss(xx, xy) }
A function for computing rolling optimizations to minimize variance.
roll_min_var(sigma, total = 1, lower = 0, upper = 1)
roll_min_var(sigma, total = 1, lower = 0, upper = 1)
sigma |
cube. Slices are covariance matrices. |
total |
numeric. Sum of the weights. |
lower |
numeric. Lower bound of the weights. |
upper |
numeric. Upper bound of the weights. |
An object of the same class and dimension as mu
with the rolling
optimizations to minimize variance.
if (requireNamespace("roll", quietly = TRUE)) { n_vars <- 3 n_obs <- 15 x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars) sigma <- roll::roll_cov(x, width = 5) # rolling optimizations to minimize variance roll_min_var(sigma) }
if (requireNamespace("roll", quietly = TRUE)) { n_vars <- 3 n_obs <- 15 x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars) sigma <- roll::roll_cov(x, width = 5) # rolling optimizations to minimize variance roll_min_var(sigma) }