rebalance {PMwR} | R Documentation |
Rebalance Portfolio
Description
Compute the differences between two portfolios.
Usage
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 = "::")
Arguments
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 |
a numeric vector: the current prices; may be named |
notional |
a single number: 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 |
Details
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.
Value
An object of class rebalance
, which is a
data.frame
:
instrument |
character, or |
price |
prices |
current |
current portfolio, in units of instrument |
target |
new portfolio, in units of instrument |
difference |
the difference between |
Attached to the data.frame are several attributes:
notional |
a single number |
match.names |
logical |
multiplier |
a numeric vector with as many elements as the resulting data.frame has rows |
Author(s)
Enrico Schumann
References
Schumann, E. (2023) Portfolio Management with R.
https://enricoschumann.net/R/packages/PMwR/;
in particular, see
https://enricoschumann.net/R/packages/PMwR/manual/PMwR.html#rebalance
See Also
Examples
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 = "|")