mdd {stocks}R Documentation

Maximum Drawdown

Description

Calculates maximum drawdown from vector of closing prices, highs and lows, or gains.

Usage

mdd(prices = NULL, highs = NULL, lows = NULL, gains = NULL,
  indices = FALSE)

Arguments

prices

Numeric matrix with 1 column of prices for each investment (can be a vector if there is only one).

highs

Numeric vector of daily high prices.

lows

Numeric vector of daily low prices.

gains

Numeric matrix with 1 column of gains for each investment (can be a vector if there is only one).

indices

Logical value for whether to include indices for when the maximum drawdown occurred.

Value

Numeric value, vector, or matrix depending on indices and whether there is 1 fund or several.

Examples

## Not run: 
# Simulate minute-to-minute stock gains over a 2-year period
set.seed(123)
stock.gains <- rnorm(6.5 * 60 * 252 * 2, 0.000005, 0.001)

# Convert to stock prices assuming an initial price of $9.50 per share
stock.prices <- gains_prices(gains = stock.gains, initial = 9.50)

# Plot minute-to-minute stock prices (200k data point, may be slow)
plot(stock.prices)

# Maximum drawdown based on stock prices
mdd(prices = stock.prices)

# Same answer using gains rather than prices
mdd(gains = stock.gains)

## End(Not run)



[Package stocks version 1.1.4 Index]