From 56e77f0c7d7806a0cb7149b1b69f6040a132a29c Mon Sep 17 00:00:00 2001 From: vzhomeexperiments Date: Wed, 31 Oct 2018 21:19:51 +0100 Subject: [PATCH] added test data for the function --- _RL/TradeTriggerRL.R | 9 +++++---- _RL/generate_RL_policy.R | 10 ++++++++-- _RL/record_policy.R | 7 +++++-- _TEST_DATA/TradeStatePolicy.rds | Bin 0 -> 245 bytes 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 _TEST_DATA/TradeStatePolicy.rds diff --git a/_RL/TradeTriggerRL.R b/_RL/TradeTriggerRL.R index 26c57ec..4114045 100644 --- a/_RL/TradeTriggerRL.R +++ b/_RL/TradeTriggerRL.R @@ -11,7 +11,7 @@ # packages used *** make sure to install these packages library(tidyverse) #install.packages("tidyverse") library(lubridate) #install.packages("lubridate") -library(ReinforcementLearning) #devtools::install_github("nproellochs/ReinforcementLearning") +library(ReinforcementLearning) #install.packages("ReinforcementLearning") library(magrittr) # ----------- Main Steps ----------------- @@ -76,7 +76,8 @@ for (i in 1:length(vector_systems)) { # tryCatch() function will not abort the entire for loop in case of the error in one iteration tryCatch({ # execute this code below for debugging: - # i <- 5 + # i <- 7 #policy off + # i <- 2 #policy on # extract current magic number id trading_system <- vector_systems[i] @@ -102,8 +103,8 @@ for (i in 1:length(vector_systems)) { # NOTE: more research is required to find best parameters TDL TDL TDL #control <- list(alpha = 0.5, gamma = 0.5, epsilon = 0.5) #control <- list(alpha = 0.9, gamma = 0.9, epsilon = 0.9) - control <- list(alpha = 0.1, gamma = 0.2, epsilon = 0.5) - #control <- list(alpha = 0.3, gamma = 0.6, epsilon = 0.1) + #control <- list(alpha = 0.7, gamma = 0.5, epsilon = 0.9) + control <- list(alpha = 0.3, gamma = 0.6, epsilon = 0.1) # perform reinforcement learning and return policy policy_tr_systDF <- generate_RL_policy(trading_systemDF, states = states,actions = actions, diff --git a/_RL/generate_RL_policy.R b/_RL/generate_RL_policy.R index fa2256d..cf51bea 100644 --- a/_RL/generate_RL_policy.R +++ b/_RL/generate_RL_policy.R @@ -17,6 +17,7 @@ generate_RL_policy <- function(x, states, actions, control){ require(tidyverse) require(ReinforcementLearning) + require(magrittr) # uncomment to debug code inside the function # x <- read_rds("_TEST_DATA/data_trades.rds") # x <- trading_systemDF @@ -63,15 +64,20 @@ generate_RL_policy <- function(x, states, actions, control){ s_new = "NextState", control = control, iter = 1, model = model) #model$Q #print(i) + } + + #plot(model) + # extract custom policy from the obtained dataset df_Q <- model$Q %>% as.data.frame() %>% # create column with market periods mutate(TradeState = row.names(.)) %>% # interpret policy as defined logic, value at ON must be >= 0! mutate(Policy = ifelse(ON <= 0, "OFF", ifelse(ON > OFF, "ON", ifelse(OFF > ON, "OFF", NA)))) %>% - select(TradeState, Policy) - + select(TradeState, Policy) + # record this object for the function debugging + # write_rds(df_Q, "_TEST_DATA/TradeStatePolicy.rds") #plot(model) return(df_Q) diff --git a/_RL/record_policy.R b/_RL/record_policy.R index 2bb5215..ba2bc17 100644 --- a/_RL/record_policy.R +++ b/_RL/record_policy.R @@ -10,13 +10,16 @@ #' @param last_result - character vector of the last result of the trade #' #' @return nothing is returned -#' @export function creates csv file +#' @export - function creates csv file #' @example record_policy(x = policy_tr_systDF, trading_system = trading_system, path_sandbox = path_T4) #' record_policy <- function(x, last_result, trading_system, path_sandbox){ + require(tidyverse) + require(magrittr) # debugging - # trading_system <- 8118105 + # trading_system <- 8118101 # last_result <- "tradeloss" + # x <- read_rds("_TEST_DATA/TradeStatePolicy.rds") # x <- policy_tr_systDF # path_sandbox <- "C:/Program Files (x86)/FxPro - Terminal3/MQL4/Files/" # derive which terminal should be enabled (using path to sandbox) and using variable 'addition' diff --git a/_TEST_DATA/TradeStatePolicy.rds b/_TEST_DATA/TradeStatePolicy.rds new file mode 100644 index 0000000000000000000000000000000000000000..0713510146924df91dccef6e991fdf97622e26a7 GIT binary patch literal 245 zcma#xVqjokVqj)vWMELa!w-91c(lpAXiFaNupj_QDSZ?nsUyf{BpfKpg2ei sFAy^|0Ez$q|Nlc%$O==0>=LdJkduQ;5=&B{*0TlV=VT^V0?qgb0CKY-(*OVf literal 0 HcmV?d00001