-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0a05f4
commit 941ad04
Showing
104 changed files
with
197,034 additions
and
0 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+383 Bytes
RESEARCH/2019-02-21-Result-75-1.rds → RESEARCH/2019-03-24-Result-100-1.rds
Binary file not shown.
Binary file renamed
BIN
+383 Bytes
RESEARCH/2019-02-21-Result-75-15.rds → RESEARCH/2019-03-24-Result-100-15.rds
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
## FUNCTION create_labelled_data | ||
## PURPOSE: function gets price data in each column | ||
## it is splitting this data by periods and transposes the data. | ||
## additionally it is label the data based on the simple logic assigning it to 2 categories based on the difference | ||
## between beginning and end of the vector | ||
## finally it is stacking all data and joining everything into the table | ||
|
||
## TEST: | ||
# library(tidyverse) | ||
# library(lubridate) | ||
# pathT2 <- "C:/Program Files (x86)/FxPro - Terminal2/MQL4/Files/" | ||
# prices <- read_csv(file.path(pathT2, "AI_CP1.csv"), col_names = F) | ||
# prices$X1 <- ymd_hms(prices$X1) | ||
# write_rds(prices, "test_data/prices.rds") | ||
|
||
#' Create labelled data | ||
#' https://www.udemy.com/self-learning-trading-robot/?couponCode=LAZYTRADE7-10 | ||
#' | ||
#' @param x - data set containing a table where 1st column is a Time index and other columns containing financial asset price values | ||
#' @param n - number of rows we intend to split and transpose the data | ||
#' @param type - type of the label required. Can be either "classification" or "regression". "classification" will return either "BU" or "BE", | ||
#' "regression" will return the difference between first value and the last value in each row | ||
#' | ||
#' @return function returns transposed data. One column called 'LABEL' indicate achieved value of the label. | ||
#' Transposed values from every column are stacked one to each other | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
create_labelled_data <- function(x, n = 50, type = "regression"){ | ||
require(tidyverse) | ||
#source("C:/Users/fxtrams/Documents/000_TradingRepo/R_selflearning/_FUN/load_data.R") | ||
#x <- load_data(path_terminal = "C:/Program Files (x86)/FxPro - Terminal2/MQL4/Files/", trade_log_file = "AI_CP", time_period = 1, data_deepth = "50000") | ||
#x <- read_rds("_TEST_DATA/price_dataset.rds") | ||
#n <- 100 | ||
#type <- "classification" | ||
#type <- "regression" | ||
# | ||
nr <- nrow(x) | ||
dat11 <- x %>% | ||
# remove column 1 with data and time information | ||
select(-1) %>% | ||
# split dataset into several objects each containing n rows (it will be a list) | ||
split(rep(1:ceiling(nr/n), each=n, length.out=nr)) #list | ||
# remove last element of the list | ||
dat11[length(dat11)] <- NULL | ||
|
||
# operations within the list | ||
for (i in 1:length(dat11)) { | ||
#i <- 2 | ||
if(type == "classification"){ | ||
|
||
# classify by 2 classes 'BU', 'BE' | ||
if(!exists("dfr12")){ | ||
dfr12 <- dat11[i] %>% as.data.frame() %>% t() %>% as_tibble(.name_repair = "universal") %>% | ||
mutate(LABEL = ifelse(.[[1]]>.[[n]], "BU", "BE"))} else { | ||
dfr12 <- dat11[i] %>% as.data.frame() %>% t() %>% as_tibble(.name_repair = "universal") %>% | ||
mutate(LABEL = ifelse(.[[1]]>.[[n]], "BU", "BE")) %>% | ||
bind_rows(dfr12) | ||
} | ||
} else if(type == "regression"){ | ||
# add label with numeric difference {in pips} | ||
# i <- 1 | ||
if(!exists("dfr12")){ | ||
dfr12 <- dat11[i] %>% as.data.frame() %>% t() %>% as_tibble(.name_repair = "universal", verbose =F) %>% | ||
mutate(LABEL = 10000*(.[[1]]-.[[n]]))} else { | ||
dfr12 <- dat11[i] %>% as.data.frame() %>% t() %>% as_tibble(.name_repair = "universal", verbose =F) %>% | ||
mutate(LABEL = 10000*(.[[1]]-.[[n]])) %>% | ||
#oldest data will be on top of the dataframe! | ||
bind_rows(dfr12) | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
return(dfr12) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
## FUNCTION create_transposed_data | ||
## PURPOSE: function gets indicator data in each column | ||
## it is splitting this data by periods and transpose the data. | ||
## additionally it is label the data based on the simple logic assigning it to 2 categories based on the difference | ||
## between beginning and end of the vector | ||
## finally it is stacking all data and joining everything into the table | ||
|
||
## TEST: | ||
# library(tidyverse) | ||
# library(lubridate) | ||
# pathT2 <- "C:/Program Files (x86)/FxPro - Terminal2/MQL4/Files/" | ||
# macd <- read_csv(file.path(pathT2, "AI_Macd1.csv"), col_names = F) | ||
# macd$X1 <- ymd_hms(macd$X1) | ||
# write_rds(macd, "test_data/macd.rds") | ||
|
||
#' Create Transposed Data | ||
#' https://www.udemy.com/self-learning-trading-robot/?couponCode=LAZYTRADE7-10 | ||
#' | ||
#' @param x - data set containing a table where 1st column is a Time index and other columns containing financial asset indicator values | ||
#' @param n - number of rows we intend to split and transpose the data | ||
#' | ||
#' @return function returns transposed data. Transposed values from every column are stacked one to each other | ||
#' @export | ||
#' | ||
#' @examples | ||
#' | ||
create_transposed_data <- function(x, n = 50){ | ||
require(tidyverse) | ||
#source("C:/Users/fxtrams/Documents/000_TradingRepo/R_selflearning/_FUN/load_data.R") | ||
#n <- 100 | ||
#x <- load_data(path_terminal = "C:/Program Files (x86)/FxPro - Terminal2/MQL4/Files/", trade_log_file = "AI_Macd", time_period = 1, data_deepth = "50000") | ||
#x <- read_rds("_TEST_DATA/indicator_dataset.rds") | ||
nr <- nrow(x) | ||
dat11 <- x %>% select(-1) %>% split(rep(1:ceiling(nr/n), each=n, length.out=nr)) #list | ||
dat11[length(dat11)] <- NULL | ||
|
||
# operations within the list | ||
for (i in 1:length(dat11)) { | ||
#i <- 1 | ||
|
||
if(!exists("dfr12")){ | ||
dfr12 <- dat11[i] %>% as.data.frame() %>% t() %>% as_tibble(.name_repair = "universal", verbose =F) } else { | ||
dfr12 <- dat11[i] %>% as.data.frame() %>% t() %>% as_tibble(.name_repair = "universal", verbose =F) %>% bind_rows(dfr12) | ||
} | ||
|
||
} | ||
|
||
return(dfr12) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# import data function | ||
# (C) 2018 Vladimir Zhbanko | ||
# ------------------------- | ||
# Import Data to R | ||
# ------------------------- | ||
#' Load Data Function | ||
#' https://www.udemy.com/self-learning-trading-robot/?couponCode=LAZYTRADE7-10 | ||
#' | ||
#' Function imports file and change date column type. Function return the dataframe with trade data. | ||
#' -> update: data_deepth argument was added to optimize code and separate data needed to train and score the model | ||
#' | ||
#' @param path_terminal - path to the MT4 terminal, string | ||
#' @param trade_log_file - csv file name where the data is stored, without ".csv" | ||
#' @param time_period - data periodicity in minutes, can be 1, 15, 60 | ||
#' @param data_deepth - collected data deepth in rows. describe how many rows in original file to read | ||
#' | ||
#' @return - dataframe with asset data in columns where X1 column is in a POSIXct format | ||
#' @export | ||
#' | ||
#' @examples | ||
#' prices <- load_data(path_terminal = "C:/Program Files (x86)/FxPro - Terminal2/MQL4/Files/", | ||
#' trade_log_file = "AI_CP", | ||
#' time_period = 1, | ||
#' data_deepth = "14200") | ||
#' | ||
load_data <- function(path_terminal, trade_log_file, time_period = 1, data_deepth = 14200){ | ||
# path_terminal <- "C:/Program Files (x86)/FxPro - Terminal2/MQL4/Files/" | ||
# path_terminal <- file.path(getwd(), "test_data") | ||
# trade_log_file <- "AI_CP" | ||
# trade_log_file <- "AI_Macd" | ||
# time_period <- 1 | ||
# data_deepth <- "100000" | ||
require(tidyverse) | ||
require(lubridate) | ||
DFT1 <- try(read_csv(file = file.path(path_terminal, paste0(trade_log_file, time_period, "-", data_deepth, ".csv")), | ||
col_names = F), | ||
silent = TRUE) | ||
if(class(DFT1)[1] == "try-error") {stop("Error reading file. File with trades may not exist yet!", | ||
call. = FALSE)} | ||
if(!nrow(DFT1)==0){ | ||
# data frame preparation | ||
DFT1$X1 <- ymd_hms(DFT1$X1) | ||
if(trade_log_file == "AI_CP"){ | ||
## divide JPY pairs by 100 | ||
DFT2 <- DFT1[ , c(8,10,18,22,24,25,26)]/100 | ||
DFT3 <- DFT1[, -c(8,10,18,22,24,25,26)] %>% bind_cols(DFT2) %>% select(X1,X2,X3,X4,X5,X6,X7,X8, | ||
X9,X10,X11,X12,X13,X14,X15, | ||
X16,X17,X18,X19,X20,X21,X22, | ||
X23,X24,X25,X26,X27,X28,X29) | ||
return(DFT3) | ||
} | ||
|
||
return(DFT1) | ||
} else { | ||
stop("Data log is empty!", call. = FALSE) | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.