buildModel: Build quantmod model given specified fitting method

Description Usage Arguments Value Examples

Description

Construct and attach a fitted model of type method to quantmod object. This is a re-implementation of the R CRAN package buildModel with added flexibility in training.per

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# xgboost parameters
# https://xgboost.readthedocs.io/en/latest/parameter.html

# tuneGrid (production)

tg <- expand.grid(
 nrounds   =  c(500,200,100),
 eta       =  c(0.3,0.1,0.01,0.001),
 max_depth =  c(4,6,8,10),
 gamma     =  0,
 colsample_bytree = c(1,0.5),
 min_child_weight = 1,
 subsample        = c(1,0.5)
)

# tuneGrid (non-production)

tg <- expand.grid(
  nrounds   =  50,
  eta       =  c(0.1,0.01),
  max_depth =  c(4,7,10),
  gamma     =  0,
  colsample_bytree = 1,
  min_child_weight = 1,
  subsample        = 1
)

tc <- caret::trainControl(method = "cv", number = 5, summaryFunction = tradeModelSummary)

# of variable "specmodel", see
? econModel::specifyModel

# built model
specmodel <- buildModel(specmodel, method="train"
  , training.per=c("1970-12-31","2006-12-31")
  , method_train = "xgbTree", tuneGrid = tg, trControl = tc)

Usage

1
2
3
buildModel(x, method, training.per, ...)

buildModel.train(quantmod, training.data, ...)

Arguments

x

An object of class quantmod. Required. Created with specifyModel or an R formula

training.per

Default is none. Required. Default will train on all data provided in the paramter object "quantmod". Character vector representing dates in ISO 8601 format “CCYY-MM-DD” or “CCYY-MM-DD HH:MM:SS” of length 2. training.per can also be a list of training dates (THE LIST FEATURE NOT YET IMPLMENTED).

...

Dots. Additional arguments to method call.

method_train

Default is none. Defaults to "xgbTree". A character string naming the R CRAN package caret function train fitting method.

Value

An object of class quantmod with fitted model attached.

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
# of variable "specmodel", see
? econModel::specifyModel

# built model
specmodel <- buildModel(specmodel, method="train"
  , training.per=list(c("1970-12-31","1998-12-31"), c("2001-0101","2008-06-30"))

## End(Not run)

AndreMikulec/econModel documentation built on June 30, 2021, 9:48 a.m.