#Using Artemis
Repository link: [https://github.com/mandradebs/artemis]
To start using Artemis bot, you must install the following R packages. By default, when loading the Bot.R file, it will try to install the required packages but if an error occur, you must install the missing pakages manually. All tests were done on a Windows 10 laptop with a 6th Generation Intel i7 processor and 16 GB of RAM.
#Load Bot.R file. It contains the Bot class.
source("Bot.R")
After loading the Bot class, you can load the Artemis bot with the following command:
load("190830artemis.rda")
Now, we can communicate with Artemis as follows:
Artemis, What’s your name? When’s your birthday?
#Translating the questions to the Artemis language:
artemis$getName()
## [1] "artemis"
artemis$getBirthday()
## [1] "2019-04-13"
Artemis, show me the first 10 tickers in your study material. How many tickers are there?
head(artemis$studyMaterial$quotes,10)
## [1] "MMM" "ABT" "ABBV" "ABMD" "ACN" "ATVI" "ADBE" "AMD" "AAP" "AES"
length(artemis$studyMaterial$quotes)
## [1] 503
Artemis, How many records do you have in your knowledge? How many by pattern name and class?
length(artemis$knowledge)
## [1] 1004
#class 0 means negative pattern, 1 means positive pattern
table(Reduce(f = function(x,y) rbind(x,y),x = artemis$knowledge)[,1:2])
## class
## name 0 1
## CH 411 91
## DB 311 191
This copy of Artemis already contains 5 models for 2 patterns (cup with handle (CH) and double bottom (DB)). So you don’t need to start a new training process. Examples of Artemis training are:
Artemis, start your training ability for the CH pattern using the knn method and trying from 1 to 20 neighbors. Use 7 cores of my laptop. Also, start a training for DB but using a deep neural network with 3 hidden layers and 1024 neurons in each one.
set.seed(67)
artemis$train(patternName = "CH",method = "knn",nsocks = 7,
trControl = trainControl(classProbs = TRUE,summaryFunction = twoClassSum),
tuneGrid = expand.grid(k = seq(1,20)))
set.seed(80)
artemis$train(patternName = "DB",method = "deepNet",hidden=c(1024,1024,1024))
Full training was performed using the following sentences:
seed = 67
set.seed(seed)
artemis$train(patternName = "CH",method = "knn",nsocks = 7,
trControl = trainControl(classProbs = TRUE,summaryFunction = twoClassSum), tuneGrid = expand.grid(k = seq(1,20)))
set.seed(seed)
artemis$train(patternName = "CH",method = "deepNet",hidden=c(1024,1024,1024))
set.seed(seed)
artemis$train(patternName = "CH",method = "rf",nsocks = 7,tuneLength = 10,trControl = trainControl(classProbs = TRUE,summaryFunction = twoClassSum))
set.seed(seed)
artemis$train(patternName = "CH",method = "svmRadial",nsocks = 7,tuneLength = 10,trControl = trainControl(classProbs = TRUE,summaryFunction = twoClassSum))
set.seed(seed)
artemis$train(patternName = "CH",method = "glm",family=binomial(),nsocks = 7,trControl = trainControl(classProbs = TRUE,summaryFunction = twoClassSum))
seed = 80
set.seed(seed)
artemis$train(patternName = "DB",method = "knn",nsocks = 7,
trControl = trainControl(classProbs = TRUE,summaryFunction = twoClassSum), tuneGrid = expand.grid(k = seq(1,20)))
set.seed(seed)
artemis$train(patternName = "DB",method = "deepNet",hidden=c(1024,1024,1024))
set.seed(seed)
artemis$train(patternName = "DB",method = "rf",nsocks = 7,tuneLength = 10,trControl = trainControl(classProbs = TRUE,summaryFunction = twoClassSum))
set.seed(seed)
artemis$train(patternName = "DB",method = "svmRadial",nsocks = 7,tuneLength = 10,trControl = trainControl(classProbs = TRUE,summaryFunction = twoClassSum))
set.seed(seed)
artemis$train(patternName = "DB",method = "glm",family=binomial(),nsocks = 7,tuneLength = 10,trControl = trainControl(classProbs = TRUE,summaryFunction = twoClassSum))
Artemis, show me your training results.
artemis$trainSummary()
Pattern name | Method | Train Accuracy | Train Sensitivity | Train Specificity | Test Accuracy | Test Sensitivity | Test Specificity |
---|---|---|---|---|---|---|---|
DB | deepNet | 0.97 | 0.98 | 0.98 | 0.83 | 0.83 | 0.82 |
DB | svmRadial | 0.88 | 0.82 | 0.92 | 0.87 | 0.81 | 0.91 |
DB | knn | 0.84 | 0.70 | 0.93 | 0.83 | 0.68 | 0.92 |
DB | rf | 0.83 | 0.66 | 0.92 | 0.82 | 0.69 | 0.90 |
DB | glm | 0.64 | 0.55 | 0.70 | 0.63 | 0.63 | 0.63 |
CH | deepNet | 1.00 | 1.00 | 1.00 | 0.92 | 0.68 | 0.97 |
CH | svmRadial | 0.91 | 0.69 | 0.96 | 0.93 | 0.62 | 0.99 |
CH | rf | 0.91 | 0.66 | 0.97 | 0.90 | 0.53 | 0.98 |
CH | knn | 0.88 | 0.46 | 0.99 | 0.89 | 0.35 | 0.99 |
CH | glm | 0.77 | 0.55 | 0.83 | 0.84 | 0.50 | 0.90 |
Note that Neural networks (deepNet) and Support vector machines (svmRadial) were the best methods according to the accuracy.
Artemis, check if the AAL time series is a known pattern.
dta <- artemis$getData(ticker = "AAL")[,"Close"]
artemis$explore(tickers = "AAL",dta = list(dta),nlast = nrow(dta),minN = nrow(dta))#use all available records and consider just one candidate
Tickers | Method | Pattern | start | Probability |
---|---|---|---|---|
AAL | rf | DB | 2007-01-03 | 0.2640 |
AAL | svmRadial | DB | 2007-01-03 | 0.0708 |
AAL | deepNet | DB | 2007-01-03 | 0.0111 |
AAL | glm | DB | 2007-01-03 | 0.0000 |
AAL | knn | DB | 2007-01-03 | 0.0000 |
AAL | glm | CH | 2007-01-03 | 1.0000 |
AAL | deepNet | CH | 2007-01-03 | 1.0000 |
AAL | svmRadial | CH | 2007-01-03 | 0.9121 |
AAL | rf | CH | 2007-01-03 | 0.8440 |
AAL | knn | CH | 2007-01-03 | 0.8333 |
Note that DB pattern has a low probability meanwhile CH pattern has probability 1 using neural networks (deepNet) and logistic regression (glm) models.
Artemis, make a plot of the AAL ticker.
#one way
#artemis$plot(ticker = "AAL")
#another way, since dta dataframe contains the AAL close prices
artemis$plot(dta = dta)
Note that the plot seems to be a cup with handle pattern.
Artemis, explore 100 tickers, take the names from your study material (only the names, not the time series data). Consider just the last year (240 days) with candidates length of 5 months (100 days) or more and return up to 3 candidates for each ticker (the best 3 candidates).
#This was run on May 1, 2019
artemis$explore(tickers = head(artemis$studyMaterial$quotes,100),nlast = 240,minN = 100,ncandidates = 3)
Artemis, show me the best candidates (with probability 0.99 or more using Support vector machines and Neural networks methods).
dta <- artemis$exploration$candidates[which(artemis$exploration$candidates$Probability>0.99 & artemis$exploration$candidates$Method %in% c("svmRadial","deepNet")),]
dta
Tickers | Method | Pattern | start | Probability | |
---|---|---|---|---|---|
1 | BKNG | deepNet | DB | 2018-12-04 | 1.0000 |
2 | LNT | deepNet | DB | 2018-09-10 | 1.0000 |
3 | AWK | deepNet | DB | 2018-09-10 | 1.0000 |
4 | ADSK | deepNet | DB | 2018-06-14 | 1.0000 |
5 | AGN | deepNet | DB | 2018-11-19 | 1.0000 |
6 | AMD | deepNet | DB | 2018-06-14 | 1.0000 |
7 | AVGO | deepNet | DB | 2018-06-28 | 0.9999 |
8 | CDNS | deepNet | DB | 2018-09-10 | 0.9999 |
9 | AON | deepNet | DB | 2018-07-13 | 0.9998 |
10 | AFL | deepNet | DB | 2018-05-31 | 0.9998 |
11 | APD | deepNet | DB | 2018-05-31 | 0.9998 |
12 | A | deepNet | DB | 2018-05-31 | 0.9994 |
13 | AJG | deepNet | DB | 2018-07-27 | 0.9993 |
14 | AEE | deepNet | DB | 2018-09-10 | 0.9993 |
15 | BR | deepNet | DB | 2018-12-04 | 0.9986 |
16 | BDX | deepNet | DB | 2018-08-24 | 0.9970 |
17 | AAL | deepNet | DB | 2018-12-04 | 0.9960 |
18 | CAH | deepNet | DB | 2018-08-24 | 0.9946 |
19 | CNC | deepNet | DB | 2018-08-24 | 0.9940 |
20 | AEP | deepNet | DB | 2018-09-10 | 0.9926 |
21 | CAT | deepNet | DB | 2018-05-16 | 0.9908 |
22 | BHGE | deepNet | CH | 2018-10-22 | 1.0000 |
23 | ALGN | deepNet | CH | 2018-10-08 | 1.0000 |
24 | AOS | deepNet | CH | 2018-09-10 | 1.0000 |
25 | ALL | deepNet | CH | 2018-10-08 | 1.0000 |
26 | BWA | deepNet | CH | 2018-09-10 | 1.0000 |
27 | BBT | deepNet | CH | 2018-11-05 | 1.0000 |
28 | AMD | deepNet | CH | 2018-10-08 | 1.0000 |
29 | CAH | deepNet | CH | 2018-11-05 | 1.0000 |
30 | AMG | deepNet | CH | 2018-10-22 | 1.0000 |
31 | BLK | deepNet | CH | 2018-09-24 | 1.0000 |
32 | AAPL | deepNet | CH | 2018-10-22 | 1.0000 |
33 | CELG | deepNet | CH | 2018-08-24 | 1.0000 |
34 | AMP | deepNet | CH | 2018-10-08 | 1.0000 |
35 | ALB | deepNet | CH | 2018-11-19 | 1.0000 |
36 | ANSS | deepNet | CH | 2018-09-24 | 0.9999 |
37 | AIZ | deepNet | CH | 2018-10-08 | 0.9999 |
38 | BKNG | deepNet | CH | 2018-11-05 | 0.9999 |
39 | AMAT | deepNet | CH | 2018-08-24 | 0.9998 |
40 | BA | deepNet | CH | 2018-10-08 | 0.9998 |
41 | ABC | deepNet | CH | 2018-10-22 | 0.9997 |
42 | CE | deepNet | CH | 2018-09-24 | 0.9997 |
43 | BAX | deepNet | CH | 2018-09-24 | 0.9995 |
44 | CBS | deepNet | CH | 2018-11-05 | 0.9994 |
45 | BAC | deepNet | CH | 2018-09-10 | 0.9993 |
46 | AIG | deepNet | CH | 2018-09-24 | 0.9993 |
47 | AJG | deepNet | CH | 2018-11-05 | 0.9993 |
48 | CPRI | deepNet | CH | 2018-10-22 | 0.9993 |
49 | APA | deepNet | CH | 2018-11-05 | 0.9991 |
50 | CCL | deepNet | CH | 2018-11-05 | 0.9986 |
51 | AVY | deepNet | CH | 2018-09-24 | 0.9975 |
52 | MO | deepNet | CH | 2018-11-05 | 0.9973 |
53 | AMZN | deepNet | CH | 2018-09-10 | 0.9963 |
54 | AKAM | deepNet | CH | 2018-11-05 | 0.9946 |
55 | BBY | deepNet | CH | 2018-11-05 | 0.9941 |
Artemis, from the last table, plot the first candidate. It is supposed to be a DB pattern.
j <- 1
artemis$plot(dta = artemis$exploration$dta[[which(artemis$exploration$tickers == dta$Tickers[j])]][sprintf("%s/",dta$start[j]),])