toymkt: Toy Market Objects

Description Usage Arguments Details Value See Also Examples

Description

The function toymkt is used to create toy market objects.

Usage

1
2
3
toymkt(price = NULL, R = NULL, 
       benchmark.weight = NULL, initial.weight = NULL,
       buy.and.hold = TRUE)

Arguments

price

A zoo object containing the price or market captitalizations of the assets. Matrix and dataframes are also accepted.

R

Simple returns of the assets (same format as price). At least one of price and R must be supplied.

benchmark.weight

Portfolio weights of the benchmark (same format as price).

initial.weight

a numeric vector of initial benchmark weights. All entries of initial.weight must be non-negative. If initial.weight is not supplied and buy.and.hold is TRUE, the initial weights will be equal-weighted by default. If buy.and.hold is FALSE, initial.weight will not be used.

buy.and.hold

If TRUE, the benchmark is a buy-and-hold portfolio, and benchmark.weight will be ignored even if it is supplied. If FALSE, benchmark.weight must be supplied. The default value is TRUE.

Details

The function toymkt is used to create toy market objects from prices, returns and/or benchmark weights. The universe consists of (say) n assets. For each asset, we have a time series of returns. A benchmark portfolio is given by a fixed set of portfolio weights, and we want to study the performances of portfolios with respect to this benchmark. The portfolio weights of the benchmark are called the benchmark weights.

If buy.and.hold is TRUE, the toy market is an idealized market where the benchmark is a buy-and-hold portfolio. In this case all data in the output is derived from price and initial.weight, or R and initial.weight. If buy.and.hold is TRUE, initial.weight is not given but benchmark.weight is given, the first row of benchmark.weight will be used as the initial weight vector.

In the case buy.and.hold is FALSE the benchmark portfolio can be quite arbitrary. It is defined in terms of the beginning benchmark weights for each period and the returns for each asset.

Value

A list containing the following components:

growth

a zoo object containing the growth of $1 for each asset.

R

a zoo object containing the simple returns.

r

a zoo object containing the log returns.

benchmark.weight

a zoo object containing the benchmark weights of the assets. If buy.and.hold = TRUE, these are derived from the normalized market capitalizations.

n

number of assets in the market.

buy.and.hold

TRUE if the market is buy-and-hold.

See Also

print.toymkt, plot.toymkt

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# We use the EuStockMarkets dataset in the datasets package
data(EuStockMarkets)

# Example 1: Minimal specifications
# The market will be equal-weighted initially.
market <- toymkt(price = EuStockMarkets)
print(market)
plot(market)  # several plots


# Example 2: Generate a market from simulated log-normal returns.
n.periods <- 60
n.stocks <- 5
mu <- 0
sigma <- 0.1
R <- matrix(0, nrow = n.periods, ncol = n.stocks)
for (j in 1:n.stocks) {
  R[, j] <- exp(rnorm(n.periods, mean = mu, sd = sigma)) - 1
}
initial.weight <- c(0.1, 0.2, 0.3, 0.2, 0.2)  # specify initial weights
market <- toymkt(R = R, initial.weight = initial.weight,
                 buy.and.hold = TRUE)
plot(market)

Example output

Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Warning message:
In toymkt(price = EuStockMarkets) :
  Since initial.weight is not given, the benchmark is assumed to be equal-weighted initially.

There are 4 assets:
DAX SMI CAC FTSE 

The benchmark is buy-and-hold.

Other information (use $):
growth R r benchmark.weight n buy.and.hold 

RelValAnalysis documentation built on May 2, 2019, 3:09 a.m.