aml_test_model: Function to test the model and conditionally decide to update...

View source: R/aml_test_model.R

aml_test_modelR Documentation

Function to test the model and conditionally decide to update existing model for a single currency pair

Description

Function is designed to test the trading decision generated by the Deep learning regression model. It is doing so by simulating trading strategy outcome. The outcome of this function will be also used to define best trigger to join into the trading opportunity

[Experimental]

Usage

aml_test_model(
  symbol,
  num_bars,
  timeframe,
  path_model,
  path_data,
  path_sbxm = path_sbxm,
  path_sbxs = path_sbxs
)

Arguments

symbol

Character symbol of the asset for which to train the model

num_bars

Integer, Number of (rows) bars used to test the model

timeframe

Integer, Data timeframe e.g. 60 min. This will be equal to 1 bar

path_model

String, User path where the models are be stored

path_data

String, User path where the aggregated historical data is stored, if exists in rds format

path_sbxm

String, User path to the sandbox where file with strategy test results should be written (master terminal)

path_sbxs

String, User path to the sandbox where file with strategy test results should be written (slave terminal)

Details

Function is reading price data and corresponding indicator. Starting from the trained model function will test the trading strategy using simplified trading approach. Trading approach will entail using the last available indicator data, predict the price change for every row, trade will be simulating by holding the asset for 3, 5, 10 and 34 hours. Several trigger points will be evaluated selecting the most optimal trading trigger. Function is writing most optimal decision into *.csv file Such file will be used by the function aml_make_model.R to decide whether model must be updated...

Value

Function is writing file into Decision Support System folders

Author(s)

(C) 2020, 2021 Vladimir Zhbanko

Examples




library(dplyr)
library(magrittr)
library(readr)
library(h2o)
library(lazytrade)
library(lubridate)

path_model <- normalizePath(tempdir(),winslash = "/")
path_data <- normalizePath(tempdir(),winslash = "/")

ind = system.file("extdata", "AI_RSIADXUSDJPY60.csv",
                  package = "lazytrade") %>% read_csv(col_names = FALSE)

ind$X1 <- ymd_hms(ind$X1)

tick = system.file("extdata", "TickSize_AI_RSIADX.csv",
                  package = "lazytrade") %>% read_csv(col_names = FALSE)

write_csv(ind, file.path(path_data, "AI_RSIADXUSDJPY60.csv"), col_names = FALSE)

write_csv(tick, file.path(path_data, "TickSize_AI_RSIADX.csv"), col_names = FALSE)

# data transformation using the custom function for one symbol
aml_collect_data(indicator_dataset = ind,
                 symbol = 'USDJPY',
                 timeframe = 60,
                 path_data = path_data)


# start h2o engine
h2o.init(nthreads = 2)


# performing Deep Learning Regression using the custom function
aml_make_model(symbol = 'USDJPY',
               timeframe = 60,
               path_model = path_model,
               path_data = path_data,
               force_update=FALSE,
               num_nn_options = 3)

path_sbxm <- normalizePath(tempdir(),winslash = "/")
path_sbxs <- normalizePath(tempdir(),winslash = "/")

# score the latest data to generate predictions for one currency pair
aml_score_data(symbol = 'USDJPY',
               timeframe = 60,
               path_model = path_model,
               path_data = path_data,
               path_sbxm = path_sbxm,
               path_sbxs = path_sbxs)

# test the results of predictions
aml_test_model(symbol = 'USDJPY',
               num_bars = 600,
               timeframe = 60,
               path_model = path_model,
               path_data = path_data,
               path_sbxm = path_sbxm,
               path_sbxs = path_sbxs)

# stop h2o engine
h2o.shutdown(prompt = FALSE)

#set delay to insure h2o unit closes properly before the next test
Sys.sleep(5)






vzhomeexperiments/lazytrade documentation built on Feb. 20, 2024, 6:09 p.m.