Last chance! 50% off unlimited learning
Sale ends in
Implements a trading strategy aimed at maintaining a fixed allocation to each of several funds, rebalancing when the effective allocations deviate too far from the targets.
targetall(tickers = NULL, intercepts = NULL, slopes = NULL, ...,
tickers.gains = NULL, target.alls = NULL, tol = 0.05,
rebalance.cost = 0, initial = 10000)
Character vector of ticker symbols that Yahoo! Finance recognizes, if you want to download data on the fly.
Numeric vector of values to add to daily gains for each ticker.
Numeric vector of values to multiply daily gains for each ticker by. Slopes are multiplied prior to adding intercepts.
Arguments to pass along with tickers
to
load_gains
.
Numeric matrix of gains, where each column has gains for a particular fund.
Numeric vector specifying target allocations to each fund. If unspecified, equal allocations are used (e.g. 1/3, 1/3, 1/3 if there are 3 funds).
Numeric value indicating how far the effective allocations can drift away from the targets before rebalancing.
Numeric value specifying total cost of each rebalancing trade.
Numeric value specifying what value to scale initial prices to.
List containing:
Numeric matrix named fund.balances
giving fund balances over
time.
Numeric value named rebalance.count
giving the number of
rebalancing trades executed.
Ryan, J.A. and Ulrich, J.M. (2017) quantmod: Quantitative Financial Modelling Framework. R package version 0.4-12, https://CRAN.R-project.org/package=quantmod.
# NOT RUN {
# Backtest equal-allocation UPRO/VBLTX/VWEHX strategy
port <- targetall(tickers = c("UPRO", "VBLTX", "VWEHX"))
plot(port$fund.balances[, "Portfolio"])
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab