Learn R Programming

RelValAnalysis (version 1.0)

toymkt: Toy Market Objects

Description

The function toymkt is used to create toy market objects.

Usage

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

Arguments

Value

A list containing the following components:growtha zoo object containing the growth of $1 for each asset.Ra zoo object containing the simple returns.ra zoo object containing the log returns.benchmark.weighta zoo object containing the benchmark weights of the assets. If buy.and.hold = TRUE, these are derived from the normalized market capitalizations.nnumber of assets in the market.buy.and.holdTRUE if the market is buy-and-hold.

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.

See Also

print.toymkt, plot.toymkt

Examples

Run this code
# 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)

Run the code above in your browser using DataLab