required_packages <- c("mlr3verse", "data.table", "xts", "openxlsx", "glmnet", "readxl",
                       "PerformanceAnalytics", "outliers", "ggplot2")

# Function to check and install the necessary packages
install_and_load <- function(packages) {
  for (package in packages) {
    # Check if the package is installed
    if (!require(package, character.only = TRUE)) {
      # Install the package if it is not installed
      install.packages(package, dependencies = TRUE)
      # Load the package after installing
      library(package, character.only = TRUE)
    }
  }
}

install_and_load(required_packages)
setwd('..')
source(file.path('sandbox', 'sampledata.R'))
setwd('..')
source(file.path('sandbox', 'TSML.R'))
source(file.path('sandbox', 'MLutils.R'))

Preprocessing

setwd('..')
# Outlier detection and removal
source(file.path('sandbox', 'outliers.R'))

# Feature Selection
source(file.path('sandbox', 'featureselection.R'))

# Rescaling
source(file.path('sandbox', 'rescale.R'))

Evaluation

setwd('..')
# Constructing benchmarks
source(file.path('sandbox', 'benchmark.R'))
# Evaluation scores
source(file.path('sandbox', 'evaluation.R'))
testtask <- TSML$new(data = regr_data,
                     task = "regression",
                     ts_var = "DATE",
                     y = "WI.RET")
testtask$train_test_split(cutoff = 0.8)
testtask$train_predict("regr.rpart", method = "default")
testtask$prevailing_means()
testtask$mse()
testtask$mae()
testtask$rsq(benchmark = "zero")
testtask$evals
setwd('..')
source(file.path('sandbox', 'cvglmnet.R'))
source(file.path('sandbox', 'rpart.R'))
source(file.path('sandbox', 'ranger.R'))
source(file.path('sandbox', 'svm.R'))
source(file.path('sandbox', 'lda.R'))
source(file.path('sandbox', 'qda.R'))
source(file.path('sandbox', 'naiveBayes.R'))
source(file.path('sandbox', 'KNN.R'))
source(file.path('sandbox', 'nnet.R'))


JustinMShea/ExpectedReturns documentation built on June 14, 2025, 4:28 p.m.