targetall: Backtest a Fixed-Allocation Trading Strategy

Description Usage Arguments Value Examples

View source: R/targetall.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
targetall(
  tickers = NULL,
  intercepts = NULL,
  slopes = NULL,
  ...,
  tickers.gains = NULL,
  target.alls = NULL,
  tol = 0.05,
  rebalance.cost = 0,
  initial = 10000
)

Arguments

tickers

Character vector specifying 2 ticker symbols that Yahoo! Finance recognizes, if you want to download data on the fly.

intercepts

Numeric vector of values to add to daily gains for each fund.

slopes

Numeric vector of values to multiply daily gains for each fund by. Slopes are multiplied prior to adding intercepts.

...

Arguments to pass along with tickers to load_gains.

tickers.gains

Data frame with one column of gains for each investment and a date variable named Date.

target.alls

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).

tol

Numeric value indicating how far the effective allocations can drift away from the targets before rebalancing.

rebalance.cost

Numeric value specifying total cost of each rebalancing trade.

initial

Numeric value specifying what value to scale initial prices to.

Value

List containing:

  1. Numeric matrix named fund.balances giving fund balances over time.

  2. Numeric value named rebalance.count giving the number of rebalancing trades executed.

Examples

1
2
3
4
5
6
## Not run: 
# Backtest equal-allocation UPRO/VBLTX/VWEHX strategy
port <- targetall(tickers = c("UPRO", "VBLTX", "VWEHX"))
plot(port$fund.balances[, "Portfolio"])

## End(Not run)

vandomed/stocks documentation built on July 22, 2020, 3:25 a.m.