make_featuremat: Generate a predictor xts matrix to use with a Machine...

Description Usage Arguments Details Value See Also

Description

This function assembles an xts matrix from a list of pre-calculated features. The xts matrix is made up of a properly lagged first column named y (the target to predict), and a number of additional columns specifying the feature vector.

Usage

1
2
make_featuremat(feature_list, symbol, Nlags = 1, featuresub = NA,
  verbose = FALSE)

Arguments

feature_list

A list containing multiple xts matrices, each corresponding to a feature. Each xts matrix may contain the feature for a universe of assets, but only the column containing the string specified by 'symbol' as a subset of the column name will be extracted (see symbol below). The FIRST feature in the list should be the target variable (y) if this is used to train a machine learning model via supervised learning.

symbol

The name of the symbol in the form of a character vector of length 1. This is used to extract the relevant column from each feature matrices in the feature_list. Note that a column will be extracted even if the symbol name has addition text prepended or appended. For example, if symbol = "SPY", a column named "xxx_SPY_mom4" will be extracted.

Nlags

The number of periods (days), either positive or negative, by which each specified feature will be lagged. The specified features is an internally built vector comprising target (if specified), followed by featuresub (if specified). If featuresub is not specified, then the entire feature_list is used. Nlags is padded with zeroes on the right if it doesn't specify the lag for all features. Default is 1, meaning that the target is lagged by 1 day.

featuresub

Specifies the names of features to subset from the feature_list if only a subset of the features should be used to build the feature matrix. Default is NA, which means all features in the feature_list will be used. Note that the name of the target variable column (y) should be explicitly specified as the FIRST item in this list if the resulting matrix is used by a machine learning model.

verbose

Logical. Prints diagnostics on console. Useful to ensure the data is set up as expected. Default is FALSE.

Details

It is assumed that multiple xts matrices have been computed a priori and stored in the feature_list, and each of these matrices hold the values of a given predictor. A predictor (feature) may or may not be derived from the targeted asset. For example, y may represent the 3 month momentum of price of a stock (possibly lagged), while interest rates may be a feature extracted from the feature_list.

Function make_features is normally called a priori to generate the list of features specified in feature_list.

In addition, the function can do a negative lag (lead) the predictor variable if desired.

Value

Returns an xts matrix with the following columns:

y:

Assuming a target The target variable appropriately named as y. This column is moved forward in time by Nlags periods to reflect that y is in the future. NA padding at the tail is done as appropriate so its obvious that the more recent vectors don't have y values and should therefore be predicted by a trained model.

predictor columns (kept in order):

The extracted predictor columns, kept in the order specified in prednames.

See Also

make_features


jeanmarcgp/xtsanalytics documentation built on May 19, 2019, 12:38 a.m.