From 93b858777654742efe35a0ed475f3cd447782fc1 Mon Sep 17 00:00:00 2001 From: vzhomeexperiments Date: Sat, 14 Nov 2020 20:29:10 +0100 Subject: [PATCH 1/7] solve warning --- R/mt_make_model.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/mt_make_model.R b/R/mt_make_model.R index b753512..4a37def 100644 --- a/R/mt_make_model.R +++ b/R/mt_make_model.R @@ -25,8 +25,10 @@ #' @param path_model String, Path where the models are be stored #' @param path_data String, Path where the aggregated historical data is stored, if exists in rds format #' @param activate_balance Boolean, option to choose if to balance market type classes or not, default TRUE -#' @param num_nn_options Integer, value from 1 to 20 or more. Used to change number of variants -#' of the random neural network structures +#' @param num_nn_options Integer, value from 3 to 24 or more. Used to change number of variants +#' of the random neural network structures. Value 3 will mean that only one +#' random structure will be used. To avoid warnings make sure to set this value +#' multiple of 3. Higher values will increase computation time. #' #' @return Function is writing file object with the model #' @export @@ -59,7 +61,7 @@ #' path_model = path_model, #' path_data = path_data, #' activate_balance = TRUE, -#' num_nn_options = 2) +#' num_nn_options = 3) #' #' # stop h2o engine #' h2o.shutdown(prompt = FALSE) From 92a1ef78582615814b04163da93eef3a2f178060 Mon Sep 17 00:00:00 2001 From: vzhomeexperiments Date: Mon, 16 Nov 2020 17:57:12 +0100 Subject: [PATCH 2/7] handle jpy pairs --- DESCRIPTION | 2 +- NEWS.md | 9 +++++++++ R/mt_evaluate.R | 33 ++++++++------------------------- man/mt_evaluate.Rd | 6 ++++-- man/mt_make_model.Rd | 8 +++++--- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7ff2e1c..385e628 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: lazytrade Type: Package Title: Learn Computer and Data Science using Algorithmic Trading -Version: 0.4.2 +Version: 0.4.3 Author: Vladimir Zhbanko Maintainer: Vladimir Zhbanko Description: Provide sets of functions and methods to learn and practice data science using idea of algorithmic trading. diff --git a/NEWS.md b/NEWS.md index 0cdcc54..ceef77b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,15 @@ * Add folder generation function +# lazytrade 0.4.3 + +# Version 0.4.3 + +## Changes + +* solving warnings by changing example in *mt_make_model* function +* division of macd data by 100 for all jpy pairs in *mt_evaluate* function + # lazytrade 0.4.2 # Version 0.4.2 diff --git a/R/mt_evaluate.R b/R/mt_evaluate.R index 80119c9..337e112 100644 --- a/R/mt_evaluate.R +++ b/R/mt_evaluate.R @@ -35,7 +35,7 @@ #' data(macd_ML60M) #' #' # start h2o engine (using all CPU's by default) -#' h2o.init() +#' h2o.init(nthreads = 2) #' #' # performing Deep Learning Regression using the custom function #' # this function stores model to the temp location @@ -43,7 +43,9 @@ #' num_bars = 64, #' timeframe = 60, #' path_model = path_model, -#' path_data = path_data) +#' path_data = path_data, +#' activate_balance = TRUE, +#' num_nn_options = 3) #' #' #' # Use sample data @@ -77,30 +79,11 @@ mt_evaluate <- function(x, path_model, num_cols, timeframe){ # load models m1 <- h2o::h2o.loadModel(m_path) - - if(class(m1)[1] == "H2ORegressionModel") { - # Convert to matrix - X_m <- lazytrade::to_m(x, num_cols) %>% as.data.frame() - colnames(X_m) <- c(paste("X",1:num_cols,sep="")) - # load the dataset to h2o - test <- h2o::as.h2o(x = X_m, destination_frame = "test") - - # retrieve the predicted market type value - e1 <- h2o::h2o.predict(m1, test) - - # round the number to achieve class - result <- round(e1) %>% as.vector() - - # manage negatives and/or bizzare numbers - if(result <= 0 || result > 6) {element <- -1} else {element <- result} - - # output result of prediction from the function - return(element) - + #normalize macd value if we are dealing with JPY pairs + if(stringr::str_detect(names(x), 'JPY')){ + x <- x/100 } - if(class(m1)[1] == "H2OMultinomialModel") { - # Convert to matrix X_m <- lazytrade::to_m(x, num_cols) %>% as.data.frame() colnames(X_m) <- c(paste("X",1:num_cols,sep="")) @@ -117,6 +100,6 @@ mt_evaluate <- function(x, path_model, num_cols, timeframe){ # output result of prediction from the function return(e1) - } + } diff --git a/man/mt_evaluate.Rd b/man/mt_evaluate.Rd index b8b256b..1256148 100644 --- a/man/mt_evaluate.Rd +++ b/man/mt_evaluate.Rd @@ -44,7 +44,7 @@ path_data <- normalizePath(tempdir(),winslash = "/") data(macd_ML60M) # start h2o engine (using all CPU's by default) -h2o.init() +h2o.init(nthreads = 2) # performing Deep Learning Regression using the custom function # this function stores model to the temp location @@ -52,7 +52,9 @@ mt_make_model(indicator_dataset = macd_ML60M, num_bars = 64, timeframe = 60, path_model = path_model, - path_data = path_data) + path_data = path_data, + activate_balance = TRUE, + num_nn_options = 3) # Use sample data diff --git a/man/mt_make_model.Rd b/man/mt_make_model.Rd index 0a3b6d2..ee4cc5d 100644 --- a/man/mt_make_model.Rd +++ b/man/mt_make_model.Rd @@ -27,8 +27,10 @@ mt_make_model( \item{activate_balance}{Boolean, option to choose if to balance market type classes or not, default TRUE} -\item{num_nn_options}{Integer, value from 1 to 20 or more. Used to change number of variants -of the random neural network structures} +\item{num_nn_options}{Integer, value from 3 to 24 or more. Used to change number of variants +of the random neural network structures. Value 3 will mean that only one +random structure will be used. To avoid warnings make sure to set this value +multiple of 3. Higher values will increase computation time.} } \value{ Function is writing file object with the model @@ -79,7 +81,7 @@ mt_make_model(indicator_dataset = macd_ML60M, path_model = path_model, path_data = path_data, activate_balance = TRUE, - num_nn_options = 2) + num_nn_options = 3) # stop h2o engine h2o.shutdown(prompt = FALSE) From 74a60b874e03ebc5077c53090322565178b73b03 Mon Sep 17 00:00:00 2001 From: vzhomeexperiments Date: Wed, 25 Nov 2020 17:24:43 +0100 Subject: [PATCH 3/7] update file name to update model --- NEWS.md | 3 ++- R/mt_make_model.R | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index ceef77b..c8378f7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,7 +11,8 @@ ## Changes * solving warnings by changing example in *mt_make_model* function -* division of macd data by 100 for all jpy pairs in *mt_evaluate* function +* conditional division of data by 100 in *mt_evaluate* function +* change function *mt_make_model* to read manually checked dataset # lazytrade 0.4.2 diff --git a/R/mt_make_model.R b/R/mt_make_model.R index 4a37def..9d70883 100644 --- a/R/mt_make_model.R +++ b/R/mt_make_model.R @@ -88,18 +88,18 @@ mt_make_model <- function(indicator_dataset, ## check if the latest data is available # construct path to the new data - path_file_name <- paste0("macd_ai_classified_", timeframe, "M.rds") + path_file_name <- paste0("macd_checked_", timeframe, "M.rds") path_newdata <- file.path(path_data, path_file_name) if(file.exists(path_newdata)){ # use new data... - macd_ML2 <- read_rds(path_newdata) %>% + macd_ML2 <- readr::read_rds(path_newdata) %>% # and add new data - bind_rows(indicator_dataset) %>% + dplyr::bind_rows(indicator_dataset) %>% # convert one column to factor - mutate_at("M_T", as.factor) + dplyr::mutate_at("M_T", as.factor) } else { # use input data and transform dataset column to factor - macd_ML2 <- indicator_dataset %>% mutate_at("M_T", as.factor) + macd_ML2 <- indicator_dataset %>% dplyr::mutate_at("M_T", as.factor) } # check if we don't have too much data From c695352653c5638b019ed0279487144f997985ba Mon Sep 17 00:00:00 2001 From: vzhomeexperiments Date: Sun, 6 Dec 2020 22:28:16 +0100 Subject: [PATCH 4/7] remove conditional division --- NEWS.md | 1 - R/aml_make_model.R | 4 ++-- R/mt_evaluate.R | 5 ----- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index c8378f7..f28502d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,7 +11,6 @@ ## Changes * solving warnings by changing example in *mt_make_model* function -* conditional division of data by 100 in *mt_evaluate* function * change function *mt_make_model* to read manually checked dataset # lazytrade 0.4.2 diff --git a/R/aml_make_model.R b/R/aml_make_model.R index cc0dd7a..b0e58fa 100644 --- a/R/aml_make_model.R +++ b/R/aml_make_model.R @@ -105,8 +105,8 @@ aml_make_model <- function(symbol, timeframe, path_model, path_data, model_status <- readr::read_csv(dec_file_path) %>% select(MaxPerf) %$% MaxPerf } else if(force_update == TRUE) { # delete the model and previous test results - remove(dec_file_path) - remove(m_path) + #try(remove(dec_file_path), silent = TRUE) + #try(remove(m_path),silent = TRUE) model_status <- -1 } else { model_status <- 0 } diff --git a/R/mt_evaluate.R b/R/mt_evaluate.R index 337e112..4127d95 100644 --- a/R/mt_evaluate.R +++ b/R/mt_evaluate.R @@ -79,11 +79,6 @@ mt_evaluate <- function(x, path_model, num_cols, timeframe){ # load models m1 <- h2o::h2o.loadModel(m_path) - #normalize macd value if we are dealing with JPY pairs - if(stringr::str_detect(names(x), 'JPY')){ - x <- x/100 - } - # Convert to matrix X_m <- lazytrade::to_m(x, num_cols) %>% as.data.frame() colnames(X_m) <- c(paste("X",1:num_cols,sep="")) From a511300950e9b3ac60ab3f2c7be7912984461261 Mon Sep 17 00:00:00 2001 From: vzhomeexperiments Date: Mon, 14 Dec 2020 19:00:06 +0100 Subject: [PATCH 5/7] update function documentation --- R/aml_test_model.R | 23 +++++++++-------------- man/aml_test_model.Rd | 14 +++++++------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/R/aml_test_model.R b/R/aml_test_model.R index 6e0b655..3d519b7 100644 --- a/R/aml_test_model.R +++ b/R/aml_test_model.R @@ -16,14 +16,14 @@ #' @author (C) 2020 Vladimir Zhbanko #' #' @param symbol Character symbol of the asset for which to train the model -#' @param num_bars Number of bars used to test the model -#' @param timeframe Data timeframe e.g. 60 min -#' @param path_model Path where the models are be stored -#' @param path_data Path where the aggregated historical data is stored, if exists in rds format -#' @param path_sbxm Path to the sandbox where file with strategy test results should be written (master terminal) -#' @param path_sbxs Path to the sandbox where file with strategy test results should be written (slave terminal) +#' @param num_bars Integer, Number of (rows) bars used to test the model +#' @param timeframe Integer, Data timeframe e.g. 60 min. This will be equal to 1 bar +#' @param path_model String, User path where the models are be stored +#' @param path_data String, User path where the aggregated historical data is stored, if exists in rds format +#' @param path_sbxm String, User path to the sandbox where file with strategy test results should be written (master terminal) +#' @param path_sbxs String, User path to the sandbox where file with strategy test results should be written (slave terminal) #' -#' @return Function is writing file into Decision Support System folder +#' @return Function is writing file into Decision Support System folders #' @export #' #' @examples @@ -116,10 +116,6 @@ aml_test_model <- function(symbol, num_bars, timeframe, path_model, path_data, # file name with the tick data path_tick <- file.path(path_data, "TickSize_AI_RSIADX.csv") - ## !!!!!! TDL - ## only select the latest 30% of data... or only last 2 month - - #dataset with date column X1 y <- readr::read_rds(full_path) %>% # remove empty rows @@ -139,6 +135,8 @@ aml_test_model <- function(symbol, num_bars, timeframe, path_model, path_data, #value z will contain tick value for this symbol X2 + #TDL add fail safe mechanism for 'z' + # generate a file name for model m_name <- paste0("DL_Regression", "-", symbol,"-", timeframe) m_path <- file.path(path_model, m_name) @@ -158,9 +156,6 @@ aml_test_model <- function(symbol, num_bars, timeframe, path_model, path_data, #NB <- 3 - - - # To DO: Add ATR multiplier to simulate TP/SL # add for loop for ATR Multiplier diff --git a/man/aml_test_model.Rd b/man/aml_test_model.Rd index 8592ec1..d0ee2e6 100644 --- a/man/aml_test_model.Rd +++ b/man/aml_test_model.Rd @@ -17,20 +17,20 @@ aml_test_model( \arguments{ \item{symbol}{Character symbol of the asset for which to train the model} -\item{num_bars}{Number of bars used to test the model} +\item{num_bars}{Integer, Number of (rows) bars used to test the model} -\item{timeframe}{Data timeframe e.g. 60 min} +\item{timeframe}{Integer, Data timeframe e.g. 60 min. This will be equal to 1 bar} -\item{path_model}{Path where the models are be stored} +\item{path_model}{String, User path where the models are be stored} -\item{path_data}{Path where the aggregated historical data is stored, if exists in rds format} +\item{path_data}{String, User path where the aggregated historical data is stored, if exists in rds format} -\item{path_sbxm}{Path to the sandbox where file with strategy test results should be written (master terminal)} +\item{path_sbxm}{String, User path to the sandbox where file with strategy test results should be written (master terminal)} -\item{path_sbxs}{Path to the sandbox where file with strategy test results should be written (slave terminal)} +\item{path_sbxs}{String, User path to the sandbox where file with strategy test results should be written (slave terminal)} } \value{ -Function is writing file into Decision Support System folder +Function is writing file into Decision Support System folders } \description{ Function is designed to test the trading decision generated by the Deep learning regression model. From c78406632ba31023359851150021f08d1d60b743 Mon Sep 17 00:00:00 2001 From: vzhomeexperiments Date: Wed, 16 Dec 2020 14:46:58 +0100 Subject: [PATCH 6/7] comment update --- NEWS.md | 3 +++ R/aml_make_model.R | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index f28502d..73838bc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,8 @@ ## Planned Changes * Add folder generation function +* Put option predict ahead as a parameter (now 34 bars) +* aml_make_model use parameter to split data with specific n of rows e.g. n_rows # lazytrade 0.4.3 @@ -12,6 +14,7 @@ * solving warnings by changing example in *mt_make_model* function * change function *mt_make_model* to read manually checked dataset +* update documentation # lazytrade 0.4.2 diff --git a/R/aml_make_model.R b/R/aml_make_model.R index b0e58fa..ed853e2 100644 --- a/R/aml_make_model.R +++ b/R/aml_make_model.R @@ -129,7 +129,7 @@ aml_make_model <- function(symbol, timeframe, path_model, path_data, # split data to train and test blocks - # note: model will be tested on the PAST data and trained on the NEWEST data + # note: model will be trained on the OLDEST data test_ind <- 1:round(0.3*(nrow(dat12))) #train indices 1:xxx dat21 <- dat12[test_ind, ] #dataset to test the model using 30% of data dat22 <- dat12[-test_ind, ] #dataset to train the model From abe7b3d2a8f2372a27901aa9d45bc7de3a29cecf Mon Sep 17 00:00:00 2001 From: vzhomeexperiments Date: Wed, 16 Dec 2020 16:30:34 +0100 Subject: [PATCH 7/7] update cran commnets --- cran-comments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cran-comments.md b/cran-comments.md index 7220908..ca294fb 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -2,7 +2,7 @@ * windows, R 4.0.3 * R-hub builder * R version 4.0.3 (2020-10-10) -* R Under development (unstable) (2020-10-11 r79327) +* R Under development (unstable) (2020-12-13 r79623) ## R CMD check results Status: OK