stockDataResample: Generate random resamples from stock data

Description Usage Arguments Value Author(s) See Also Examples

View source: R/stockDataDownload.R

Description

This function resamples the stock data downloaded by stockDataDownload to obtain many datasets for a subsequent backtesting with portfolioBacktest. Given the original data, each resample is obtained by randomly choosing a subset of the stock names and randomly choosing a time period over the available long period.

Usage

1
2
3
4
5
6
7
stockDataResample(
  X,
  N_sample = 50,
  T_sample = 2 * 252,
  num_datasets = 10,
  rm_stocks_with_na = TRUE
)

Arguments

X

List of xts objects matching the structure returned by the function stockDataDownload.

N_sample

Number of stocks in each resample.

T_sample

Length of each resample (consecutive samples with a random initial time).

num_datasets

Number of resampled datasets (chosen randomly among the stock universe).

rm_stocks_with_na

Logical value indicating whether to remove stocks with missing values (ignoring leading missing values). Default is TRUE.

Value

List of datasets resampled from X.

Author(s)

Rui Zhou and Daniel P. Palomar

See Also

stockDataDownload, portfolioBacktest

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
library(portfolioBacktest)
data(SP500_symbols)

# download data from internet
SP500_data <- stockDataDownload(stock_symbols = SP500_symbols, 
                                from = "2009-01-01", to = "2009-12-31") 
                                
# generate 20 resamples from data, each with 10 stocks and one quarter continuous data
my_dataset_list <- stockDataResample(SP500_data, N = 10, T = 252/4, num_datasets = 20)

## End(Not run)

dppalomar/portfolioBacktest documentation built on Sept. 25, 2020, 2:44 p.m.