financialDataResample: Generate random resamples from financial data

View source: R/stockDataDownload.R

financialDataResampleR Documentation

Generate random resamples from financial data

Description

This function resamples the financial data (e.g., downloaded with 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 financial instruments and randomly choosing a time period over the available long period.

Usage

financialDataResample(
  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

Desired number of financial instruments in each resample.

T_sample

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

num_datasets

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

rm_stocks_with_na

Logical value indicating whether to remove instruments with inner 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

## 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 <- financialDataResample(SP500_data, N = 10, T = 252/4, num_datasets = 20)

## End(Not run)


dppalomar/portfolioBacktest documentation built on April 27, 2022, 3:27 a.m.