make_path: Create a financial path

Description Usage Arguments Value Examples

View source: R/financial-path.R

Description

Evaluates the model given in model by stepping through the given dates and applying transformations as follows: adjust for returns over the preceeding period, apply contributions or withdrawals (transactions), rebalance according to the given allocations.

Usage

1
make_path(model, nonneg = TRUE, verbose = FALSE)

Arguments

model

a named list containing transactions, allocations, portfolio, asset_names, and dates

nonneg

whether to disallow a negative balance. Setting this to FALSE (allowing a negative balance) can be useful for understanding shortfalls.

verbose

whether to output diagnostic information. Currently unused.

Value

a financial path, which is an xts timeseries containing balances for each holding and the total balance, as well as any transactions that occured and the investment return as a percent change.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library(tidyverse)
library(xts)
library(lubridate)
library(investmentsim)

# Time series of returns
data(simreturns)
head(simreturns)

# Historical assets
simstock_asset <- make_historical(simreturns$Stock.Returns)
simbond_asset <- make_historical(simreturns$Bond.Returns)
# Be sure dates simulated over are a subset of the dates of the assets.
dates <- seq(ymd("1940-01-01"), ymd("2010-01-01"), by="years")

# Portfolio with S&P 500 and 10-year T-bonds. Yearly transaction
# of $1000. Linear allocation.
asset_names <- c("Stocks", "Bonds")
port <- make_portfolio(asset_names,
                       c(simstock_asset,
                         simbond_asset),
                         c(2500, 2500))
alloc <- make_linear_allocation_path(asset_names,
                                    c(ymd("1990-01-01"),
                                      ymd("2015-01-01")),
                                    list(c(0.9, 0.1),
                                         c(0.4, 0.6)))
trans <- make_transactions_on_dates(rep(1000, length(dates)),
                                    dates)
model <- make_model(port, alloc, trans, dates)

# Evaluate the model
path <- make_path(model)
print(c(head(path), tail(path)))
plot(path[,1:3],
    col = c("red", "blue", "green"),
    main = "Investment Path")
addLegend("topleft",
          c(asset_names, "Total"),
          col = c("red", "blue", "green"),
          lty = 1, cex = 1,
          bty = "o")

ryanholbrook/investmentsim documentation built on Nov. 5, 2019, 5:10 a.m.