I am new to R and having a bit of trouble setting up functions. I am trying to run a backtest in a large number of assets or markets. All of this data is in CSV.
I have a dataframe that is basically a list of the markets [asset] and their characteristics [assetlist] that I want to open in my enviroment so that I can use to test. I will need to open them quite frequently since they are daily updated as a CSV file.
My main goal is to get the CSV files that are downloaded daily and convert them to a dataframe in R.
I tried setting up the function below, I do get the print out on my console but the markets [asset] don´t show up in my enviroment.
# this is the function I set up to upload the asset list with the markets and their features/characteristics and in the loop I go through each of their files.
trading.opencsv <- function(rd){
asset.directory <- paste(rd, "list.csv", sep="")
assetlist <<- read.csv(asset.directory, stringsAsFactors=FALSE)
print(assetlist$Market)
for (i in 1:nrow(assetlist)){
asset <- assetlist$Market[i]
x.dir <- paste(rd, asset, ".csv", sep="")
x <- read.csv(x.dir)
print(asset)
assign(asset, x)
}
}
#this is the directory I use to save the csv files and running the function.
rd <- "C:/Users/augus/Dropbox/Trading/R/Trading/Dados/"
trading.opencsv(rd)