View source: R/stockDataDownload.R
financialDataResample | R Documentation |
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.
financialDataResample( X, N_sample = 50, T_sample = 2 * 252, num_datasets = 10, rm_stocks_with_na = TRUE )
X |
List of |
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 |
List of datasets resampled from X
.
Rui Zhou and Daniel P. Palomar
stockDataDownload
, portfolioBacktest
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.