Rebalance Portfolio
Compute the differences between two portfolios.
rebalance(current, target, price, notional = NULL, multiplier = 1, truncate = TRUE, match.names = TRUE, fraction = 1, drop.zero = FALSE, current.weights = FALSE, target.weights = TRUE) ## S3 method for class 'rebalance' print(x, ..., drop.zero = TRUE) replace_weight(weights, ..., prefix = TRUE, sep = "::")
current |
the current holdings: a (typically named) vector of position sizes;
can also be a |
target |
the target holdings: a (typically named) vector of weights;
can also be a |
price |
the current prices |
notional |
the value of the portfolio; if missing, replaced by
|
multiplier |
numeric vector, possibly named |
truncate |
truncate computed positions? Default is |
match.names |
logical |
fraction |
numeric |
x |
an object of class |
... |
|
drop.zero |
logical: should instruments with no difference
between Note the different defaults for computing and printing. |
current.weights |
logical. If |
target.weights |
logical. If |
weights |
a numeric vector with named components |
sep |
character |
prefix |
logical |
The function computes the necessary trades to move from the
current
portfolio to a target
portfolio.
replace_weight
is a helper function to split
baskets into their components. All arguments passed
via ...
should be named vectors. If names are
not syntactically valid (see
make.names
), quote them. The passed
vectors themselves should be passed as named
arguments: see examples.
An object of class rebalance
, which is a
data.frame
:
instrument |
character, or |
price |
prices |
current |
current portfolio |
target |
new portfolio |
difference |
the difference between current and target |
Attached to the data.frame are several attributes:
notional |
notional |
match.names |
logical |
multiplier |
multipliers |
Enrico Schumann
Schumann, E. (2018) Portfolio Management with R. http://enricoschumann.net/R/packages/PMwR/
r <- rebalance(current = c(a = 100, b = 20), target = c(a = 0.2, c = 0.3), price = c(a = 1, b = 2, c = 3)) as.journal(r) ## replace_weight: the passed vectors must be named; ## 'basket_3' is ignored because not ## component of weights is named ## 'basket_3' replace_weight(c(basket_1 = 0.3, basket_2 = 0.7), basket_1 = c(a = 0.1, b = 0.4, c = .5), basket_2 = c(x = 0.1, y = 0.4, z = .5), basket_3 = c(X = 0.5, Z = 0.5), sep = "|")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.