OVERVIEW

Fears of the coronavirus crashed the stock market back in February, precisely beginning on February 24, 2020. The pandemic sent a shockwave to the global market and it still continuously wreaked havoc to humanity. The fears spread quickly and globally, e.g. over 70% of the world population was under lockdown at some point in March. Recently in May, the US unemployment rate has climbed to historical high since the Great Depression, and the whole country is still not ready for reopen (as of this moment the report is generated on 2020-05-13 18:42:36). Nevertheless, the US stock market has remarkably bounced back since late March, early April and continuously rising in May. The inspiration of this final project is come from the decoupling of the stock market and reality. Can we predict and visualize any upward or downward trend of any stock during this significant crisis in our time?

(I) SET UP

We first load a list of packages in the session using pacman::p_load. We need to register for an API from https://www.alphavantage.co/ in order to get real time data using the quantmod package. It’s free to use this service as long as there’s not more than 500 calls a day.

# load packages
packages <- c('broom', 'caret', 'doParallel', 'e1071', 'foreach', 'glue', 'gridExtra', 'Hmisc', 'htmlwidgets', 'InformationValue', 'kableExtra', 'parallel', 'plotly', 'quantmod', 'sqldf', 'tictoc', 'tidyverse', 'TTR', 'wrapr')
pacman::p_load(char = packages)

# set environment
readRenviron("~/I/config/.env")

# set project home directory
PROJECT_HOME_DIRECTORY <- Sys.getenv("PROJECT_HOME_DIRECTORY")
setwd(PROJECT_HOME_DIRECTORY)

# get real time data if necessary
REAL_TIME = TRUE
ALPHA_VANTAGE_API <- Sys.getenv("ALPHA_VANTAGE_API")

(II) GET DATA

For illustrative purpose, we pick only one stock to look at in this final project (but the script is built to handle multiple stocks at the same time). We decide to choose a very popular stock to look at, i.e. Apple Inc (AAPL). When downloading historical data for multiple stocks, it’s wise to use multicores on one’s machine and create a parallel processing to speed up the data retrieval processing.

# stock symbol
stock <- c("AAPL")

# detect, use multicores
numCores <- parallel::detectCores()

# create a simple cluster on the local machine using all available threads
cl <- parallel::makeCluster(detectCores(), methods = FALSE)

# register our cluster
doParallel::registerDoParallel(cl)

# loop through a list of stock tickers - super fast! 5x faster than the traditional for-loop approach!!
symbols <- foreach::foreach(i = 1:length(stock), .errorhandling = 'remove') %dopar% { quantmod::getSymbols(stock[i]) } %>% unlist  # change .errorhandling = 'pass' to see error

# return a single list of xts objects from the valid symbols
if(REAL_TIME){
        
        xtsList <- vector(mode = "list", length = length(symbols))
        
        for(i in 1:length(symbols)){
                
                xtsList[[i]] <- quantmod::getSymbols(
                        
                        symbols[i], 
                        env = NULL,  # set env = NULL and that is equivalent to auto.assign = FALSE
                        src = "av",
                        periodicity = "daily", 
                        output.size = "full", 
                        adjusted = TRUE,
                        api.key = ALPHA_VANTAGE_API
                        
                )
                
                Sys.sleep(12)
                
        }
        
} else {
        
        xtsList <- foreach::foreach(i = 1:length(symbols)) %dopar% { quantmod::getSymbols(symbols[i], env = NULL, adjusted = TRUE) }  # set env = NULL and that is equivalent to auto.assign = FALSE        
        
}

# set names for xtsList
names(xtsList) <- symbols

(III) BASIC TECHNICAL ANALYSIS

Before diving into our prediction model, let’s take a quick look of the time series data from “01-02-2019” to “05-13-2020”. There are two obvious observations from the chart, i.e. 1) there’s a steady upward trend presented in the data, and 2) there’s a significant and rapid down turn (caused by the pandemic) starting on “02-24-2020” until a bounce-back on “03-23-2020”. The chart includes multiple technical indicators, e.g. Bollinger Bands, Width and %B Indicator, Average Directional Movement Index (ADX), Moving Average Convergence Divergence (MACD), Relative Strength Index (RSI), Commodity Channel Index (CCI), Chaikin Money Flow (CMF), and Trading Volume.

(IV) DATA TRANSFORMATION, BUILD MODELS

There are four simple concepts that we need to first go over, i.e. i) nday (or tday as they are interchangable throughout the script), ii) lday, iii) trend, and iv) close_percentile_threshold.

nday is referred to the number of future trading day(s). For example, we want to use today (t) closing price to predict tomorrow (t plus 1) closing price, and we want to know whether the difference (closing tomorrow - closing today) / closing today would signal an upward or downward trend. Therefore, we actually look at two trends, and we simply refer them as “bullish” and “bearish”.

How should we set up a threshold for triggering a “bullish” or “bearish” signal? We look at the change in percentage between today and future values. Say, we want to make a prediction for tomorrow (or the next trading window), we first calculate the ratio of (closing tomorrow - closing today) / closing today, and then we find the distribution and look up the percentile (see below density curves for better illustration). Anything that is roughly above 1 SD is considered to be an upward trend (“bullish”) signal, whereas anything that is roughly below 1 SD (“bearish”) is considered to be a downward trend signal. We decide to choose roughly “plus or minus one SD” as our close_percentile_threshold, i.e. above 85th percentile / below 15th perentile. Thus our target of prediction is always a moving target based on market volatility and the gap between current and future trading windows. We decide to go with a very liberal approach (roughly plus or minus 1 SD) because we do not want to miss any signal. We want to avoid any type II error.

In addition, we need to transform our data by getting values from the past to see if that would predict the future. We use “5 ndays” and “5 ldays” in this final project. The 5 ndays are 1, 2, 3, 4, and 5, whereas the ldays are 1, 5, 10, 15, and 20. What that means is that for each n day, we use 5 ldays and each lday would make an individual prediction for the nday. Subsequently, we would create a consensus out of the 5 models. For example, let’s say we use trading volume to predict closing price. We would transform our data and get the trading volume of today minus 1 (previous trading day), today minus 5 (5 days ago), 10 days ago, 15 days ago, and 20 days ago. Each set of data would make a prediction of today plus 1 (next trading day), plus 2, 3, and so forth. We need to find a consensus out of these five models and that’s our signal for trend.

We write a custom function to transform and return values plus multiple indicators (such as RSI, MACD) from the time series object that we pull from quantmod. Please see the appendix for detail.

After data transformation, we build separate classification models to identify whether future trading day will close at higher or lower end than the present day. Our target is actually a threshold, i.e. whether it is above or below 1 SD and we use it as our predicted or dependent variable (“Yes” or “No”).

We build our classification/prediction model using different algorithms, i.e. glm (generalized linear model), nb (naive bayes) and gbm (gradient boosting machine). We build a base layer (using glm, nb and gbm) to predict the target from the train set. Second, we build a top layer (again using glm, nb and gbm) to predict the target based on the outcomes (OOF or Out-Of-Fold prediction) of our base layer. In other words, we make prediction (of the target variable) based on the predictions of our base models. Finally, we simply average the outcome probabilities of our top layer to get our final probability and decision using 0.5 as cut-off.

Instead of using entire historical record, let’s just focus on the past 1000 trading days. We split the data by 80/20 for our train and test sets respectively. Finally, we use the past 90 trading days as our evaluation set for accuracy.

Our focus is to see whether our data transformation (using ldays 1, 5, 10, 15, 20 to predict for ndays 1, 2, 3, 4, 5) and ensembling different algorithms would return any signal about stock price movement.

(V) RESULTS

Here we show a snippet of the original data, then the same piece of data after transformation with additional features, and subsequently, we scale and impute missing data and split it into train and test sets respectively.

Down below is a summary of the model output. We care mainly about the model of “final - averaging” and that’s the result of our top layer ensembling our models. We apply that specific model to our evaluation set using the most recent 90 trading days (including today closing price on 2020-05-13) to generate prediction. The target field represents the actual, whereas the pred_final represents our prediction.

original data

AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
300.46 303.240 298.87 300.63 35583438 299.8372
303.22 305.170 301.97 303.74 28803764 302.9390
305.64 310.350 304.29 310.13 33511985 310.1300
308.10 317.050 307.24 315.01 36486561 315.0100
317.83 319.688 310.91 311.41 40575263 311.4100
312.15 315.950 303.21 307.65 49979647 307.6500

after transformation

trend symbol l_period n_period partition date year quarter month weekday day open high low close volume adjusted rsi_close cci_close macd_close signal_close macd_close_diff op_l hi_l lo_l cl_l vol_l adj_l op_n hi_n lo_n cl_n vol_n adj_n cl_op_diff hi_lo_diff op_l_diff hi_l_diff lo_l_diff cl_l_diff vol_l_diff adj_l_diff op_n_diff hi_n_diff lo_n_diff cl_n_diff vol_n_diff adj_n_diff op_l_percent_diff hi_l_percent_diff lo_l_percent_diff cl_l_percent_diff vol_l_percent_diff cl_op_diff_by_op hi_lo_diff_by_op cl_op_diff_by_cl_l hi_lo_diff_by_cl_l cl_cl_l_ratio op_cl_l_ratio vol_cl_l_ratio vol_op_l_ratio vol_diff_ratio sma_5 sma_10 sma_15 target
996 bearish AAPL 20 5 5 2020-05-06 2020 2 5 Wednesday 6 300.46 303.240 298.87 300.63 35583438 299.8372 62.79564 153.90974 2.729758 1.968072 0.7616867 270.80 271.70 259.00 259.43 50721831 258.7459 312.15 315.95 303.21 307.65 49979647 307.65 0.17 4.370 29.66 31.540 39.87 41.20 -15138393 41.0913 11.69 12.71 4.34 7.02 14396209 7.8128 0.1095273 0.1160839 0.1539382 0.1588097 -0.2984591 0.0005658 0.0145444 0.0006553 0.0168446 1.158810 1.158154 -0.2575566 -0.2577024 -0.9509734 294.844 288.170 284.8393 No
997 bearish AAPL 20 5 4 2020-05-07 2020 2 5 Thursday 7 303.22 305.170 301.97 303.74 28803764 302.9390 64.18093 162.03047 2.958091 2.166075 0.7920153 262.74 267.37 261.23 266.07 42223821 265.3684 NA NA NA NA NA NA 0.52 3.200 40.48 37.800 40.74 37.67 -13420057 37.5706 NA NA NA NA NA NA 0.1540687 0.1413771 0.1559545 0.1415793 -0.3178314 0.0017149 0.0105534 0.0019544 0.0120269 1.141579 1.139625 -0.2784138 -0.2788913 NA 296.832 291.041 285.9760 NA
998 bearish AAPL 20 5 3 2020-05-08 2020 2 5 Friday 8 305.64 310.350 304.29 310.13 33511985 310.1300 66.90741 187.14544 3.273022 2.387465 0.8855568 268.70 270.07 264.70 267.99 40529123 267.2833 NA NA NA NA NA NA 4.49 6.060 36.94 40.280 39.59 42.14 -7017138 42.8467 NA NA NA NA NA NA 0.1374767 0.1491465 0.1495655 0.1572447 -0.1731382 0.0146905 0.0198272 0.0167544 0.0226128 1.157245 1.140490 -0.1496124 -0.1518103 NA 301.044 293.757 287.7980 NA
999 bearish AAPL 20 5 2 2020-05-11 2020 2 5 Monday 11 308.10 317.050 307.24 315.01 36486561 315.0100 68.85704 187.12734 3.607397 2.631451 0.9759463 268.31 273.70 265.83 273.25 32755731 272.5294 NA NA NA NA NA NA 6.91 9.810 39.79 43.350 41.41 41.76 3730830 42.4806 NA NA NA NA NA NA 0.1482986 0.1583851 0.1557762 0.1528271 0.1138985 0.0224278 0.0318403 0.0252882 0.0359012 1.152827 1.127539 0.0987993 0.1010152 NA 305.414 296.941 290.3367 NA
1000 bearish AAPL 20 5 1 2020-05-12 2020 2 5 Tuesday 12 317.83 319.688 310.91 311.41 40575263 311.4100 65.77831 134.84359 3.724404 2.850042 0.8743619 280.00 288.25 278.05 287.05 48748672 286.2930 NA NA NA NA NA NA -6.42 8.778 37.83 31.438 32.86 24.36 -8173409 25.1170 NA NA NA NA NA NA 0.1351071 0.1090650 0.1181802 0.0848633 -0.1676642 -0.0201995 0.0276185 -0.0223654 0.0305800 1.084863 1.107229 -0.1545487 -0.1514269 NA 308.184 300.224 293.2060 NA
1001 bearish AAPL 20 5 0 2020-05-13 2020 2 5 Wednesday 13 312.15 315.950 303.21 307.65 49979647 307.6500 62.62864 97.34025 3.669459 3.013925 0.6555334 282.40 286.33 280.63 284.43 32788641 283.6799 NA NA NA NA NA NA -4.50 12.740 29.75 29.620 22.58 23.22 17191006 23.9701 NA NA NA NA NA NA 0.1053470 0.1034471 0.0804618 0.0816370 0.5242976 -0.0144161 0.0408137 -0.0158211 0.0447913 1.081637 1.097458 0.4847260 0.4777382 NA 309.588 302.216 295.3093 NA

train set

partition date rsi_close op_cl_l_ratio hi_l_percent_diff lo_l_percent_diff op_l_percent_diff cl_l_percent_diff cl_cl_l_ratio cci_close macd_close vol_n_diff sma_15 hi_lo_diff_by_op signal_close sma_10 hi_lo_diff_by_cl_l sma_5 vol_op_l_ratio vol_cl_l_ratio vol_l_percent_diff target OOF_pred_glm OOF_pred_nb OOF_pred_gbm
577 788 2017-03-27 0.5941293 -0.0860625 0.0259496 -0.1089624 -0.1193624 0.0403788 0.0403788 0.4141655 0.4252867 -0.2157906 -0.7407335 0.0645776 0.6234565 -0.7380919 0.1003626 -0.7402292 0.0261690 0.0230661 0.0443486 No 0.1714786 0.0007146 0.0862415
578 807 2017-02-28 2.1115116 1.3386435 1.3890034 1.3505992 1.3935076 1.2993760 1.2993760 0.3519109 1.1673768 -0.3635380 -0.8372603 -1.0525550 1.3213788 -0.8182669 -1.1111413 -0.8128807 -0.5186544 -0.5190177 -0.5559561 No 0.0266172 0.0000018 0.0250923
579 963 2016-07-15 0.1820300 -0.1372888 -0.1295660 -0.0065412 -0.0005129 -0.1694323 -0.1694323 1.1565614 -0.2014732 -0.1091657 -1.5739526 -0.8234686 -0.4716169 -1.5579675 -0.9091749 -1.5415584 -0.2721179 -0.2725347 -0.2656148 No 0.0884190 0.0064820 0.3607964
580 341 2019-01-04 -1.6841555 -2.6985096 -2.8102498 -2.6479124 -2.9306403 -2.4113899 -2.4113899 -1.3951217 -3.1012486 -1.9059406 -0.4187683 1.2591131 -3.1829453 -0.5042487 0.8392387 -0.5215289 0.5518789 0.5316656 0.4342095 No 0.1401079 0.9999145 0.4710399
581 303 2019-03-01 0.4176277 0.2945936 0.1437523 0.3127654 0.3039570 0.3298467 0.3298467 0.6494030 0.5705581 -0.1129988 -0.1385437 -0.4132670 0.6092631 -0.1314229 -0.4058939 -0.1142257 -0.7394433 -0.7373897 -0.7674001 No 0.1186773 0.0285232 0.0621122
583 836 2017-01-17 0.9556489 -0.0365185 0.0596136 0.0017050 0.0000713 0.1339740 0.1339740 0.9078716 0.3346000 -0.6770169 -1.1610390 -0.0684980 0.3075284 -1.1550585 -0.0444153 -1.1376118 -0.5981109 -0.5929348 -0.6063222 No 0.0723700 0.0036941 0.0333305

evaluation (prediction) output

trend symbol n_period l_period date target pred_final_avg pred_final
bearish AAPL 5 20 2020-01-03 No 0.1861071 0
bearish AAPL 5 20 2020-01-06 No 0.0357360 0
bearish AAPL 5 20 2020-01-07 No 0.1161324 0
bearish AAPL 5 20 2020-01-08 No 0.0312756 0
bearish AAPL 5 20 2020-01-09 No 0.1627764 0
bearish AAPL 5 20 2020-01-10 No 0.2898218 0
bearish AAPL 5 20 2020-01-13 No 0.0300195 0
bearish AAPL 5 20 2020-01-14 No 0.0406912 0
bearish AAPL 5 20 2020-01-15 No 0.0304247 0
bearish AAPL 5 20 2020-01-16 No 0.0386506 0
bearish AAPL 5 20 2020-01-17 Yes 0.0877919 0
bearish AAPL 5 20 2020-01-21 No 0.0425072 0
bearish AAPL 5 20 2020-01-22 No 0.0851848 0
bearish AAPL 5 20 2020-01-23 No 0.1274586 0
bearish AAPL 5 20 2020-01-24 Yes 0.2583408 0
bearish AAPL 5 20 2020-01-27 No 0.6950139 1
bearish AAPL 5 20 2020-01-28 No 0.1140367 0
bearish AAPL 5 20 2020-01-29 No 0.0322130 0
bearish AAPL 5 20 2020-01-30 No 0.0338633 0
bearish AAPL 5 20 2020-01-31 No 0.1093895 0
bearish AAPL 5 20 2020-02-03 No 0.0337342 0
bearish AAPL 5 20 2020-02-04 No 0.0308722 0
bearish AAPL 5 20 2020-02-05 No 0.0369197 0
bearish AAPL 5 20 2020-02-06 No 0.0333376 0
bearish AAPL 5 20 2020-02-07 No 0.0297580 0
bearish AAPL 5 20 2020-02-10 No 0.0531578 0
bearish AAPL 5 20 2020-02-11 No 0.0277412 0
bearish AAPL 5 20 2020-02-12 No 0.0296434 0
bearish AAPL 5 20 2020-02-13 Yes 0.0323237 0
bearish AAPL 5 20 2020-02-14 Yes 0.1231750 0
bearish AAPL 5 20 2020-02-18 Yes 0.7426590 1
bearish AAPL 5 20 2020-02-19 Yes 0.5701448 1
bearish AAPL 5 20 2020-02-20 Yes 0.7746513 1
bearish AAPL 5 20 2020-02-21 Yes 0.9082341 1
bearish AAPL 5 20 2020-02-24 No 0.8194669 1
bearish AAPL 5 20 2020-02-25 No 0.5853079 1
bearish AAPL 5 20 2020-02-26 No 0.4502759 0
bearish AAPL 5 20 2020-02-27 No 0.3688501 0
bearish AAPL 5 20 2020-02-28 No 0.9561448 1
bearish AAPL 5 20 2020-03-02 Yes 0.7279586 1
bearish AAPL 5 20 2020-03-03 No 0.4082508 0
bearish AAPL 5 20 2020-03-04 Yes 0.6489827 1
bearish AAPL 5 20 2020-03-05 Yes 0.8656721 1
bearish AAPL 5 20 2020-03-06 Yes 0.9364427 1
bearish AAPL 5 20 2020-03-09 Yes 0.9453148 1
bearish AAPL 5 20 2020-03-10 Yes 0.8233193 1
bearish AAPL 5 20 2020-03-11 Yes 0.7021333 1
bearish AAPL 5 20 2020-03-12 No 0.9597048 1
bearish AAPL 5 20 2020-03-13 Yes 0.9364633 1
bearish AAPL 5 20 2020-03-16 Yes 0.9384207 1
bearish AAPL 5 20 2020-03-17 No 0.9211511 1
bearish AAPL 5 20 2020-03-18 No 0.7667433 1
bearish AAPL 5 20 2020-03-19 No 0.6779139 1
bearish AAPL 5 20 2020-03-20 No 0.9292353 1
bearish AAPL 5 20 2020-03-23 No 0.7835432 1
bearish AAPL 5 20 2020-03-24 No 0.3590859 0
bearish AAPL 5 20 2020-03-25 No 0.1895799 0
bearish AAPL 5 20 2020-03-26 Yes 0.0841470 0
bearish AAPL 5 20 2020-03-27 Yes 0.0287567 0
bearish AAPL 5 20 2020-03-30 No 0.0694237 0
bearish AAPL 5 20 2020-03-31 No 0.0341530 0
bearish AAPL 5 20 2020-04-01 No 0.0341902 0
bearish AAPL 5 20 2020-04-02 No 0.0737650 0
bearish AAPL 5 20 2020-04-03 No 0.0343496 0
bearish AAPL 5 20 2020-04-06 No 0.0289993 0
bearish AAPL 5 20 2020-04-07 No 0.0287062 0
bearish AAPL 5 20 2020-04-08 No 0.0270313 0
bearish AAPL 5 20 2020-04-09 No 0.0744268 0
bearish AAPL 5 20 2020-04-13 No 0.0320685 0
bearish AAPL 5 20 2020-04-14 Yes 0.0274313 0
bearish AAPL 5 20 2020-04-15 Yes 0.0276674 0
bearish AAPL 5 20 2020-04-16 Yes 0.0269232 0
bearish AAPL 5 20 2020-04-17 No 0.0274259 0
bearish AAPL 5 20 2020-04-20 No 0.0276178 0
bearish AAPL 5 20 2020-04-21 No 0.0276837 0
bearish AAPL 5 20 2020-04-22 No 0.0288562 0
bearish AAPL 5 20 2020-04-23 No 0.0340632 0
bearish AAPL 5 20 2020-04-24 No 0.1854106 0
bearish AAPL 5 20 2020-04-27 No 0.0299120 0
bearish AAPL 5 20 2020-04-28 No 0.0325296 0
bearish AAPL 5 20 2020-04-29 No 0.0267825 0
bearish AAPL 5 20 2020-04-30 No 0.0284602 0
bearish AAPL 5 20 2020-05-01 No 0.0333916 0
bearish AAPL 5 20 2020-05-04 No 0.0508018 0
bearish AAPL 5 20 2020-05-05 No 0.0414098 0
bearish AAPL 5 20 2020-05-06 No 0.0794864 0
bearish AAPL 5 20 2020-05-07 NA 0.0308495 0
bearish AAPL 5 20 2020-05-08 NA 0.0283522 0
bearish AAPL 5 20 2020-05-11 NA 0.0303203 0
bearish AAPL 5 20 2020-05-12 NA 0.0273319 0
bearish AAPL 5 20 2020-05-13 NA 0.0515707 0

model summary output

trend symbol n_period l_period trainMethod accuracy balanced_accuracy detection_prevalence detection_rate f1 kappa neg_pred_value pos_pred_value precision prevalence recall sensitivity specificity
bearish AAPL 1 1 final - averaging 0.7889908 0.6970637 0.2018349 0.1376147 0.5660377 0.4319057 0.8160920 0.6818182 0.6818182 0.2844037 0.4838710 0.4838710 0.9102564
bearish AAPL 1 5 final - averaging 0.7889908 0.7456576 0.2935780 0.1834862 0.6349206 0.4865861 0.8571429 0.6250000 0.6250000 0.2844037 0.6451613 0.6451613 0.8461538
bearish AAPL 1 10 final - averaging 0.7870370 0.7397436 0.2870370 0.1759259 0.6229508 0.4746193 0.8571429 0.6129032 0.6129032 0.2777778 0.6333333 0.6333333 0.8461538
bearish AAPL 1 15 final - averaging 0.8272727 0.7491987 0.2090909 0.1636364 0.6545455 0.5434688 0.8390805 0.7826087 0.7826087 0.2909091 0.5625000 0.5625000 0.9358974
bearish AAPL 1 20 final - averaging 0.8490566 0.8516484 0.3396226 0.2264151 0.7500000 0.6442953 0.9428571 0.6666667 0.6666667 0.2641509 0.8571429 0.8571429 0.8461538
bearish AAPL 1 1 gbm 0.7889908 0.6970637 0.2018349 0.1376147 0.5660377 0.4319057 0.8160920 0.6818182 0.6818182 0.2844037 0.4838710 0.4838710 0.9102564
bearish AAPL 1 5 gbm 0.7981651 0.7520678 0.2844037 0.1834862 0.6451613 0.5041356 0.8589744 0.6451613 0.6451613 0.2844037 0.6451613 0.6451613 0.8589744
bearish AAPL 1 10 gbm 0.7962963 0.7564103 0.2962963 0.1851852 0.6451613 0.5025126 0.8684211 0.6250000 0.6250000 0.2777778 0.6666667 0.6666667 0.8461538
bearish AAPL 1 15 gbm 0.8272727 0.7584135 0.2272727 0.1727273 0.6666667 0.5524625 0.8470588 0.7600000 0.7600000 0.2909091 0.5937500 0.5937500 0.9230769
bearish AAPL 1 20 gbm 0.8396226 0.8337912 0.3301887 0.2169811 0.7301587 0.6180585 0.9295775 0.6571429 0.6571429 0.2641509 0.8214286 0.8214286 0.8461538
bearish AAPL 1 1 gbm - top layer 0.7798165 0.6809347 0.1926606 0.1284404 0.5384615 0.4008246 0.8068182 0.6666667 0.6666667 0.2844037 0.4516129 0.4516129 0.9102564
bearish AAPL 1 5 gbm - top layer 0.8165138 0.7551696 0.2477064 0.1743119 0.6551724 0.5309811 0.8536585 0.7037037 0.7037037 0.2844037 0.6129032 0.6129032 0.8974359
bearish AAPL 1 10 gbm - top layer 0.7777778 0.7230769 0.2777778 0.1666667 0.6000000 0.4461538 0.8461538 0.6000000 0.6000000 0.2777778 0.6000000 0.6000000 0.8461538
bearish AAPL 1 15 gbm - top layer 0.7727273 0.6462340 0.1363636 0.1000000 0.4680851 0.3467933 0.7789474 0.7333333 0.7333333 0.2909091 0.3437500 0.3437500 0.9487179
bearish AAPL 1 20 gbm - top layer 0.7735849 0.7316850 0.3018868 0.1698113 0.6000000 0.4430823 0.8648649 0.5625000 0.5625000 0.2641509 0.6428571 0.6428571 0.8205128
bearish AAPL 1 1 glm 0.7981651 0.6743176 0.1376147 0.1100917 0.5217391 0.4128306 0.7978723 0.8000000 0.8000000 0.2844037 0.3870968 0.3870968 0.9615385
bearish AAPL 1 5 glm 0.7522936 0.6519851 0.2018349 0.1192661 0.4905660 0.3331067 0.7931034 0.5909091 0.5909091 0.2844037 0.4193548 0.4193548 0.8846154
bearish AAPL 1 10 glm 0.7685185 0.6756410 0.2129630 0.1296296 0.5283019 0.3784530 0.8117647 0.6086957 0.6086957 0.2777778 0.4666667 0.4666667 0.8846154
bearish AAPL 1 15 glm 0.7454545 0.6177885 0.1454545 0.0909091 0.4166667 0.2763158 0.7659574 0.6250000 0.6250000 0.2909091 0.3125000 0.3125000 0.9230769
bearish AAPL 1 20 glm 0.8113208 0.7573260 0.2641509 0.1698113 0.6428571 0.5146520 0.8717949 0.6428571 0.6428571 0.2641509 0.6428571 0.6428571 0.8717949
bearish AAPL 1 1 glm - top layer 0.7889908 0.6873449 0.1834862 0.1284404 0.5490196 0.4195416 0.8089888 0.7000000 0.7000000 0.2844037 0.4516129 0.4516129 0.9230769
bearish AAPL 1 5 glm - top layer 0.8073394 0.7487593 0.2568807 0.1743119 0.6440678 0.5124601 0.8518519 0.6785714 0.6785714 0.2844037 0.6129032 0.6129032 0.8846154
bearish AAPL 1 10 glm - top layer 0.7962963 0.7564103 0.2962963 0.1851852 0.6451613 0.5025126 0.8684211 0.6250000 0.6250000 0.2777778 0.6666667 0.6666667 0.8461538
bearish AAPL 1 15 glm - top layer 0.8090909 0.7271635 0.2090909 0.1545455 0.6181818 0.4954128 0.8275862 0.7391304 0.7391304 0.2909091 0.5312500 0.5312500 0.9230769
bearish AAPL 1 20 glm - top layer 0.8490566 0.8402015 0.3207547 0.2169811 0.7419355 0.6366752 0.9305556 0.6764706 0.6764706 0.2641509 0.8214286 0.8214286 0.8589744
bearish AAPL 1 1 nb 0.7614679 0.6875517 0.2477064 0.1467890 0.5517241 0.3902754 0.8170732 0.5925926 0.5925926 0.2844037 0.5161290 0.5161290 0.8589744
bearish AAPL 1 5 nb 0.6880734 0.6459884 0.3394495 0.1559633 0.5000000 0.2758890 0.8055556 0.4594595 0.4594595 0.2844037 0.5483871 0.5483871 0.7435897
bearish AAPL 1 10 nb 0.7222222 0.6743590 0.3148148 0.1574074 0.5312500 0.3349754 0.8243243 0.5000000 0.5000000 0.2777778 0.5666667 0.5666667 0.7820513
bearish AAPL 1 15 nb 0.7000000 0.6225962 0.2636364 0.1272727 0.4590164 0.2521632 0.7777778 0.4827586 0.4827586 0.2909091 0.4375000 0.4375000 0.8076923
bearish AAPL 1 20 nb 0.7830189 0.7495421 0.3113208 0.1792453 0.6229508 0.4720658 0.8767123 0.5757576 0.5757576 0.2641509 0.6785714 0.6785714 0.8205128
bearish AAPL 1 1 nb - top layer 0.7798165 0.7003722 0.2293578 0.1467890 0.5714286 0.4255599 0.8214286 0.6400000 0.6400000 0.2844037 0.5161290 0.5161290 0.8846154
bearish AAPL 1 5 nb - top layer 0.7614679 0.7264268 0.3211009 0.1834862 0.6060606 0.4359076 0.8513514 0.5714286 0.5714286 0.2844037 0.6451613 0.6451613 0.8076923
bearish AAPL 1 10 nb - top layer 0.7500000 0.7346154 0.3611111 0.1944444 0.6086957 0.4295775 0.8695652 0.5384615 0.5384615 0.2777778 0.7000000 0.7000000 0.7692308
bearish AAPL 1 15 nb - top layer 0.8000000 0.7207532 0.2181818 0.1545455 0.6071429 0.4766436 0.8255814 0.7083333 0.7083333 0.2909091 0.5312500 0.5312500 0.9102564
bearish AAPL 1 20 nb - top layer 0.8396226 0.8223443 0.3113208 0.2075472 0.7213115 0.6097878 0.9178082 0.6666667 0.6666667 0.2641509 0.7857143 0.7857143 0.8589744
bearish AAPL 2 1 final - averaging 0.7818182 0.7355769 0.2909091 0.1818182 0.6250000 0.4711538 0.8461538 0.6250000 0.6250000 0.2909091 0.6250000 0.6250000 0.8461538
bearish AAPL 2 5 final - averaging 0.8288288 0.7995338 0.3063063 0.2162162 0.7164179 0.5938764 0.8831169 0.7058824 0.7058824 0.2972973 0.7272727 0.7272727 0.8717949
bearish AAPL 2 10 final - averaging 0.8035714 0.7760181 0.3214286 0.2142857 0.6857143 0.5430267 0.8684211 0.6666667 0.6666667 0.3035714 0.7058824 0.7058824 0.8461538
bearish AAPL 2 15 final - averaging 0.8648649 0.8251748 0.2702703 0.2162162 0.7619048 0.6678636 0.8888889 0.8000000 0.8000000 0.2972973 0.7272727 0.7272727 0.9230769
bearish AAPL 2 20 final - averaging 0.8571429 0.8310709 0.3035714 0.2321429 0.7647059 0.6621418 0.8974359 0.7647059 0.7647059 0.3035714 0.7647059 0.7647059 0.8974359
bearish AAPL 2 1 gbm 0.8363636 0.7924679 0.2727273 0.2000000 0.7096774 0.5959184 0.8750000 0.7333333 0.7333333 0.2909091 0.6875000 0.6875000 0.8974359
bearish AAPL 2 5 gbm 0.8468468 0.8210956 0.3063063 0.2252252 0.7462687 0.6366262 0.8961039 0.7352941 0.7352941 0.2972973 0.7575758 0.7575758 0.8846154
bearish AAPL 2 10 gbm 0.7857143 0.7466063 0.3035714 0.1964286 0.6470588 0.4932127 0.8461538 0.6470588 0.6470588 0.3035714 0.6470588 0.6470588 0.8461538
bearish AAPL 2 15 gbm 0.8648649 0.8251748 0.2702703 0.2162162 0.7619048 0.6678636 0.8888889 0.8000000 0.8000000 0.2972973 0.7272727 0.7272727 0.9230769
bearish AAPL 2 20 gbm 0.8660714 0.8291855 0.2767857 0.2232143 0.7692308 0.6751740 0.8888889 0.8064516 0.8064516 0.3035714 0.7352941 0.7352941 0.9230769
bearish AAPL 2 1 gbm - top layer 0.8636364 0.8209135 0.2636364 0.2090909 0.7540984 0.6600742 0.8888889 0.7931034 0.7931034 0.2909091 0.7187500 0.7187500 0.9230769
bearish AAPL 2 5 gbm - top layer 0.8198198 0.8018648 0.3333333 0.2252252 0.7142857 0.5833333 0.8918919 0.6756757 0.6756757 0.2972973 0.7575758 0.7575758 0.8461538
bearish AAPL 2 10 gbm - top layer 0.8035714 0.7594268 0.2857143 0.1964286 0.6666667 0.5276074 0.8500000 0.6875000 0.6875000 0.3035714 0.6470588 0.6470588 0.8717949
bearish AAPL 2 15 gbm - top layer 0.8738739 0.8403263 0.2792793 0.2252252 0.7812500 0.6927639 0.9000000 0.8064516 0.8064516 0.2972973 0.7575758 0.7575758 0.9230769
bearish AAPL 2 20 gbm - top layer 0.8571429 0.8310709 0.3035714 0.2321429 0.7647059 0.6621418 0.8974359 0.7647059 0.7647059 0.3035714 0.7647059 0.7647059 0.8974359
bearish AAPL 2 1 glm 0.6818182 0.5637019 0.1909091 0.0818182 0.3396226 0.1417744 0.7415730 0.4285714 0.4285714 0.2909091 0.2812500 0.2812500 0.8461538
bearish AAPL 2 5 glm 0.7747748 0.6736597 0.1801802 0.1261261 0.5283019 0.3918475 0.7912088 0.7000000 0.7000000 0.2972973 0.4242424 0.4242424 0.9230769
bearish AAPL 2 10 glm 0.7589286 0.7024887 0.2767857 0.1696429 0.5846154 0.4153132 0.8148148 0.6129032 0.6129032 0.3035714 0.5588235 0.5588235 0.8461538
bearish AAPL 2 15 glm 0.7567568 0.6608392 0.1981982 0.1261261 0.5090909 0.3558994 0.7865169 0.6363636 0.6363636 0.2972973 0.4242424 0.4242424 0.8974359
bearish AAPL 2 20 glm 0.7142857 0.6206637 0.2142857 0.1160714 0.4482759 0.2631579 0.7613636 0.5416667 0.5416667 0.3035714 0.3823529 0.3823529 0.8589744
bearish AAPL 2 1 glm - top layer 0.8181818 0.7520032 0.2363636 0.1727273 0.6551724 0.5335030 0.8452381 0.7307692 0.7307692 0.2909091 0.5937500 0.5937500 0.9102564
bearish AAPL 2 5 glm - top layer 0.8288288 0.7907925 0.2882883 0.2072072 0.7076923 0.5867137 0.8734177 0.7187500 0.7187500 0.2972973 0.6969697 0.6969697 0.8846154
bearish AAPL 2 10 glm - top layer 0.8035714 0.7594268 0.2857143 0.1964286 0.6666667 0.5276074 0.8500000 0.6875000 0.6875000 0.3035714 0.6470588 0.6470588 0.8717949
bearish AAPL 2 15 glm - top layer 0.8648649 0.8251748 0.2702703 0.2162162 0.7619048 0.6678636 0.8888889 0.8000000 0.8000000 0.2972973 0.7272727 0.7272727 0.9230769
bearish AAPL 2 20 glm - top layer 0.8482143 0.7997738 0.2589286 0.2053571 0.7301587 0.6254917 0.8674699 0.7931034 0.7931034 0.3035714 0.6764706 0.6764706 0.9230769
bearish AAPL 2 1 nb 0.6363636 0.5500801 0.2727273 0.1000000 0.3548387 0.1020408 0.7375000 0.3666667 0.3666667 0.2909091 0.3437500 0.3437500 0.7564103
bearish AAPL 2 5 nb 0.7207207 0.6789044 0.3243243 0.1711712 0.5507246 0.3486655 0.8133333 0.5277778 0.5277778 0.2972973 0.5757576 0.5757576 0.7820513
bearish AAPL 2 10 nb 0.7053571 0.6474359 0.2946429 0.1517857 0.5074627 0.2973384 0.7848101 0.5151515 0.5151515 0.3035714 0.5000000 0.5000000 0.7948718
bearish AAPL 2 15 nb 0.6486486 0.5926573 0.3243243 0.1351351 0.4347826 0.1805792 0.7600000 0.4166667 0.4166667 0.2972973 0.4545455 0.4545455 0.7307692
bearish AAPL 2 20 nb 0.6875000 0.6843891 0.4196429 0.2053571 0.5679012 0.3328795 0.8307692 0.4893617 0.4893617 0.3035714 0.6764706 0.6764706 0.6923077
bearish AAPL 2 1 nb - top layer 0.7636364 0.7227564 0.3090909 0.1818182 0.6060606 0.4374508 0.8421053 0.5882353 0.5882353 0.2909091 0.6250000 0.6250000 0.8205128
bearish AAPL 2 5 nb - top layer 0.7747748 0.7610723 0.3603604 0.2162162 0.6575342 0.4920373 0.8732394 0.6000000 0.6000000 0.2972973 0.7272727 0.7272727 0.7948718
bearish AAPL 2 10 nb - top layer 0.7946429 0.7696078 0.3303571 0.2142857 0.6760563 0.5261221 0.8666667 0.6486486 0.6486486 0.3035714 0.7058824 0.7058824 0.8333333
bearish AAPL 2 15 nb - top layer 0.8648649 0.8339161 0.2882883 0.2252252 0.7692308 0.6737213 0.8987342 0.7812500 0.7812500 0.2972973 0.7575758 0.7575758 0.9102564
bearish AAPL 2 20 nb - top layer 0.8214286 0.8054299 0.3392857 0.2321429 0.7222222 0.5912409 0.8918919 0.6842105 0.6842105 0.3035714 0.7647059 0.7647059 0.8461538
bearish AAPL 3 1 final - averaging 0.8425926 0.8192308 0.3055556 0.2129630 0.7301587 0.6194030 0.9066667 0.6969697 0.6969697 0.2777778 0.7666667 0.7666667 0.8717949
bearish AAPL 3 5 final - averaging 0.8508772 0.8162393 0.2894737 0.2280702 0.7536232 0.6469945 0.8765432 0.7878788 0.7878788 0.3157895 0.7222222 0.7222222 0.9102564
bearish AAPL 3 10 final - averaging 0.8198198 0.7843823 0.2972973 0.2072072 0.6969697 0.5687646 0.8717949 0.6969697 0.6969697 0.2972973 0.6969697 0.6969697 0.8717949
bearish AAPL 3 15 final - averaging 0.8440367 0.8035567 0.2752294 0.2018349 0.7213115 0.6130716 0.8860759 0.7333333 0.7333333 0.2844037 0.7096774 0.7096774 0.8974359
bearish AAPL 3 20 final - averaging 0.8807339 0.8583540 0.2935780 0.2293578 0.7936508 0.7098095 0.9220779 0.7812500 0.7812500 0.2844037 0.8064516 0.8064516 0.9102564
bearish AAPL 3 1 gbm 0.8703704 0.8487179 0.2962963 0.2222222 0.7741935 0.6834171 0.9210526 0.7500000 0.7500000 0.2777778 0.8000000 0.8000000 0.8974359
bearish AAPL 3 5 gbm 0.8508772 0.8087607 0.2719298 0.2192982 0.7462687 0.6415094 0.8674699 0.8064516 0.8064516 0.3157895 0.6944444 0.6944444 0.9230769
bearish AAPL 3 10 gbm 0.8198198 0.7756410 0.2792793 0.1981982 0.6875000 0.5610913 0.8625000 0.7096774 0.7096774 0.2972973 0.6666667 0.6666667 0.8846154
bearish AAPL 3 15 gbm 0.8532110 0.8099669 0.2660550 0.2018349 0.7333333 0.6322227 0.8875000 0.7586207 0.7586207 0.2844037 0.7096774 0.7096774 0.9102564
bearish AAPL 3 20 gbm 0.8899083 0.8744830 0.3027523 0.2385321 0.8125000 0.7346856 0.9342105 0.7878788 0.7878788 0.2844037 0.8387097 0.8387097 0.9102564
bearish AAPL 3 1 gbm - top layer 0.8240741 0.7961538 0.3055556 0.2037037 0.6984127 0.5746269 0.8933333 0.6666667 0.6666667 0.2777778 0.7333333 0.7333333 0.8589744
bearish AAPL 3 5 gbm - top layer 0.8421053 0.8023504 0.2807018 0.2192982 0.7352941 0.6233480 0.8658537 0.7812500 0.7812500 0.3157895 0.6944444 0.6944444 0.9102564
bearish AAPL 3 10 gbm - top layer 0.8198198 0.7843823 0.2972973 0.2072072 0.6969697 0.5687646 0.8717949 0.6969697 0.6969697 0.2972973 0.6969697 0.6969697 0.8717949
bearish AAPL 3 15 gbm - top layer 0.8532110 0.8196857 0.2844037 0.2110092 0.7419355 0.6393714 0.8974359 0.7419355 0.7419355 0.2844037 0.7419355 0.7419355 0.8974359
bearish AAPL 3 20 gbm - top layer 0.8807339 0.8583540 0.2935780 0.2293578 0.7936508 0.7098095 0.9220779 0.7812500 0.7812500 0.2844037 0.8064516 0.8064516 0.9102564
bearish AAPL 3 1 glm 0.7314815 0.5884615 0.1388889 0.0740741 0.3555556 0.2090909 0.7634409 0.5333333 0.5333333 0.2777778 0.2666667 0.2666667 0.9102564
bearish AAPL 3 5 glm 0.7280702 0.6292735 0.1842105 0.1140351 0.4561404 0.2912154 0.7526882 0.6190476 0.6190476 0.3157895 0.3611111 0.3611111 0.8974359
bearish AAPL 3 10 glm 0.7207207 0.6089744 0.1801802 0.0990991 0.4150943 0.2458909 0.7582418 0.5500000 0.5500000 0.2972973 0.3333333 0.3333333 0.8846154
bearish AAPL 3 15 glm 0.7706422 0.6842432 0.2201835 0.1376147 0.5454545 0.3953850 0.8117647 0.6250000 0.6250000 0.2844037 0.4838710 0.4838710 0.8846154
bearish AAPL 3 20 glm 0.7706422 0.6842432 0.2201835 0.1376147 0.5454545 0.3953850 0.8117647 0.6250000 0.6250000 0.2844037 0.4838710 0.4838710 0.8846154
bearish AAPL 3 1 glm - top layer 0.8518519 0.8256410 0.2962963 0.2129630 0.7419355 0.6381910 0.9078947 0.7187500 0.7187500 0.2777778 0.7666667 0.7666667 0.8846154
bearish AAPL 3 5 glm - top layer 0.8684211 0.8290598 0.2719298 0.2280702 0.7761194 0.6836848 0.8795181 0.8387097 0.8387097 0.3157895 0.7222222 0.7222222 0.9358974
bearish AAPL 3 10 glm - top layer 0.8198198 0.7756410 0.2792793 0.1981982 0.6875000 0.5610913 0.8625000 0.7096774 0.7096774 0.2972973 0.6666667 0.6666667 0.8846154
bearish AAPL 3 15 glm - top layer 0.8532110 0.8099669 0.2660550 0.2018349 0.7333333 0.6322227 0.8875000 0.7586207 0.7586207 0.2844037 0.7096774 0.7096774 0.9102564
bearish AAPL 3 20 glm - top layer 0.8807339 0.8583540 0.2935780 0.2293578 0.7936508 0.7098095 0.9220779 0.7812500 0.7812500 0.2844037 0.8064516 0.8064516 0.9102564
bearish AAPL 3 1 nb 0.7037037 0.6615385 0.3333333 0.1574074 0.5151515 0.3043478 0.8194444 0.4722222 0.4722222 0.2777778 0.5666667 0.5666667 0.7564103
bearish AAPL 3 5 nb 0.6929825 0.6036325 0.2192982 0.1140351 0.4262295 0.2258440 0.7415730 0.5200000 0.5200000 0.3157895 0.3611111 0.3611111 0.8461538
bearish AAPL 3 10 nb 0.6846847 0.6270396 0.3063063 0.1441441 0.4776119 0.2518775 0.7792208 0.4705882 0.4705882 0.2972973 0.4848485 0.4848485 0.7692308
bearish AAPL 3 15 nb 0.7247706 0.6716294 0.3027523 0.1559633 0.5312500 0.3367140 0.8157895 0.5151515 0.5151515 0.2844037 0.5483871 0.5483871 0.7948718
bearish AAPL 3 20 nb 0.6788991 0.6492969 0.3669725 0.1651376 0.5070423 0.2745769 0.8115942 0.4500000 0.4500000 0.2844037 0.5806452 0.5806452 0.7179487
bearish AAPL 3 1 nb - top layer 0.8240741 0.8064103 0.3240741 0.2129630 0.7076923 0.5829268 0.9041096 0.6571429 0.6571429 0.2777778 0.7666667 0.7666667 0.8461538
bearish AAPL 3 5 nb - top layer 0.7894737 0.7339744 0.2631579 0.1842105 0.6363636 0.4899329 0.8214286 0.7000000 0.7000000 0.3157895 0.5833333 0.5833333 0.8846154
bearish AAPL 3 10 nb - top layer 0.7747748 0.7348485 0.3063063 0.1891892 0.6268657 0.4656268 0.8441558 0.6176471 0.6176471 0.2972973 0.6363636 0.6363636 0.8333333
bearish AAPL 3 15 nb - top layer 0.8256881 0.7907361 0.2935780 0.2018349 0.6984127 0.5758755 0.8831169 0.6875000 0.6875000 0.2844037 0.7096774 0.7096774 0.8717949
bearish AAPL 3 20 nb - top layer 0.8256881 0.7907361 0.2935780 0.2018349 0.6984127 0.5758755 0.8831169 0.6875000 0.6875000 0.2844037 0.7096774 0.7096774 0.8717949
bearish AAPL 4 1 final - averaging 0.8495575 0.8043956 0.2654867 0.2123894 0.7384615 0.6337464 0.8674699 0.8000000 0.8000000 0.3097345 0.6857143 0.6857143 0.9230769
bearish AAPL 4 5 final - averaging 0.8545455 0.8145032 0.2727273 0.2090909 0.7419355 0.6408163 0.8875000 0.7666667 0.7666667 0.2909091 0.7187500 0.7187500 0.9102564
bearish AAPL 4 10 final - averaging 0.8333333 0.7820513 0.2592593 0.1851852 0.6896552 0.5759162 0.8750000 0.7142857 0.7142857 0.2777778 0.6666667 0.6666667 0.8974359
bearish AAPL 4 15 final - averaging 0.8285714 0.7877493 0.2761905 0.1809524 0.6785714 0.5618915 0.8947368 0.6551724 0.6551724 0.2571429 0.7037037 0.7037037 0.8717949
bearish AAPL 4 20 final - averaging 0.8518519 0.8051282 0.2592593 0.1944444 0.7241379 0.6230366 0.8875000 0.7500000 0.7500000 0.2777778 0.7000000 0.7000000 0.9102564
bearish AAPL 4 1 gbm 0.8495575 0.7965201 0.2477876 0.2035398 0.7301587 0.6276410 0.8588235 0.8214286 0.8214286 0.3097345 0.6571429 0.6571429 0.9358974
bearish AAPL 4 5 gbm 0.8545455 0.8145032 0.2727273 0.2090909 0.7419355 0.6408163 0.8875000 0.7666667 0.7666667 0.2909091 0.7187500 0.7187500 0.9102564
bearish AAPL 4 10 gbm 0.8703704 0.8282051 0.2592593 0.2037037 0.7586207 0.6701571 0.9000000 0.7857143 0.7857143 0.2777778 0.7333333 0.7333333 0.9230769
bearish AAPL 4 15 gbm 0.8380952 0.7941595 0.2666667 0.1809524 0.6909091 0.5812808 0.8961039 0.6785714 0.6785714 0.2571429 0.7037037 0.7037037 0.8846154
bearish AAPL 4 20 gbm 0.8611111 0.8115385 0.2500000 0.1944444 0.7368421 0.6428571 0.8888889 0.7777778 0.7777778 0.2777778 0.7000000 0.7000000 0.9230769
bearish AAPL 4 1 gbm - top layer 0.8584071 0.8108059 0.2566372 0.2123894 0.7500000 0.6524414 0.8690476 0.8275862 0.8275862 0.3097345 0.6857143 0.6857143 0.9358974
bearish AAPL 4 5 gbm - top layer 0.8454545 0.7988782 0.2636364 0.2000000 0.7213115 0.6147507 0.8765432 0.7586207 0.7586207 0.2909091 0.6875000 0.6875000 0.9102564
bearish AAPL 4 10 gbm - top layer 0.8796296 0.8346154 0.2500000 0.2037037 0.7719298 0.6904762 0.9012346 0.8148148 0.8148148 0.2777778 0.7333333 0.7333333 0.9358974
bearish AAPL 4 15 gbm - top layer 0.8285714 0.7514245 0.2190476 0.1523810 0.6400000 0.5284431 0.8658537 0.6956522 0.6956522 0.2571429 0.5925926 0.5925926 0.9102564
bearish AAPL 4 20 gbm - top layer 0.8796296 0.8141026 0.2129630 0.1851852 0.7547170 0.6767956 0.8823529 0.8695652 0.8695652 0.2777778 0.6666667 0.6666667 0.9615385
bearish AAPL 4 1 glm 0.7079646 0.5915751 0.1592920 0.0884956 0.3773585 0.2114612 0.7368421 0.5555556 0.5555556 0.3097345 0.2857143 0.2857143 0.8974359
bearish AAPL 4 5 glm 0.7727273 0.6738782 0.1909091 0.1272727 0.5283019 0.3869817 0.7977528 0.6666667 0.6666667 0.2909091 0.4375000 0.4375000 0.9102564
bearish AAPL 4 10 glm 0.7314815 0.5987179 0.1574074 0.0833333 0.3829787 0.2278107 0.7692308 0.5294118 0.5294118 0.2777778 0.3000000 0.3000000 0.8974359
bearish AAPL 4 15 glm 0.7809524 0.6467236 0.1523810 0.0952381 0.4651163 0.3385374 0.8089888 0.6250000 0.6250000 0.2571429 0.3703704 0.3703704 0.9230769
bearish AAPL 4 20 glm 0.7500000 0.6628205 0.2314815 0.1296296 0.5090909 0.3432432 0.8072289 0.5600000 0.5600000 0.2777778 0.4666667 0.4666667 0.8589744
bearish AAPL 4 1 glm - top layer 0.8495575 0.8043956 0.2654867 0.2123894 0.7384615 0.6337464 0.8674699 0.8000000 0.8000000 0.3097345 0.6857143 0.6857143 0.9230769
bearish AAPL 4 5 glm - top layer 0.8454545 0.7988782 0.2636364 0.2000000 0.7213115 0.6147507 0.8765432 0.7586207 0.7586207 0.2909091 0.6875000 0.6875000 0.9102564
bearish AAPL 4 10 glm - top layer 0.8703704 0.8282051 0.2592593 0.2037037 0.7586207 0.6701571 0.9000000 0.7857143 0.7857143 0.2777778 0.7333333 0.7333333 0.9230769
bearish AAPL 4 15 glm - top layer 0.8380952 0.7820513 0.2476190 0.1714286 0.6792453 0.5710166 0.8860759 0.6923077 0.6923077 0.2571429 0.6666667 0.6666667 0.8974359
bearish AAPL 4 20 glm - top layer 0.8425926 0.7782051 0.2314815 0.1759259 0.6909091 0.5864865 0.8674699 0.7600000 0.7600000 0.2777778 0.6333333 0.6333333 0.9230769
bearish AAPL 4 1 nb 0.7079646 0.6152015 0.2123894 0.1150442 0.4406780 0.2522559 0.7528090 0.5416667 0.5416667 0.3097345 0.3714286 0.3714286 0.8589744
bearish AAPL 4 5 nb 0.7272727 0.6786859 0.3090909 0.1636364 0.5454545 0.3509048 0.8157895 0.5294118 0.5294118 0.2909091 0.5625000 0.5625000 0.7948718
bearish AAPL 4 10 nb 0.7314815 0.6089744 0.1759259 0.0925926 0.4081633 0.2456647 0.7752809 0.5263158 0.5263158 0.2777778 0.3333333 0.3333333 0.8846154
bearish AAPL 4 15 nb 0.7142857 0.6381766 0.2761905 0.1238095 0.4642857 0.2698192 0.8157895 0.4482759 0.4482759 0.2571429 0.4814815 0.4814815 0.7948718
bearish AAPL 4 20 nb 0.7962963 0.7564103 0.2962963 0.1851852 0.6451613 0.5025126 0.8684211 0.6250000 0.6250000 0.2777778 0.6666667 0.6666667 0.8461538
bearish AAPL 4 1 nb - top layer 0.8141593 0.7708791 0.2831858 0.2035398 0.6865672 0.5548678 0.8518519 0.7187500 0.7187500 0.3097345 0.6571429 0.6571429 0.8846154
bearish AAPL 4 5 nb - top layer 0.8454545 0.8173077 0.3000000 0.2181818 0.7384615 0.6288210 0.8961039 0.7272727 0.7272727 0.2909091 0.7500000 0.7500000 0.8846154
bearish AAPL 4 10 nb - top layer 0.8148148 0.7589744 0.2592593 0.1759259 0.6551724 0.5287958 0.8625000 0.6785714 0.6785714 0.2777778 0.6333333 0.6333333 0.8846154
bearish AAPL 4 15 nb - top layer 0.8190476 0.8055556 0.3238095 0.2000000 0.6885246 0.5633618 0.9154930 0.6176471 0.6176471 0.2571429 0.7777778 0.7777778 0.8333333
bearish AAPL 4 20 nb - top layer 0.8148148 0.7794872 0.2962963 0.1944444 0.6774194 0.5477387 0.8815789 0.6562500 0.6562500 0.2777778 0.7000000 0.7000000 0.8589744
bearish AAPL 5 1 final - averaging 0.8035714 0.7760181 0.3214286 0.2142857 0.6857143 0.5430267 0.8684211 0.6666667 0.6666667 0.3035714 0.7058824 0.7058824 0.8461538
bearish AAPL 5 5 final - averaging 0.8141593 0.7787546 0.3008850 0.2123894 0.6956522 0.5619347 0.8607595 0.7058824 0.7058824 0.3097345 0.6857143 0.6857143 0.8717949
bearish AAPL 5 10 final - averaging 0.8584071 0.8108059 0.2566372 0.2123894 0.7500000 0.6524414 0.8690476 0.8275862 0.8275862 0.3097345 0.6857143 0.6857143 0.9358974
bearish AAPL 5 15 final - averaging 0.8611111 0.8217949 0.2685185 0.2037037 0.7457627 0.6502591 0.8987342 0.7586207 0.7586207 0.2777778 0.7333333 0.7333333 0.9102564
bearish AAPL 5 20 final - averaging 0.8363636 0.8293269 0.3454545 0.2363636 0.7428571 0.6241458 0.9166667 0.6842105 0.6842105 0.2909091 0.8125000 0.8125000 0.8461538
bearish AAPL 5 1 gbm 0.8035714 0.7594268 0.2857143 0.1964286 0.6666667 0.5276074 0.8500000 0.6875000 0.6875000 0.3035714 0.6470588 0.6470588 0.8717949
bearish AAPL 5 5 gbm 0.7964602 0.7501832 0.2831858 0.1946903 0.6567164 0.5124742 0.8395062 0.6875000 0.6875000 0.3097345 0.6285714 0.6285714 0.8717949
bearish AAPL 5 10 gbm 0.8672566 0.8172161 0.2477876 0.2123894 0.7619048 0.6714480 0.8705882 0.8571429 0.8571429 0.3097345 0.6857143 0.6857143 0.9487179
bearish AAPL 5 15 gbm 0.8796296 0.8346154 0.2500000 0.2037037 0.7719298 0.6904762 0.9012346 0.8148148 0.8148148 0.2777778 0.7333333 0.7333333 0.9358974
bearish AAPL 5 20 gbm 0.8272727 0.8229167 0.3545455 0.2363636 0.7323944 0.6066993 0.9154930 0.6666667 0.6666667 0.2909091 0.8125000 0.8125000 0.8333333
bearish AAPL 5 1 gbm - top layer 0.7946429 0.7613122 0.3125000 0.2053571 0.6666667 0.5183246 0.8571429 0.6571429 0.6571429 0.3035714 0.6764706 0.6764706 0.8461538
bearish AAPL 5 5 gbm - top layer 0.8141593 0.7708791 0.2831858 0.2035398 0.6865672 0.5548678 0.8518519 0.7187500 0.7187500 0.3097345 0.6571429 0.6571429 0.8846154
bearish AAPL 5 10 gbm - top layer 0.8584071 0.7950549 0.2212389 0.1946903 0.7333333 0.6405567 0.8522727 0.8800000 0.8800000 0.3097345 0.6285714 0.6285714 0.9615385
bearish AAPL 5 15 gbm - top layer 0.8611111 0.8217949 0.2685185 0.2037037 0.7457627 0.6502591 0.8987342 0.7586207 0.7586207 0.2777778 0.7333333 0.7333333 0.9102564
bearish AAPL 5 20 gbm - top layer 0.8181818 0.8072917 0.3454545 0.2272727 0.7142857 0.5823842 0.9027778 0.6578947 0.6578947 0.2909091 0.7812500 0.7812500 0.8333333
bearish AAPL 5 1 glm 0.7232143 0.6602564 0.2767857 0.1517857 0.5230769 0.3286930 0.7901235 0.5483871 0.5483871 0.3035714 0.5000000 0.5000000 0.8205128
bearish AAPL 5 5 glm 0.7256637 0.6358974 0.2123894 0.1238938 0.4745763 0.2975737 0.7640449 0.5833333 0.5833333 0.3097345 0.4000000 0.4000000 0.8717949
bearish AAPL 5 10 glm 0.7345133 0.6265568 0.1681416 0.1061947 0.4444444 0.2896060 0.7553191 0.6315789 0.6315789 0.3097345 0.3428571 0.3428571 0.9102564
bearish AAPL 5 15 glm 0.8055556 0.7012821 0.1759259 0.1296296 0.5714286 0.4537572 0.8202247 0.7368421 0.7368421 0.2777778 0.4666667 0.4666667 0.9358974
bearish AAPL 5 20 glm 0.7636364 0.6766827 0.2181818 0.1363636 0.5357143 0.3814879 0.8023256 0.6250000 0.6250000 0.2909091 0.4687500 0.4687500 0.8846154
bearish AAPL 5 1 glm - top layer 0.8125000 0.7658371 0.2767857 0.1964286 0.6769231 0.5452436 0.8518519 0.7096774 0.7096774 0.3035714 0.6470588 0.6470588 0.8846154
bearish AAPL 5 5 glm - top layer 0.8053097 0.7644689 0.2920354 0.2035398 0.6764706 0.5374023 0.8500000 0.6969697 0.6969697 0.3097345 0.6571429 0.6571429 0.8717949
bearish AAPL 5 10 glm - top layer 0.8672566 0.8172161 0.2477876 0.2123894 0.7619048 0.6714480 0.8705882 0.8571429 0.8571429 0.3097345 0.6857143 0.6857143 0.9487179
bearish AAPL 5 15 glm - top layer 0.8796296 0.8243590 0.2314815 0.1944444 0.7636364 0.6837838 0.8915663 0.8400000 0.8400000 0.2777778 0.7000000 0.7000000 0.9487179
bearish AAPL 5 20 glm - top layer 0.8363636 0.8293269 0.3454545 0.2363636 0.7428571 0.6241458 0.9166667 0.6842105 0.6842105 0.2909091 0.8125000 0.8125000 0.8461538
bearish AAPL 5 1 nb 0.7053571 0.6723228 0.3482143 0.1785714 0.5479452 0.3309196 0.8082192 0.5128205 0.5128205 0.3035714 0.5882353 0.5882353 0.7564103
bearish AAPL 5 5 nb 0.7168142 0.6609890 0.2920354 0.1592920 0.5294118 0.3271306 0.7875000 0.5454545 0.5454545 0.3097345 0.5142857 0.5142857 0.8076923
bearish AAPL 5 10 nb 0.6991150 0.6324176 0.2743363 0.1415929 0.4848485 0.2734493 0.7682927 0.5161290 0.5161290 0.3097345 0.4571429 0.4571429 0.8076923
bearish AAPL 5 15 nb 0.7962963 0.7461538 0.2777778 0.1759259 0.6333333 0.4923077 0.8589744 0.6333333 0.6333333 0.2777778 0.6333333 0.6333333 0.8589744
bearish AAPL 5 20 nb 0.7181818 0.6538462 0.2818182 0.1454545 0.5079365 0.3105540 0.7974684 0.5161290 0.5161290 0.2909091 0.5000000 0.5000000 0.8076923
bearish AAPL 5 1 nb - top layer 0.7857143 0.7631976 0.3392857 0.2142857 0.6666667 0.5094891 0.8648649 0.6315789 0.6315789 0.3035714 0.7058824 0.7058824 0.8205128
bearish AAPL 5 5 nb - top layer 0.7610619 0.7324176 0.3362832 0.2035398 0.6301370 0.4541063 0.8400000 0.6052632 0.6052632 0.3097345 0.6571429 0.6571429 0.8076923
bearish AAPL 5 10 nb - top layer 0.8141593 0.7551282 0.2477876 0.1858407 0.6666667 0.5400271 0.8352941 0.7500000 0.7500000 0.3097345 0.6000000 0.6000000 0.9102564
bearish AAPL 5 15 nb - top layer 0.8518519 0.8051282 0.2592593 0.1944444 0.7241379 0.6230366 0.8875000 0.7500000 0.7500000 0.2777778 0.7000000 0.7000000 0.9102564
bearish AAPL 5 20 nb - top layer 0.8272727 0.8137019 0.3363636 0.2272727 0.7246377 0.5997702 0.9041096 0.6756757 0.6756757 0.2909091 0.7812500 0.7812500 0.8461538
bullish AAPL 1 1 final - averaging 0.8240741 0.7653846 0.2500000 0.1759259 0.6666667 0.5476190 0.8641975 0.7037037 0.7037037 0.2777778 0.6333333 0.6333333 0.8974359
bullish AAPL 1 5 final - averaging 0.8518519 0.7743590 0.2037037 0.1666667 0.6923077 0.5977654 0.8604651 0.8181818 0.8181818 0.2777778 0.6000000 0.6000000 0.9487179
bullish AAPL 1 10 final - averaging 0.8018018 0.7628205 0.2972973 0.1981982 0.6666667 0.5256410 0.8589744 0.6666667 0.6666667 0.2972973 0.6666667 0.6666667 0.8589744
bullish AAPL 1 15 final - averaging 0.8198198 0.8106061 0.3513514 0.2342342 0.7222222 0.5902547 0.9027778 0.6666667 0.6666667 0.2972973 0.7878788 0.7878788 0.8333333
bullish AAPL 1 20 final - averaging 0.8545455 0.8052885 0.2545455 0.2000000 0.7333333 0.6339434 0.8780488 0.7857143 0.7857143 0.2909091 0.6875000 0.6875000 0.9230769
bullish AAPL 1 1 gbm 0.8240741 0.7653846 0.2500000 0.1759259 0.6666667 0.5476190 0.8641975 0.7037037 0.7037037 0.2777778 0.6333333 0.6333333 0.8974359
bullish AAPL 1 5 gbm 0.8611111 0.7910256 0.2129630 0.1759259 0.7169811 0.6270718 0.8705882 0.8260870 0.8260870 0.2777778 0.6333333 0.6333333 0.9487179
bullish AAPL 1 10 gbm 0.8108108 0.7692308 0.2882883 0.1981982 0.6769231 0.5432099 0.8607595 0.6875000 0.6875000 0.2972973 0.6666667 0.6666667 0.8717949
bullish AAPL 1 15 gbm 0.8378378 0.8234266 0.3333333 0.2342342 0.7428571 0.6250000 0.9054054 0.7027027 0.7027027 0.2972973 0.7878788 0.7878788 0.8589744
bullish AAPL 1 20 gbm 0.8545455 0.8145032 0.2727273 0.2090909 0.7419355 0.6408163 0.8875000 0.7666667 0.7666667 0.2909091 0.7187500 0.7187500 0.9102564
bullish AAPL 1 1 gbm - top layer 0.8333333 0.7615385 0.2222222 0.1666667 0.6666667 0.5573770 0.8571429 0.7500000 0.7500000 0.2777778 0.6000000 0.6000000 0.9230769
bullish AAPL 1 5 gbm - top layer 0.8333333 0.7410256 0.1851852 0.1481481 0.6400000 0.5371429 0.8409091 0.8000000 0.8000000 0.2777778 0.5333333 0.5333333 0.9487179
bullish AAPL 1 10 gbm - top layer 0.8198198 0.7668998 0.2612613 0.1891892 0.6774194 0.5531401 0.8536585 0.7241379 0.7241379 0.2972973 0.6363636 0.6363636 0.8974359
bullish AAPL 1 15 gbm - top layer 0.8198198 0.7843823 0.2972973 0.2072072 0.6969697 0.5687646 0.8717949 0.6969697 0.6969697 0.2972973 0.6969697 0.6969697 0.8717949
bullish AAPL 1 20 gbm - top layer 0.8818182 0.8337340 0.2454545 0.2090909 0.7796610 0.6997060 0.8915663 0.8518519 0.8518519 0.2909091 0.7187500 0.7187500 0.9487179
bullish AAPL 1 1 glm 0.7685185 0.6346154 0.1388889 0.0925926 0.4444444 0.3181818 0.7849462 0.6666667 0.6666667 0.2777778 0.3333333 0.3333333 0.9358974
bullish AAPL 1 5 glm 0.7314815 0.5987179 0.1574074 0.0833333 0.3829787 0.2278107 0.7692308 0.5294118 0.5294118 0.2777778 0.3000000 0.3000000 0.8974359
bullish AAPL 1 10 glm 0.7297297 0.6416084 0.2252252 0.1261261 0.4827586 0.3045113 0.7790698 0.5600000 0.5600000 0.2972973 0.4242424 0.4242424 0.8589744
bullish AAPL 1 15 glm 0.7027027 0.6136364 0.2342342 0.1171171 0.4406780 0.2420857 0.7647059 0.5000000 0.5000000 0.2972973 0.3939394 0.3939394 0.8333333
bullish AAPL 1 20 glm 0.7545455 0.6149840 0.1181818 0.0818182 0.4000000 0.2787761 0.7628866 0.6923077 0.6923077 0.2909091 0.2812500 0.2812500 0.9487179
bullish AAPL 1 1 glm - top layer 0.8333333 0.7717949 0.2407407 0.1759259 0.6785714 0.5668449 0.8658537 0.7307692 0.7307692 0.2777778 0.6333333 0.6333333 0.9102564
bullish AAPL 1 5 glm - top layer 0.8518519 0.7743590 0.2037037 0.1666667 0.6923077 0.5977654 0.8604651 0.8181818 0.8181818 0.2777778 0.6000000 0.6000000 0.9487179
bullish AAPL 1 10 glm - top layer 0.8108108 0.7692308 0.2882883 0.1981982 0.6769231 0.5432099 0.8607595 0.6875000 0.6875000 0.2972973 0.6666667 0.6666667 0.8717949
bullish AAPL 1 15 glm - top layer 0.8378378 0.8146853 0.3153153 0.2252252 0.7352941 0.6185567 0.8947368 0.7142857 0.7142857 0.2972973 0.7575758 0.7575758 0.8717949
bullish AAPL 1 20 glm - top layer 0.8545455 0.8052885 0.2545455 0.2000000 0.7333333 0.6339434 0.8780488 0.7857143 0.7857143 0.2909091 0.6875000 0.6875000 0.9230769
bullish AAPL 1 1 nb 0.7222222 0.6641026 0.2962963 0.1481481 0.5161290 0.3216080 0.8157895 0.5000000 0.5000000 0.2777778 0.5333333 0.5333333 0.7948718
bullish AAPL 1 5 nb 0.7314815 0.6910256 0.3240741 0.1666667 0.5538462 0.3634146 0.8356164 0.5142857 0.5142857 0.2777778 0.6000000 0.6000000 0.7820513
bullish AAPL 1 10 nb 0.6936937 0.6509324 0.3333333 0.1621622 0.5142857 0.2916667 0.7972973 0.4864865 0.4864865 0.2972973 0.5454545 0.5454545 0.7564103
bullish AAPL 1 15 nb 0.6936937 0.6684149 0.3693694 0.1801802 0.5405405 0.3148148 0.8142857 0.4878049 0.4878049 0.2972973 0.6060606 0.6060606 0.7307692
bullish AAPL 1 20 nb 0.6909091 0.6622596 0.3636364 0.1727273 0.5277778 0.3022388 0.8142857 0.4750000 0.4750000 0.2909091 0.5937500 0.5937500 0.7307692
bullish AAPL 1 1 nb - top layer 0.8055556 0.7628205 0.2870370 0.1851852 0.6557377 0.5203046 0.8701299 0.6451613 0.6451613 0.2777778 0.6666667 0.6666667 0.8589744
bullish AAPL 1 5 nb - top layer 0.8055556 0.7423077 0.2500000 0.1666667 0.6315789 0.5000000 0.8518519 0.6666667 0.6666667 0.2777778 0.6000000 0.6000000 0.8846154
bullish AAPL 1 10 nb - top layer 0.7297297 0.6940559 0.3333333 0.1801802 0.5714286 0.3750000 0.8243243 0.5405405 0.5405405 0.2972973 0.6060606 0.6060606 0.7820513
bullish AAPL 1 15 nb - top layer 0.7747748 0.7610723 0.3603604 0.2162162 0.6575342 0.4920373 0.8732394 0.6000000 0.6000000 0.2972973 0.7272727 0.7272727 0.7948718
bullish AAPL 1 20 nb - top layer 0.8454545 0.8080929 0.2818182 0.2090909 0.7301587 0.6219167 0.8860759 0.7419355 0.7419355 0.2909091 0.7187500 0.7187500 0.8974359
bullish AAPL 2 1 final - averaging 0.8148148 0.7487179 0.2407407 0.1666667 0.6428571 0.5187166 0.8536585 0.6923077 0.6923077 0.2777778 0.6000000 0.6000000 0.8974359
bullish AAPL 2 5 final - averaging 0.7927928 0.7476690 0.2882883 0.1891892 0.6461538 0.4997061 0.8481013 0.6562500 0.6562500 0.2972973 0.6363636 0.6363636 0.8589744
bullish AAPL 2 10 final - averaging 0.8348624 0.7582713 0.2110092 0.1651376 0.6666667 0.5600897 0.8488372 0.7826087 0.7826087 0.2844037 0.5806452 0.5806452 0.9358974
bullish AAPL 2 15 final - averaging 0.8090909 0.7455929 0.2454545 0.1727273 0.6440678 0.5149097 0.8433735 0.7037037 0.7037037 0.2909091 0.5937500 0.5937500 0.8974359
bullish AAPL 2 20 final - averaging 0.8148148 0.7589744 0.2592593 0.1759259 0.6551724 0.5287958 0.8625000 0.6785714 0.6785714 0.2777778 0.6333333 0.6333333 0.8846154
bullish AAPL 2 1 gbm 0.7870370 0.7294872 0.2685185 0.1666667 0.6101695 0.4637306 0.8481013 0.6206897 0.6206897 0.2777778 0.6000000 0.6000000 0.8589744
bullish AAPL 2 5 gbm 0.7927928 0.7389277 0.2702703 0.1801802 0.6349206 0.4907241 0.8395062 0.6666667 0.6666667 0.2972973 0.6060606 0.6060606 0.8717949
bullish AAPL 2 10 gbm 0.8073394 0.7390405 0.2385321 0.1651376 0.6315789 0.5024995 0.8433735 0.6923077 0.6923077 0.2844037 0.5806452 0.5806452 0.8974359
bullish AAPL 2 15 gbm 0.8000000 0.7299679 0.2363636 0.1636364 0.6206897 0.4868533 0.8333333 0.6923077 0.6923077 0.2909091 0.5625000 0.5625000 0.8974359
bullish AAPL 2 20 gbm 0.8148148 0.7692308 0.2777778 0.1851852 0.6666667 0.5384615 0.8717949 0.6666667 0.6666667 0.2777778 0.6666667 0.6666667 0.8717949
bullish AAPL 2 1 gbm - top layer 0.7870370 0.6987179 0.2129630 0.1388889 0.5660377 0.4281768 0.8235294 0.6521739 0.6521739 0.2777778 0.5000000 0.5000000 0.8974359
bullish AAPL 2 5 gbm - top layer 0.8198198 0.7668998 0.2612613 0.1891892 0.6774194 0.5531401 0.8536585 0.7241379 0.7241379 0.2972973 0.6363636 0.6363636 0.8974359
bullish AAPL 2 10 gbm - top layer 0.8256881 0.7421423 0.2018349 0.1559633 0.6415094 0.5307047 0.8390805 0.7727273 0.7727273 0.2844037 0.5483871 0.5483871 0.9358974
bullish AAPL 2 15 gbm - top layer 0.8000000 0.7299679 0.2363636 0.1636364 0.6206897 0.4868533 0.8333333 0.6923077 0.6923077 0.2909091 0.5625000 0.5625000 0.8974359
bullish AAPL 2 20 gbm - top layer 0.8240741 0.7756410 0.2685185 0.1851852 0.6779661 0.5569948 0.8734177 0.6896552 0.6896552 0.2777778 0.6666667 0.6666667 0.8846154
bullish AAPL 2 1 glm 0.7314815 0.5884615 0.1388889 0.0740741 0.3555556 0.2090909 0.7634409 0.5333333 0.5333333 0.2777778 0.2666667 0.2666667 0.9102564
bullish AAPL 2 5 glm 0.7117117 0.6113054 0.2072072 0.1081081 0.4285714 0.2439336 0.7613636 0.5217391 0.5217391 0.2972973 0.3636364 0.3636364 0.8589744
bullish AAPL 2 10 glm 0.7339450 0.5905707 0.1284404 0.0733945 0.3555556 0.2169928 0.7578947 0.5714286 0.5714286 0.2844037 0.2580645 0.2580645 0.9230769
bullish AAPL 2 15 glm 0.7181818 0.5801282 0.1363636 0.0727273 0.3404255 0.1900238 0.7473684 0.5333333 0.5333333 0.2909091 0.2500000 0.2500000 0.9102564
bullish AAPL 2 20 glm 0.7222222 0.6025641 0.1851852 0.0925926 0.4000000 0.2285714 0.7727273 0.5000000 0.5000000 0.2777778 0.3333333 0.3333333 0.8717949
bullish AAPL 2 1 glm - top layer 0.8055556 0.7423077 0.2500000 0.1666667 0.6315789 0.5000000 0.8518519 0.6666667 0.6666667 0.2777778 0.6000000 0.6000000 0.8846154
bullish AAPL 2 5 glm - top layer 0.7927928 0.7301865 0.2522523 0.1711712 0.6229508 0.4814138 0.8313253 0.6785714 0.6785714 0.2972973 0.5757576 0.5757576 0.8846154
bullish AAPL 2 10 glm - top layer 0.8256881 0.7421423 0.2018349 0.1559633 0.6415094 0.5307047 0.8390805 0.7727273 0.7727273 0.2844037 0.5483871 0.5483871 0.9358974
bullish AAPL 2 15 glm - top layer 0.8090909 0.7455929 0.2454545 0.1727273 0.6440678 0.5149097 0.8433735 0.7037037 0.7037037 0.2909091 0.5937500 0.5937500 0.8974359
bullish AAPL 2 20 glm - top layer 0.8240741 0.7756410 0.2685185 0.1851852 0.6779661 0.5569948 0.8734177 0.6896552 0.6896552 0.2777778 0.6666667 0.6666667 0.8846154
bullish AAPL 2 1 nb 0.7037037 0.6205128 0.2592593 0.1203704 0.4482759 0.2460733 0.7875000 0.4642857 0.4642857 0.2777778 0.4333333 0.4333333 0.8076923
bullish AAPL 2 5 nb 0.6486486 0.6276224 0.3963964 0.1711712 0.4935065 0.2328549 0.7910448 0.4318182 0.4318182 0.2972973 0.5757576 0.5757576 0.6794872
bullish AAPL 2 10 nb 0.6513761 0.5814723 0.3027523 0.1192661 0.4062500 0.1598377 0.7631579 0.3939394 0.3939394 0.2844037 0.4193548 0.4193548 0.7435897
bullish AAPL 2 15 nb 0.6727273 0.5665064 0.2181818 0.0909091 0.3571429 0.1435986 0.7441860 0.4166667 0.4166667 0.2909091 0.3125000 0.3125000 0.8205128
bullish AAPL 2 20 nb 0.6944444 0.6858974 0.3981481 0.1851852 0.5479452 0.3280543 0.8461538 0.4651163 0.4651163 0.2777778 0.6666667 0.6666667 0.7051282
bullish AAPL 2 1 nb - top layer 0.7962963 0.7564103 0.2962963 0.1851852 0.6451613 0.5025126 0.8684211 0.6250000 0.6250000 0.2777778 0.6666667 0.6666667 0.8461538
bullish AAPL 2 5 nb - top layer 0.7387387 0.7092075 0.3423423 0.1891892 0.5915493 0.4008934 0.8356164 0.5526316 0.5526316 0.2972973 0.6363636 0.6363636 0.7820513
bullish AAPL 2 10 nb - top layer 0.7981651 0.7423490 0.2660550 0.1743119 0.6333333 0.4943062 0.8500000 0.6551724 0.6551724 0.2844037 0.6129032 0.6129032 0.8717949
bullish AAPL 2 15 nb - top layer 0.7636364 0.6951122 0.2545455 0.1545455 0.5666667 0.4051581 0.8170732 0.6071429 0.6071429 0.2909091 0.5312500 0.5312500 0.8589744
bullish AAPL 2 20 nb - top layer 0.8333333 0.7923077 0.2777778 0.1944444 0.7000000 0.5846154 0.8846154 0.7000000 0.7000000 0.2777778 0.7000000 0.7000000 0.8846154
bullish AAPL 3 1 final - averaging 0.8018018 0.7453380 0.2612613 0.1801802 0.6451613 0.5084541 0.8414634 0.6896552 0.6896552 0.2972973 0.6060606 0.6060606 0.8846154
bullish AAPL 3 5 final - averaging 0.7657658 0.6672494 0.1891892 0.1261261 0.5185185 0.3736979 0.7888889 0.6666667 0.6666667 0.2972973 0.4242424 0.4242424 0.9102564
bullish AAPL 3 10 final - averaging 0.7272727 0.6418269 0.2363636 0.1272727 0.4827586 0.3002545 0.7857143 0.5384615 0.5384615 0.2909091 0.4375000 0.4375000 0.8461538
bullish AAPL 3 15 final - averaging 0.7747748 0.6736597 0.1801802 0.1261261 0.5283019 0.3918475 0.7912088 0.7000000 0.7000000 0.2972973 0.4242424 0.4242424 0.9230769
bullish AAPL 3 20 final - averaging 0.7719298 0.7136752 0.2631579 0.1754386 0.6060606 0.4474273 0.8095238 0.6666667 0.6666667 0.3157895 0.5555556 0.5555556 0.8717949
bullish AAPL 3 1 gbm 0.8108108 0.7604895 0.2702703 0.1891892 0.6666667 0.5350090 0.8518519 0.7000000 0.7000000 0.2972973 0.6363636 0.6363636 0.8846154
bullish AAPL 3 5 gbm 0.7387387 0.6829837 0.2882883 0.1621622 0.5538462 0.3691946 0.8101266 0.5625000 0.5625000 0.2972973 0.5454545 0.5454545 0.8205128
bullish AAPL 3 10 gbm 0.7545455 0.6702724 0.2272727 0.1363636 0.5263158 0.3640257 0.8000000 0.6000000 0.6000000 0.2909091 0.4687500 0.4687500 0.8717949
bullish AAPL 3 15 gbm 0.7927928 0.7039627 0.1981982 0.1441441 0.5818182 0.4513217 0.8089888 0.7272727 0.7272727 0.2972973 0.4848485 0.4848485 0.9230769
bullish AAPL 3 20 gbm 0.7807018 0.7200855 0.2543860 0.1754386 0.6153846 0.4644870 0.8117647 0.6896552 0.6896552 0.3157895 0.5555556 0.5555556 0.8846154
bullish AAPL 3 1 gbm - top layer 0.8378378 0.7709790 0.2252252 0.1801802 0.6896552 0.5827068 0.8488372 0.8000000 0.8000000 0.2972973 0.6060606 0.6060606 0.9358974
bullish AAPL 3 5 gbm - top layer 0.7837838 0.6713287 0.1531532 0.1171171 0.5200000 0.3983740 0.7872340 0.7647059 0.7647059 0.2972973 0.3939394 0.3939394 0.9487179
bullish AAPL 3 10 gbm - top layer 0.7090909 0.6197917 0.2363636 0.1181818 0.4482759 0.2536047 0.7738095 0.5000000 0.5000000 0.2909091 0.4062500 0.4062500 0.8333333
bullish AAPL 3 15 gbm - top layer 0.8108108 0.6993007 0.1441441 0.1261261 0.5714286 0.4681725 0.8000000 0.8750000 0.8750000 0.2972973 0.4242424 0.4242424 0.9743590
bullish AAPL 3 20 gbm - top layer 0.7894737 0.7264957 0.2456140 0.1754386 0.6250000 0.4818182 0.8139535 0.7142857 0.7142857 0.3157895 0.5555556 0.5555556 0.8974359
bullish AAPL 3 1 glm 0.7297297 0.5804196 0.0990991 0.0630631 0.3181818 0.1991342 0.7400000 0.6363636 0.6363636 0.2972973 0.2121212 0.2121212 0.9487179
bullish AAPL 3 5 glm 0.7027027 0.5699301 0.1441441 0.0720721 0.3265306 0.1642710 0.7368421 0.5000000 0.5000000 0.2972973 0.2424242 0.2424242 0.8974359
bullish AAPL 3 10 glm 0.6454545 0.5012019 0.1545455 0.0454545 0.2040816 0.0027894 0.7096774 0.2941176 0.2941176 0.2909091 0.1562500 0.1562500 0.8461538
bullish AAPL 3 15 glm 0.6756757 0.5769231 0.2252252 0.0990991 0.3793103 0.1654135 0.7441860 0.4400000 0.4400000 0.2972973 0.3333333 0.3333333 0.8205128
bullish AAPL 3 20 glm 0.7192982 0.5929487 0.1228070 0.0789474 0.3600000 0.2225064 0.7300000 0.6428571 0.6428571 0.3157895 0.2500000 0.2500000 0.9358974
bullish AAPL 3 1 glm - top layer 0.8288288 0.7733100 0.2522523 0.1891892 0.6885246 0.5716027 0.8554217 0.7500000 0.7500000 0.2972973 0.6363636 0.6363636 0.9102564
bullish AAPL 3 5 glm - top layer 0.7387387 0.6655012 0.2522523 0.1441441 0.5245902 0.3461304 0.7951807 0.5714286 0.5714286 0.2972973 0.4848485 0.4848485 0.8461538
bullish AAPL 3 10 glm - top layer 0.7545455 0.6702724 0.2272727 0.1363636 0.5263158 0.3640257 0.8000000 0.6000000 0.6000000 0.2909091 0.4687500 0.4687500 0.8717949
bullish AAPL 3 15 glm - top layer 0.8108108 0.7167832 0.1801802 0.1441441 0.6037736 0.4891519 0.8131868 0.8000000 0.8000000 0.2972973 0.4848485 0.4848485 0.9487179
bullish AAPL 3 20 glm - top layer 0.7982456 0.7403846 0.2543860 0.1842105 0.6461538 0.5073281 0.8235294 0.7241379 0.7241379 0.3157895 0.5833333 0.5833333 0.8974359
bullish AAPL 3 1 nb 0.7027027 0.5961538 0.1981982 0.0990991 0.4000000 0.2127660 0.7528090 0.5000000 0.5000000 0.2972973 0.3333333 0.3333333 0.8589744
bullish AAPL 3 5 nb 0.7027027 0.6223776 0.2522523 0.1261261 0.4590164 0.2559415 0.7710843 0.5000000 0.5000000 0.2972973 0.4242424 0.4242424 0.8205128
bullish AAPL 3 10 nb 0.6454545 0.5933494 0.3363636 0.1363636 0.4347826 0.1784757 0.7671233 0.4054054 0.4054054 0.2909091 0.4687500 0.4687500 0.7179487
bullish AAPL 3 15 nb 0.6666667 0.5879953 0.2702703 0.1171171 0.4126984 0.1807301 0.7530864 0.4333333 0.4333333 0.2972973 0.3939394 0.3939394 0.7820513
bullish AAPL 3 20 nb 0.6403509 0.5876068 0.3245614 0.1403509 0.4383562 0.1739130 0.7402597 0.4324324 0.4324324 0.3157895 0.4444444 0.4444444 0.7307692
bullish AAPL 3 1 nb - top layer 0.7657658 0.7022145 0.2612613 0.1621622 0.5806452 0.4190821 0.8170732 0.6206897 0.6206897 0.2972973 0.5454545 0.5454545 0.8589744
bullish AAPL 3 5 nb - top layer 0.7387387 0.6742424 0.2702703 0.1531532 0.5396825 0.3578695 0.8024691 0.5666667 0.5666667 0.2972973 0.5151515 0.5151515 0.8333333
bullish AAPL 3 10 nb - top layer 0.6909091 0.6069712 0.2545455 0.1181818 0.4333333 0.2221298 0.7682927 0.4642857 0.4642857 0.2909091 0.4062500 0.4062500 0.8076923
bullish AAPL 3 15 nb - top layer 0.7477477 0.6544289 0.2072072 0.1261261 0.5000000 0.3384419 0.7840909 0.6086957 0.6086957 0.2972973 0.4242424 0.4242424 0.8846154
bullish AAPL 3 20 nb - top layer 0.7631579 0.7147436 0.2894737 0.1842105 0.6086957 0.4393443 0.8148148 0.6363636 0.6363636 0.3157895 0.5833333 0.5833333 0.8461538
bullish AAPL 4 1 final - averaging 0.8378378 0.8117089 0.3063063 0.2162162 0.7272727 0.6120388 0.8961039 0.7058824 0.7058824 0.2882883 0.7500000 0.7500000 0.8734177
bullish AAPL 4 5 final - averaging 0.8055556 0.7579660 0.2777778 0.1759259 0.6440678 0.5103627 0.8717949 0.6333333 0.6333333 0.2685185 0.6551724 0.6551724 0.8607595
bullish AAPL 4 10 final - averaging 0.8301887 0.8373183 0.3490566 0.2169811 0.7187500 0.6013372 0.9420290 0.6216216 0.6216216 0.2547170 0.8518519 0.8518519 0.8227848
bullish AAPL 4 15 final - averaging 0.8198198 0.7432753 0.2162162 0.1621622 0.6428571 0.5256410 0.8390805 0.7500000 0.7500000 0.2882883 0.5625000 0.5625000 0.9240506
bullish AAPL 4 20 final - averaging 0.7962963 0.7298123 0.2500000 0.1574074 0.6071429 0.4698795 0.8518519 0.6296296 0.6296296 0.2685185 0.5862069 0.5862069 0.8734177
bullish AAPL 4 1 gbm 0.8378378 0.8024130 0.2882883 0.2072072 0.7187500 0.6048259 0.8860759 0.7187500 0.7187500 0.2882883 0.7187500 0.7187500 0.8860759
bullish AAPL 4 5 gbm 0.8148148 0.7642951 0.2685185 0.1759259 0.6551724 0.5285901 0.8734177 0.6551724 0.6551724 0.2685185 0.6551724 0.6551724 0.8734177
bullish AAPL 4 10 gbm 0.8490566 0.8377872 0.3113208 0.2075472 0.7333333 0.6295325 0.9315068 0.6666667 0.6666667 0.2547170 0.8148148 0.8148148 0.8607595
bullish AAPL 4 15 gbm 0.8198198 0.7525712 0.2342342 0.1711712 0.6551724 0.5349811 0.8470588 0.7307692 0.7307692 0.2882883 0.5937500 0.5937500 0.9113924
bullish AAPL 4 20 gbm 0.8148148 0.7533828 0.2500000 0.1666667 0.6428571 0.5180723 0.8641975 0.6666667 0.6666667 0.2685185 0.6206897 0.6206897 0.8860759
bullish AAPL 4 1 gbm - top layer 0.8198198 0.7897547 0.3063063 0.2072072 0.6969697 0.5689320 0.8831169 0.6764706 0.6764706 0.2882883 0.7187500 0.7187500 0.8607595
bullish AAPL 4 5 gbm - top layer 0.8055556 0.7579660 0.2777778 0.1759259 0.6440678 0.5103627 0.8717949 0.6333333 0.6333333 0.2685185 0.6551724 0.6551724 0.8607595
bullish AAPL 4 10 gbm - top layer 0.7924528 0.7754337 0.3301887 0.1886792 0.6451613 0.5019223 0.9014085 0.5714286 0.5714286 0.2547170 0.7407407 0.7407407 0.8101266
bullish AAPL 4 15 gbm - top layer 0.8018018 0.7213212 0.2162162 0.1531532 0.6071429 0.4782051 0.8275862 0.7083333 0.7083333 0.2882883 0.5312500 0.5312500 0.9113924
bullish AAPL 4 20 gbm - top layer 0.8611111 0.8068529 0.2407407 0.1851852 0.7272727 0.6344765 0.8902439 0.7692308 0.7692308 0.2685185 0.6896552 0.6896552 0.9240506
bullish AAPL 4 1 glm 0.7027027 0.5122627 0.0450450 0.0180180 0.1081081 0.0327436 0.7169811 0.4000000 0.4000000 0.2882883 0.0625000 0.0625000 0.9620253
bullish AAPL 4 5 glm 0.7500000 0.5781318 0.0925926 0.0555556 0.3076923 0.1971366 0.7653061 0.6000000 0.6000000 0.2685185 0.2068966 0.2068966 0.9493671
bullish AAPL 4 10 glm 0.6886792 0.4864041 0.0943396 0.0188679 0.1081081 -0.0342992 0.7395833 0.2000000 0.2000000 0.2547170 0.0740741 0.0740741 0.8987342
bullish AAPL 4 15 glm 0.6756757 0.5025712 0.0900901 0.0270270 0.1428571 0.0064644 0.7128713 0.3000000 0.3000000 0.2882883 0.0937500 0.0937500 0.9113924
bullish AAPL 4 20 glm 0.6666667 0.5102575 0.1574074 0.0462963 0.2173913 0.0236062 0.7362637 0.2941176 0.2941176 0.2685185 0.1724138 0.1724138 0.8481013
bullish AAPL 4 1 glm - top layer 0.8288288 0.7867880 0.2792793 0.1981982 0.6984127 0.5789579 0.8750000 0.7096774 0.7096774 0.2882883 0.6875000 0.6875000 0.8860759
bullish AAPL 4 5 glm - top layer 0.7962963 0.7407246 0.2685185 0.1666667 0.6206897 0.4814491 0.8607595 0.6206897 0.6206897 0.2685185 0.6206897 0.6206897 0.8607595
bullish AAPL 4 10 glm - top layer 0.8679245 0.8626348 0.3113208 0.2169811 0.7666667 0.6758410 0.9452055 0.6969697 0.6969697 0.2547170 0.8518519 0.8518519 0.8734177
bullish AAPL 4 15 glm - top layer 0.8108108 0.7369462 0.2252252 0.1621622 0.6315789 0.5068754 0.8372093 0.7200000 0.7200000 0.2882883 0.5625000 0.5625000 0.9113924
bullish AAPL 4 20 glm - top layer 0.7962963 0.7189000 0.2314815 0.1481481 0.5925926 0.4577818 0.8433735 0.6400000 0.6400000 0.2685185 0.5517241 0.5517241 0.8860759
bullish AAPL 4 1 nb 0.6936937 0.6174842 0.2702703 0.1261261 0.4516129 0.2394196 0.7777778 0.4666667 0.4666667 0.2882883 0.4375000 0.4375000 0.7974684
bullish AAPL 4 5 nb 0.7407407 0.6263640 0.1944444 0.1018519 0.4400000 0.2769010 0.7931034 0.5238095 0.5238095 0.2685185 0.3793103 0.3793103 0.8734177
bullish AAPL 4 10 nb 0.6320755 0.6190811 0.4150943 0.1509434 0.4507042 0.1972816 0.8225806 0.3636364 0.3636364 0.2547170 0.5925926 0.5925926 0.6455696
bullish AAPL 4 15 nb 0.7027027 0.6331092 0.2792793 0.1351351 0.4761905 0.2687163 0.7875000 0.4838710 0.4838710 0.2882883 0.4687500 0.4687500 0.7974684
bullish AAPL 4 20 nb 0.6296296 0.5940637 0.3796296 0.1388889 0.4285714 0.1663450 0.7910448 0.3658537 0.3658537 0.2685185 0.5172414 0.5172414 0.6708861
bullish AAPL 4 1 nb - top layer 0.8018018 0.7585047 0.2882883 0.1891892 0.6562500 0.5170095 0.8607595 0.6562500 0.6562500 0.2882883 0.6562500 0.6562500 0.8607595
bullish AAPL 4 5 nb - top layer 0.7962963 0.7516368 0.2870370 0.1759259 0.6333333 0.4925246 0.8701299 0.6129032 0.6129032 0.2685185 0.6551724 0.6551724 0.8481013
bullish AAPL 4 10 nb - top layer 0.7924528 0.7876231 0.3490566 0.1981132 0.6562500 0.5127455 0.9130435 0.5675676 0.5675676 0.2547170 0.7777778 0.7777778 0.7974684
bullish AAPL 4 15 nb - top layer 0.7657658 0.7053006 0.2702703 0.1621622 0.5806452 0.4183797 0.8271605 0.6000000 0.6000000 0.2882883 0.5625000 0.5625000 0.8481013
bullish AAPL 4 20 nb - top layer 0.7314815 0.6855085 0.3148148 0.1574074 0.5396825 0.3518212 0.8378378 0.5000000 0.5000000 0.2685185 0.5862069 0.5862069 0.7848101
bullish AAPL 5 1 final - averaging 0.7894737 0.7115385 0.2105263 0.1578947 0.6000000 0.4647887 0.8000000 0.7500000 0.7500000 0.3157895 0.5000000 0.5000000 0.9230769
bullish AAPL 5 5 final - averaging 0.8157895 0.7756410 0.2894737 0.2105263 0.6956522 0.5639344 0.8518519 0.7272727 0.7272727 0.3157895 0.6666667 0.6666667 0.8846154
bullish AAPL 5 10 final - averaging 0.8611111 0.7910256 0.2129630 0.1759259 0.7169811 0.6270718 0.8705882 0.8260870 0.8260870 0.2777778 0.6333333 0.6333333 0.9487179
bullish AAPL 5 15 final - averaging 0.7410714 0.6564857 0.2232143 0.1339286 0.5084746 0.3382233 0.7816092 0.6000000 0.6000000 0.3035714 0.4411765 0.4411765 0.8717949
bullish AAPL 5 20 final - averaging 0.8518519 0.7948718 0.2407407 0.1851852 0.7142857 0.6149733 0.8780488 0.7692308 0.7692308 0.2777778 0.6666667 0.6666667 0.9230769
bullish AAPL 5 1 gbm 0.7807018 0.7126068 0.2368421 0.1666667 0.6031746 0.4558992 0.8045977 0.7037037 0.7037037 0.3157895 0.5277778 0.5277778 0.8974359
bullish AAPL 5 5 gbm 0.8333333 0.7884615 0.2719298 0.2105263 0.7164179 0.5993341 0.8554217 0.7741935 0.7741935 0.3157895 0.6666667 0.6666667 0.9102564
bullish AAPL 5 10 gbm 0.8703704 0.8076923 0.2222222 0.1851852 0.7407407 0.6557377 0.8809524 0.8333333 0.8333333 0.2777778 0.6666667 0.6666667 0.9487179
bullish AAPL 5 15 gbm 0.7678571 0.6840121 0.2142857 0.1428571 0.5517241 0.4013158 0.7954545 0.6666667 0.6666667 0.3035714 0.4705882 0.4705882 0.8974359
bullish AAPL 5 20 gbm 0.8518519 0.7948718 0.2407407 0.1851852 0.7142857 0.6149733 0.8780488 0.7692308 0.7692308 0.2777778 0.6666667 0.6666667 0.9230769
bullish AAPL 5 1 gbm - top layer 0.8245614 0.7521368 0.2105263 0.1754386 0.6666667 0.5539906 0.8222222 0.8333333 0.8333333 0.3157895 0.5555556 0.5555556 0.9487179
bullish AAPL 5 5 gbm - top layer 0.8421053 0.8173077 0.3157895 0.2368421 0.7500000 0.6346154 0.8846154 0.7500000 0.7500000 0.3157895 0.7500000 0.7500000 0.8846154
bullish AAPL 5 10 gbm - top layer 0.8425926 0.7474359 0.1759259 0.1481481 0.6530612 0.5578035 0.8426966 0.8421053 0.8421053 0.2777778 0.5333333 0.5333333 0.9615385
bullish AAPL 5 15 gbm - top layer 0.7500000 0.6711916 0.2321429 0.1428571 0.5333333 0.3667205 0.7906977 0.6153846 0.6153846 0.3035714 0.4705882 0.4705882 0.8717949
bullish AAPL 5 20 gbm - top layer 0.8611111 0.8115385 0.2500000 0.1944444 0.7368421 0.6428571 0.8888889 0.7777778 0.7777778 0.2777778 0.7000000 0.7000000 0.9230769
bullish AAPL 5 1 glm 0.6842105 0.5149573 0.0350877 0.0175439 0.1000000 0.0393258 0.6909091 0.5000000 0.5000000 0.3157895 0.0555556 0.0555556 0.9743590
bullish AAPL 5 5 glm 0.6929825 0.5438034 0.0789474 0.0438596 0.2222222 0.1097724 0.7047619 0.5555556 0.5555556 0.3157895 0.1388889 0.1388889 0.9487179
bullish AAPL 5 10 glm 0.7592593 0.5871795 0.0740741 0.0555556 0.3157895 0.2251656 0.7600000 0.7500000 0.7500000 0.2777778 0.2000000 0.2000000 0.9743590
bullish AAPL 5 15 glm 0.6428571 0.4615385 0.0535714 0.0000000 NaN -0.1001965 0.6792453 0.0000000 0.0000000 0.3035714 0.0000000 0.0000000 0.9230769
bullish AAPL 5 20 glm 0.7037037 0.5076923 0.0555556 0.0185185 0.1111111 0.0204082 0.7254902 0.3333333 0.3333333 0.2777778 0.0666667 0.0666667 0.9487179
bullish AAPL 5 1 glm - top layer 0.7982456 0.7254274 0.2192982 0.1666667 0.6229508 0.4912689 0.8089888 0.7600000 0.7600000 0.3157895 0.5277778 0.5277778 0.9230769
bullish AAPL 5 5 glm - top layer 0.8245614 0.7745726 0.2631579 0.2017544 0.6969697 0.5749441 0.8452381 0.7666667 0.7666667 0.3157895 0.6388889 0.6388889 0.9102564
bullish AAPL 5 10 glm - top layer 0.8796296 0.8141026 0.2129630 0.1851852 0.7547170 0.6767956 0.8823529 0.8695652 0.8695652 0.2777778 0.6666667 0.6666667 0.9615385
bullish AAPL 5 15 glm - top layer 0.7767857 0.6904223 0.2053571 0.1428571 0.5614035 0.4190871 0.7977528 0.6956522 0.6956522 0.3035714 0.4705882 0.4705882 0.9102564
bullish AAPL 5 20 glm - top layer 0.8518519 0.7948718 0.2407407 0.1851852 0.7142857 0.6149733 0.8780488 0.7692308 0.7692308 0.2777778 0.6666667 0.6666667 0.9230769
bullish AAPL 5 1 nb 0.6842105 0.6570513 0.3684211 0.1842105 0.5384615 0.3006135 0.7916667 0.5000000 0.5000000 0.3157895 0.5833333 0.5833333 0.7307692
bullish AAPL 5 5 nb 0.6754386 0.5683761 0.1842105 0.0877193 0.3508772 0.1540313 0.7204301 0.4761905 0.4761905 0.3157895 0.2777778 0.2777778 0.8589744
bullish AAPL 5 10 nb 0.7129630 0.6166667 0.2314815 0.1111111 0.4363636 0.2459459 0.7831325 0.4800000 0.4800000 0.2777778 0.4000000 0.4000000 0.8333333
bullish AAPL 5 15 nb 0.6785714 0.6033183 0.2678571 0.1250000 0.4375000 0.2137285 0.7560976 0.4666667 0.4666667 0.3035714 0.4117647 0.4117647 0.7948718
bullish AAPL 5 20 nb 0.7592593 0.7205128 0.3148148 0.1759259 0.5937500 0.4236453 0.8513514 0.5588235 0.5588235 0.2777778 0.6333333 0.6333333 0.8076923
bullish AAPL 5 1 nb - top layer 0.7719298 0.7136752 0.2631579 0.1754386 0.6060606 0.4474273 0.8095238 0.6666667 0.6666667 0.3157895 0.5555556 0.5555556 0.8717949
bullish AAPL 5 5 nb - top layer 0.7894737 0.7564103 0.3157895 0.2105263 0.6666667 0.5128205 0.8461538 0.6666667 0.6666667 0.3157895 0.6666667 0.6666667 0.8461538
bullish AAPL 5 10 nb - top layer 0.8611111 0.8012821 0.2314815 0.1851852 0.7272727 0.6351351 0.8795181 0.8000000 0.8000000 0.2777778 0.6666667 0.6666667 0.9358974
bullish AAPL 5 15 nb - top layer 0.7410714 0.6481900 0.2053571 0.1250000 0.4912281 0.3261411 0.7752809 0.6086957 0.6086957 0.3035714 0.4117647 0.4117647 0.8846154
bullish AAPL 5 20 nb - top layer 0.8518519 0.7948718 0.2407407 0.1851852 0.7142857 0.6149733 0.8780488 0.7692308 0.7692308 0.2777778 0.6666667 0.6666667 0.9230769

(VI) EVALUATION

In this final project, we focus on four key measures to evaluate the success of our models, i.e. accuracy, f1 score, precision, and recall (aka sensitivity). Overall, the model seems to be more accurate in pointint out a downward trend (“bearish”).

(VII) PREDICTION

Here’s the most important piece of this final project - prediction. Let’s first display the Moving Average chart. We look at the moving average of 5- and 20-trading windows. We can use this chart as a reference when reading our prediction chart.

The prediction chart displays the two trends, i.e. bearish, bullish, each is defined by the threshold that we set up earlier. The red line represents a downward (“bearish”) trend, whereas the green line represents the upward (“bullish”) trend. These lines move up and down along the trading dates. We should read it as, “on that specific trading date, we predict”t plus n trading day" for moving upward and crossing our threshold (above 85th percentile of our change in closing prices between t and t plus n day) would be XX%, whereas the probability of moving downward and crossing the threshold (below 15th percentile) would be YY%.

The red vertical dashed lines represent very strong signal of trending downward, whereas a green vertical dashed line represents the opposite upward trend. The vertical lines would only appear if there’s a consensus among the 5 ndays and they must cross above the 50% cut-off line. We would interpret that as a very strong signal that the coming future trading day(s) would see a very strong downward/upward trend. Looking at the prediction chart, we see red flags (bearish signals) for these dates, i.e. 2020-02-24, 2020-02-26, 2020-03-05, 2020-03-06, 2020-03-11. On the other hand, we see a green flag (bullish signal) for a specific date, i.e. 2020-03-24.

The model successfully captures these significant dates that were heavily impacted by the pandemic and its subsequent reactions from the global market. Basically, the market crashed on “02-24-2020” and the Dow plunged 1000 points on coronavirus fears and AAPL droped by almost 5% from the previous trading day (“02-21-2020”). The market went into complete turmoil in the week of “02-24-2020”. A month later, AAPL bounced back starting on “03-23-2020”. The prediction chart captured all these downard and upward moments in late March and throughout April. The prediction chart highly corresponds with the moving average chart and both charts display clear signal about when market will likely rise or crash.

CONCLUSION

Obviously there’s a lot of room for improvement, such as feature selection, precision, accuracy of the model, etc. Another piece of challenge is how to speed up the time of processing multiple stocks at the same time (running for 10 stocks would require almost an hour on my personal laptop with 32 GB of RAM). In addition, how do we decide an appropriate threshold that is useful or meaningful to us? It can vary from situation to situation, and obviously stock price movement depends on market volatility and other factors (like Elon Musk tweeted about TSLA price was too high in the morning and subsequently the market responded by dragging the price down by 12% before closing. All it took was a single tweet in a single trading day). After all, maybe all the hard work is not as easily interpretable or more insightful than a simple moving average chart!

APPENDIX

############################################################
### SET UP ###

# load packages
packages <- c('broom', 'caret', 'doParallel', 'e1071', 'foreach', 'glue', 'gridExtra', 'Hmisc', 'htmlwidgets', 'InformationValue', 'kableExtra', 'parallel', 'plotly', 'quantmod', 'sqldf', 'tictoc', 'tidyverse', 'TTR', 'wrapr')
pacman::p_load(char = packages)

# set environment
readRenviron("~/I/config/.env")

# set project home directory
PROJECT_HOME_DIRECTORY <- Sys.getenv("PROJECT_HOME_DIRECTORY")
setwd(PROJECT_HOME_DIRECTORY)

# get real time data
REAL_TIME = TRUE
ALPHA_VANTAGE_API <- Sys.getenv("ALPHA_VANTAGE_API")

### GET SYMBOLS ###

# stock symbol
stock <- c("AAPL")

# detect, use multicores
numCores <- parallel::detectCores()

# create a simple cluster on the local machine using all available threads
cl <- parallel::makeCluster(detectCores(), methods = FALSE)

# register our cluster
doParallel::registerDoParallel(cl)

# loop through a list of stock tickers - super fast! 5x faster than the traditional for-loop approach!!
symbols <- foreach::foreach(i = 1:length(stock), .errorhandling = 'remove') %dopar% { quantmod::getSymbols(stock[i]) } %>% unlist  # change .errorhandling = 'pass' to see error

# return a single list of xts objects from the valid symbols
if(REAL_TIME){
        
        xtsList <- vector(mode = "list", length = length(symbols))
        
        for(i in 1:length(symbols)){
                
                xtsList[[i]] <- quantmod::getSymbols(
                        
                        symbols[i], 
                        env = NULL,  # set env = NULL and that is equivalent to auto.assign = FALSE
                        src = "av",
                        periodicity = "daily", 
                        output.size = "full", 
                        adjusted = TRUE,
                        api.key = ALPHA_VANTAGE_API
                        
                )
                
                Sys.sleep(12)
                
        }
        
} else {
        
        xtsList <- foreach::foreach(i = 1:length(symbols)) %dopar% { quantmod::getSymbols(symbols[i], env = NULL, adjusted = TRUE) }  # set env = NULL and that is equivalent to auto.assign = FALSE        
        
}

# set names for xtsList
names(xtsList) <- symbols

############################################################
### CUSTOM FUNCTION ###
historicalTransformation <- function(xts,        
                                     l = 1,
                                     n = 1,
                                     originalSymbol = FALSE,
                                     transformOnly = FALSE
){
        
        # transform() function
        transformation <- function(xts, l, n, originalSymbol){
                
                # symbol
                symbol <- stringr::str_extract_all(names(xts), pattern = "^[[:alpha:]].*\\.") %>% unlist %>% stringr::str_to_lower(.) %>% unique %>% gsub("\\.", "", .)
                
                # rename columns
                names(xts) <- gsub("^[[:alpha:]].*\\.", "", names(xts)) %>% stringr::str_to_lower(.)
                
                # turn it into data.frame
                xts <- as.data.frame(xts)
                
                # insert columns
                xts <- xts %>%
                        dplyr::mutate(
                                # date
                                date = row.names(xts) %>% lubridate::ymd(.),
                                year = lubridate::year(date),
                                quarter = lubridate::quarter(date),
                                month = lubridate::month(date),
                                weekday = base::weekdays(date),
                                day = lubridate::day(date),
                                # Lag
                                op_l = quantmod::Lag(xts[, "open"], l),
                                hi_l = quantmod::Lag(xts[, "high"], l),
                                lo_l = quantmod::Lag(xts[, "low"], l),
                                cl_l = quantmod::Lag(xts[, "close"], l),
                                vol_l = quantmod::Lag(xts[, "volume"], l),
                                adj_l = quantmod::Lag(xts[, "adjusted"], l),
                                # Next
                                op_n = lead(xts[, "open"], n),
                                hi_n = lead(xts[, "high"], n),
                                lo_n = lead(xts[, "low"], n),
                                cl_n = lead(xts[, "close"], n),
                                vol_n = lead(xts[, "volume"], n),
                                adj_n = lead(xts[, "adjusted"], n),
                                # daily "Close - Open", "Hi - Low"
                                cl_op_diff = close - open,
                                hi_lo_diff = high - low,
                                # Lag "diff"
                                op_l_diff = open - op_l,
                                hi_l_diff = high - hi_l,
                                lo_l_diff = low - lo_l,
                                cl_l_diff = close - cl_l,
                                vol_l_diff = volume - vol_l,
                                adj_l_diff = adjusted - adj_l,
                                # Next "diff"
                                op_n_diff = op_n - open,
                                hi_n_diff = hi_n - high,
                                lo_n_diff = lo_n - low,
                                cl_n_diff = cl_n - close,
                                vol_n_diff = vol_n - volume,
                                adj_n_diff = adj_n - adjusted,
                                # oscillator - RSI, CCI                                
                                rsi_close = TTR::RSI(xts[, "close"]),
                                cci_close = TTR::CCI(xts[, "close"])
                        )
                
                # oscillator - MACD
                macd <- MACD(xts$close) %>% as.data.frame %>% dplyr::select(macd)
                signal <- MACD(xts$close) %>% as.data.frame %>% dplyr::select(signal)
                
                # add MACD
                xts <- xts %>%
                        dplyr::mutate(macd_close = macd$macd,
                                      signal_close = signal$signal,
                                      macd_close_diff = macd_close - signal_close) %>%
                        dplyr::select(date, year, quarter, month, weekday, day,
                                      open, high, low, close, volume, adjusted,
                                      rsi_close, cci_close, macd_close, signal_close, macd_close_diff,
                                      everything()) %>%
                        dplyr::arrange(date)
                
                # rename columns back with original symbol
                if(originalSymbol){names(xts) <- paste(symbol, names(xts), sep = "_")}
                
                # return xts
                return(xts)
                
        }
        
        # return a df object
        if(transformOnly){
                
                # return a transformed xts object
                transformObj <- transformation(xts, l, n, originalSymbol)
                return(transformObj)
                
        } else {
                
                # return the min and max of different variables associated with dates based on a transformed xts object
                SYMBOL <- transformation(xts, l, n, originalSymbol)
                
                minVector <- SYMBOL[complete.cases(SYMBOL), 6:ncol(SYMBOL)] %>% lapply(., min) %>% unlist
                maxVector <- SYMBOL[complete.cases(SYMBOL), 6:ncol(SYMBOL)] %>% lapply(., max) %>% unlist
                
                minList <- vector(mode = "list", length = length(minVector))
                for(i in 1:length(minList)){
                        minList[[i]] <- sqldf(sprintf("select date, %s from SYMBOL where floor(%s) = floor(%f)", names(minVector)[i], names(minVector)[i], minVector[i]))
                }
                
                maxList <- vector(mode = "list", length = length(maxVector))
                for(i in 1:length(maxList)){
                        maxList[[i]] <- sqldf(sprintf("select date, %s from SYMBOL where ceil(%s) = ceil(%f)", names(maxVector)[i], names(maxVector)[i], maxVector[i]))
                }
                
                minDf <- minList %>%
                        bind_rows() %>%
                        tidyr::gather(., key, value, -date) %>%
                        dplyr::filter(!is.na(value)) %>%
                        dplyr::mutate(type = "min") %>%
                        arrange(key, date)
                
                maxDf <- maxList %>%
                        bind_rows() %>%
                        tidyr::gather(., key, value, -date) %>%
                        dplyr::filter(!is.na(value)) %>%
                        dplyr::mutate(type = "max") %>%
                        arrange(key, date)
                
                historyObj <- bind_rows(minDf, maxDf) %>%
                        dplyr::select(., type, everything()) %>%
                        arrange(type, key, date)
                
                return(historyObj)
        }
        
}

############################################################
### SET PARAMETERS FOR MODELS ###

# trend
volatility = c("bullish", "bearish")

# target percentile threshold, e.g. top X% and bottom X% price change (cl_n_diff / close)
cl_percentile_threshold = 0.15

# xts subset
xts_data_subset = TRUE

# xts subset partition, i.e. number of most recent trading days
xts_data_subset_partition = 1000

# lag day(s)
l_period = c(1, 5, 10, 15, 20)

# next day(s)
n_period = c(1, 2, 3, 4, 5)

# baseTrainMethods
baseTrainMethods <- c("glm", "nb", "gbm")

# topTrainMethods
topTrainMethods <- c("glm", "nb", "gbm")

# tune length
tune.length = 3

# seed 
seed = 1234

# split data into train and test set by XX
size = 0.8

# Dependent Variable
DV <- "target"

# Features Selection Threshold
features_selection_threshold = .01

# dfEval, i.e. number of trading days for evaluation
dfEval_subset_partition = 90

# output
modelSummaryList <- vector(mode = "list")

evalList <- vector(mode = "list")

############################################################
### BUILD MODELS ###

# start timer
tic()

# start nested for() loop        
for(b in volatility){
        
        marketTrend = b
        
        for(l in l_period){
                
                lday = l
                
                for(i in n_period){
                        
                        nday = i
                        
                        for(j in stock){
                                
                                # get data
                                x <- xtsList[[j]]
                                
                                # get target threshold
                                if(xts_data_subset){
                                        y.t <- historicalTransformation(x, l = lday, n = nday, transformOnly = TRUE) %>%
                                                dplyr::mutate(percent_diff = cl_n_diff / close,
                                                              partition = (nrow(.)-1):0) %>%
                                                dplyr::filter(partition <= xts_data_subset_partition)
                                } else {
                                        y.t <- historicalTransformation(x, l = lday, n = nday, transformOnly = TRUE) %>%
                                                dplyr::mutate(percent_diff = cl_n_diff / close)
                                }
                                y <- y.t$percent_diff
                                y <- y[!is.na(y)]
                                z <- quantile(y, c(cl_percentile_threshold, 1 - cl_percentile_threshold))
                                
                                # features
                                features <- c(                                
                                        'rsi_close', 
                                        'cci_close',
                                        'macd_close', 
                                        'signal_close',
                                        'vol_n_diff',
                                        'op_l_percent_diff', 
                                        'hi_l_percent_diff', 
                                        'lo_l_percent_diff', 
                                        'cl_l_percent_diff', 
                                        'vol_l_percent_diff',    
                                        'cl_op_diff_by_op',
                                        'hi_lo_diff_by_op',
                                        'cl_op_diff_by_cl_l',
                                        'hi_lo_diff_by_cl_l',
                                        'cl_cl_l_ratio',
                                        'op_cl_l_ratio',
                                        'vol_cl_l_ratio',
                                        'vol_op_l_ratio',  
                                        'vol_diff_ratio',
                                        'sma_5',                        
                                        'sma_10',
                                        'sma_15'
                                )
                                
                                # transform, get DV, set partition
                                x.t <- historicalTransformation(x, l = lday, n = nday, transformOnly = TRUE) %>%
                                        dplyr::mutate(
                                                trend = marketTrend,
                                                symbol = j,                        
                                                l_period = lday,
                                                n_period = nday,
                                                op_l_percent_diff = ((open - op_l) / op_l) %>% as.vector,
                                                hi_l_percent_diff = ((high - hi_l) / hi_l) %>% as.vector,
                                                lo_l_percent_diff = ((low - lo_l) / lo_l) %>% as.vector,
                                                cl_l_percent_diff = ((close - cl_l) / cl_l) %>% as.vector,
                                                vol_l_percent_diff = ((volume - vol_l) / vol_l) %>% as.vector,
                                                cl_op_diff_by_op = ((close - open) / open) %>% as.vector,
                                                hi_lo_diff_by_op = ((high - low) / open) %>% as.vector,
                                                cl_op_diff_by_cl_l = ((close - open) / cl_l) %>% as.vector,
                                                hi_lo_diff_by_cl_l = ((high - low) / cl_l) %>% as.vector,
                                                cl_cl_l_ratio = (close / cl_l) %>% as.vector,
                                                op_cl_l_ratio = (open / cl_l) %>% as.vector, 
                                                vol_cl_l_ratio = (vol_l_percent_diff / cl_cl_l_ratio) %>% as.vector, 
                                                vol_op_l_ratio = (vol_l_percent_diff / op_cl_l_ratio) %>% as.vector,  
                                                vol_diff_ratio = ((vol_n_diff / vol_l_diff) %>% as.vector) %>% as.vector, 
                                                sma_5 = TTR::SMA(close, 5),                                
                                                sma_10 = TTR::SMA(close, 10),
                                                sma_15 = TTR::SMA(close, 15),
                                                target = dplyr::case_when(trend == "bullish" ~ ifelse( (cl_n_diff / close) > z[2], "Y", "N" ),
                                                                          trend == "bearish" ~ ifelse( (cl_n_diff / close) < z[1], "Y", "N" )) %>%
                                                        factor(., levels = c("Y", "N"), labels = c("Yes", "No")),            
                                                partition = (nrow(.)-1):0) %>%  # 0 is referred to the most recent (or last) trading day
                                        dplyr::select(trend, symbol, l_period, n_period, partition, date, year, quarter, month, weekday, day, everything()) %>%
                                        arrange(desc(partition))                
                                
                                # whether to subset and use only the most recent trading days or entire historical record
                                if(xts_data_subset){x.t <- x.t %>% dplyr::filter(partition <= xts_data_subset_partition)}
                                
                                # scale features
                                x.t.scaled <- x.t %>% dplyr::mutate_at(vars(features), scale)
                                
                                # remove any nan column
                                x.t.scaled <- x.t.scaled[, which(unlist(lapply(x.t.scaled, function(x) !any(is.nan(x)))))]
                                
                                # complete.cases
                                x.t.scaled <- x.t.scaled %>% complete.cases() %.>% x.t.scaled[., ]
                                
                                # new set of features
                                features <- features[features %in% names(x.t.scaled)]
                                
                                # feature selections by t.test        
                                t.test.list <- lapply(x.t.scaled[, features], function(x) t.test(x ~ x.t.scaled$target) %>% broom::tidy())
                                t.test.df <- t.test.list %>%
                                        dplyr::bind_rows() %>%
                                        dplyr::mutate(variables = features) %>%
                                        arrange(p.value)
                                
                                IV <- t.test.df$variables[t.test.df$p.value < features_selection_threshold]
                                if(length(IV) <=2){IV = unique(c(IV, 'rsi_close', 'cci_close', 'macd_close', 'signal_close'))}
                                
                                # subset features
                                x.t.scaled2 <- x.t.scaled %>% 
                                        dplyr::select(partition, date, all_of(IV), DV) %>%
                                        dplyr::filter(partition > dfEval_subset_partition)
                                
                                # evaluation set (include all variables and TODAY values)
                                dfEval <- x.t %>% 
                                        dplyr::filter(partition <= dfEval_subset_partition) %>%
                                        dplyr::mutate_at(vars(features), scale) %>%
                                        dplyr::select(partition, date, all_of(IV), DV) %>%                
                                        dplyr::mutate_at(IV, as.vector)
                                
                                # impute dataset
                                preProcValues <- caret::preProcess(dfEval[, IV], method = c("medianImpute"))
                                dfEval <- predict(preProcValues, dfEval) %>%
                                        dplyr::mutate_at(IV, as.vector)
                                
                                # oversampling target == "Yes" by 50%
                                x.t.scaled2_Yes <- x.t.scaled2 %>% dplyr::filter(target == "Yes")
                                x.t.scaled2_IndexUp <- sample(1:nrow(x.t.scaled2_Yes), size = floor(nrow(x.t.scaled2_Yes) * 1.5), replace = TRUE)
                                x.t.scaled2_Yes <- x.t.scaled2_Yes[x.t.scaled2_IndexUp, ]
                                
                                # undersampling target == "No" by 50%
                                x.t.scaled2_No <- x.t.scaled2 %>% dplyr::filter(target == "No")
                                x.t.scaled2_IndexDown <- sample(1:nrow(x.t.scaled2_No), size = floor(nrow(x.t.scaled2_No) * 0.5), replace = FALSE)
                                x.t.scaled2_No <- x.t.scaled2_No[x.t.scaled2_IndexDown, ]
                                
                                # put them together to come up with new x.t.scaled
                                x.t.scaled2 <- dplyr::bind_rows(x.t.scaled2_Yes, x.t.scaled2_No)
                                
                                # split data into train, test sets
                                set.seed(seed + nday + lday)
                                index <- caret::createDataPartition(x.t.scaled2$target, p = size, list = FALSE)
                                trainSet <- x.t.scaled2[index, ]
                                testSet <- x.t.scaled2[-index, ] %>% distinct 
                                
                                # trainSetControl
                                trainSet.control <- caret::trainControl(method = "cv", number = 10, savePredictions = "final", classProbs = TRUE)
                                
                                # train base layer
                                for(baseLayer in baseTrainMethods){
                                        
                                        # set parameters
                                        ml = baseLayer
                                        model = paste0("model_", ml)
                                        OOF_prediction = paste0("OOF_pred_", ml)
                                        prediction = paste0("pred_", ml)
                                        result = paste0("result_", ml)
                                        
                                        # model
                                        assign(bquote(.(model)), caret::train(trainSet[, IV], trainSet[, DV], 
                                                                              method = ml, 
                                                                              trControl = trainSet.control, 
                                                                              tuneLength = tune.length))
                                        
                                        # Out-Of-Fold probability predictions - trainSet    
                                        if(ml == "glm"){trainSet$OOF_pred_glm = eval(sym(model))$pred$Y[order(eval(sym(model))$pred$rowIndex)]}
                                        if(ml == "nb"){trainSet$OOF_pred_nb = eval(sym(model))$pred$Y[order(eval(sym(model))$pred$rowIndex)]}
                                        if(ml == "gbm"){trainSet$OOF_pred_gbm = eval(sym(model))$pred$Y[order(eval(sym(model))$pred$rowIndex)]}
                                        
                                        # Out-Of-Fold probability predictions - testSet 
                                        assign(bquote(.(OOF_prediction)), predict(eval(sym(model)), testSet[, IV], type = "prob")$Y)
                                        if(ml == "glm"){testSet$OOF_pred_glm = eval(sym(OOF_prediction))}
                                        if(ml == "nb"){testSet$OOF_pred_nb = eval(sym(OOF_prediction))}
                                        if(ml == "gbm"){testSet$OOF_pred_gbm = eval(sym(OOF_prediction))}
                                        
                                        # Out-Of-Fold probability predictions - dfEval 
                                        assign(bquote(.(OOF_prediction)), predict(eval(sym(model)), dfEval[, IV], type = "prob")$Y)
                                        if(ml == "glm"){dfEval$OOF_pred_glm = eval(sym(OOF_prediction))}
                                        if(ml == "nb"){dfEval$OOF_pred_nb = eval(sym(OOF_prediction))}
                                        if(ml == "gbm"){dfEval$OOF_pred_gbm = eval(sym(OOF_prediction))}
                                        
                                        # Y/N predictions for Confusion Matrix - testSet    
                                        assign(bquote(.(prediction)), predict(eval(sym(model)), testSet[, IV]))
                                        if(ml == "glm"){testSet$pred_glm = eval(sym(prediction))}
                                        if(ml == "nb"){testSet$pred_nb = eval(sym(prediction))}
                                        if(ml == "gbm"){testSet$pred_gbm = eval(sym(prediction))}
                                        
                                        # output
                                        assign(bquote(.(result)), broom::tidy(caret::confusionMatrix(testSet[, prediction], testSet$target)) %>%
                                                       dplyr::mutate(trend = marketTrend, symbol = j, n_period = nday, l_period = lday, trainMethod = ml) %>%
                                                       dplyr::select(trend, symbol, n_period, l_period, trainMethod, everything()))
                                        
                                        # store output into a list
                                        tempModelList <- list(eval(sym(result)))
                                        modelSummaryList <<- c(modelSummaryList, tempModelList)
                                        
                                }
                                
                                # train top layer
                                for(topLayer in topTrainMethods){
                                        
                                        # set parameters
                                        ml = topLayer
                                        model = paste0("model_", ml)        
                                        OOF_predictors_top = c("OOF_pred_glm", "OOF_pred_nb", "OOF_pred_gbm")
                                        OOF_prediction_top = paste0("OOF_pred_top_", ml)
                                        prediction_top = paste0("pred_top_", ml)
                                        result = paste0("result_top_", ml)
                                        
                                        # model
                                        assign(bquote(.(model)), caret::train(trainSet[, OOF_predictors_top], trainSet[, DV], 
                                                                              method = ml, 
                                                                              trControl = trainSet.control, 
                                                                              tuneLength = tune.length))
                                        
                                        # Out-Of-Fold probability predictions - testSet 
                                        assign(bquote(.(OOF_prediction_top)), predict(eval(sym(model)), testSet[, OOF_predictors_top], type = "prob")$Y)
                                        if(ml == "glm"){testSet$OOF_pred_top_glm = eval(sym(OOF_prediction_top))}
                                        if(ml == "nb"){testSet$OOF_pred_top_nb = eval(sym(OOF_prediction_top))}
                                        if(ml == "gbm"){testSet$OOF_pred_top_gbm = eval(sym(OOF_prediction_top))}
                                        
                                        # Out-Of-Fold probability predictions - dfEval 
                                        assign(bquote(.(OOF_prediction_top)), predict(eval(sym(model)), dfEval[, OOF_predictors_top], type = "prob")$Y)
                                        if(ml == "glm"){dfEval$OOF_pred_top_glm = eval(sym(OOF_prediction_top))}
                                        if(ml == "nb"){dfEval$OOF_pred_top_nb = eval(sym(OOF_prediction_top))}
                                        if(ml == "gbm"){dfEval$OOF_pred_top_gbm = eval(sym(OOF_prediction_top))}
                                        
                                        # Y/N predictions for Confusion Matrix - testSet    
                                        assign(bquote(.(prediction_top)), predict(eval(sym(model)), testSet[, OOF_predictors_top]))
                                        if(ml == "glm"){testSet$pred_top_glm = eval(sym(prediction_top))}
                                        if(ml == "nb"){testSet$pred_top_nb = eval(sym(prediction_top))}
                                        if(ml == "gbm"){testSet$pred_top_gbm = eval(sym(prediction_top))}
                                        
                                        # output
                                        assign(bquote(.(result)), broom::tidy(caret::confusionMatrix(testSet[, prediction_top], testSet$target)) %>%
                                                       dplyr::mutate(trend = marketTrend, symbol = j, n_period = nday, l_period = lday, trainMethod = paste0(ml, " - top layer")) %>%
                                                       dplyr::select(trend, symbol, n_period, l_period, trainMethod, everything()))
                                        
                                        # store output into a list
                                        tempModelList <- list(eval(sym(result)))
                                        modelSummaryList <<- c(modelSummaryList, tempModelList)
                                        
                                }
                                
                                # put together - final averaging
                                testSet <- testSet %>%
                                        dplyr::mutate(pred_final_avg = (OOF_pred_top_glm + OOF_pred_top_nb + OOF_pred_top_gbm) / length(topTrainMethods),
                                                      pred_final = ifelse(pred_final_avg > 0.5, "Y", "N") %>%
                                                              factor(., levels = c("Y", "N"), labels = c("Yes", "No")))
                                
                                dfEval <- dfEval %>%
                                        dplyr::mutate(pred_final_avg = (OOF_pred_top_glm + OOF_pred_top_nb + OOF_pred_top_gbm) / length(topTrainMethods),
                                                      pred_final = ifelse(pred_final_avg > 0.5, 1, 0),
                                                      trend = marketTrend, symbol = j, n_period = nday, l_period = lday) %>%
                                        dplyr::select(trend, symbol, n_period, l_period, date, target, pred_final_avg, pred_final)
                                
                                finalResult <- broom::tidy(caret::confusionMatrix(testSet$pred_final, testSet$target)) %>%
                                        dplyr::mutate(trend = marketTrend, symbol = j, n_period = nday, l_period = lday, trainMethod = "final - averaging") %>%
                                        dplyr::select(trend, symbol, n_period, l_period, trainMethod, everything())
                                
                                # store output into a list
                                tempModelList <- list(finalResult)
                                modelSummaryList <<- c(modelSummaryList, tempModelList)
                                
                                tempEvalList <- list(dfEval)
                                evalList <<- c(evalList, tempEvalList)
                                
                        }
                        
                }
                
        }
        
}

# stop timer
toc()

# consolidate lists into df
modelSummaryDf <- modelSummaryList %>% dplyr::bind_rows()
evalDf <- evalList %>% dplyr::bind_rows()

############################################################
### VISUALIZATION ###

###################################
### TECHNICAL ANALYSIS ###
x <- xts::xts(xtsList[[stock]])

quantmod::chartSeries( x["201801::202005"],
                       name = stock,
                       TA = c(addBBands(draw = 'bands'), 
                              addADX(), 
                              addMACD(), 
                              addRSI(), 
                              addCCI(), 
                              addCMF(), 
                              addBBands(draw = 'width'), 
                              addBBands(draw = 'percent'), 
                              addVo()) )

###################################
# density curve
tempObj <- vector(mode = "list", length = length(n_period))

for(i in n_period){
        
        tempDf <- xtsList[[stock]] %>% 
                historicalTransformation(transformOnly = TRUE, n = i) %>%
                dplyr::mutate(percent_change = (cl_n_diff / close),
                              t_period = i,
                              tday = dplyr::case_when(t_period == 1 ~ "t plus 1 day",
                                                      t_period == 2 ~ "t plus 2 days",
                                                      t_period == 3 ~ "t plus 3 days",
                                                      t_period == 4 ~ "t plus 4 days",
                                                      t_period == 5 ~ "t plus 5 days"),
                              index = nrow(.):1) %>%
                dplyr::filter(index <= xts_data_subset_partition) %>%
                dplyr::select(date, close, cl_n_diff, percent_change, tday)
        
        tempList <- list(tempDf)
        tempObj <- c(tempObj, tempList)
        
}

tempDf <- tempObj %>% dplyr::bind_rows()

# gather data frame
dfGather <- tempDf %>%
        dplyr::select(-date) %>%
        dplyr::mutate(tday = as.factor(tday)) %>%
        tidyr::gather(key, value, -tday) 

# plot close ($) by tday
densityCurveClose <- ggplot(dfGather %>% dplyr::filter(key == "close") %>% distinct, 
                            aes(value)) +
        geom_density() +
        geom_vline(data = aggregate(value ~ tday, 
                                    dfGather %>% dplyr::filter(key == "close") %>% distinct, 
                                    median), 
                   aes(xintercept = value),
                   linetype = "dashed",
                   col = "red") +
        theme(legend.position = "none") +
        labs(x = "Close ($)") +
        theme_light() +
        scale_x_continuous(labels = scales::dollar) +
        scale_y_continuous(labels = scales::percent) +
        ggtitle(paste0(stock, " distribution of Close ($) for past ", xts_data_subset_partition, " trading days"))

# plot cl_n_diff
densityCurveCl_N_diff <- ggplot(dfGather %>% dplyr::filter(key == "cl_n_diff"), 
                                aes(value, fill = tday)) +
        geom_density(alpha = 0.5) +
        # median
        geom_vline(data = aggregate(value ~ tday, 
                                    dfGather %>% dplyr::filter(key == "cl_n_diff"), 
                                    median), 
                   aes(xintercept = value,
                       color = tday),
                   linetype = "dashed") +
        # cl_percentile_threshold
        geom_vline(data = aggregate(value ~ tday, 
                                    dfGather %>% dplyr::filter(key == "cl_n_diff"),
                                    quantile,
                                    probs = cl_percentile_threshold), 
                   aes(xintercept = value,
                       color = tday),
                   linetype = "dotted") +
        # 1 - cl_percentile_threshold
        geom_vline(data = aggregate(value ~ tday, 
                                    dfGather %>% dplyr::filter(key == "cl_n_diff"),
                                    quantile,
                                    probs = 1 -cl_percentile_threshold), 
                   aes(xintercept = value,
                       color = tday),
                   linetype = "dotted") +
        theme_minimal() +
        scale_x_continuous(labels = scales::dollar) +
        scale_y_continuous(labels = scales::percent) +
        theme(legend.position = "right") +
        labs(x = "Close ($) between t and t plus n day(s)") +
        ggtitle(paste0(stock, " distributions of difference between today (t) and future (t plus n trading day) Close ($) for past ", xts_data_subset_partition, " trading days")) +
        facet_wrap(~tday, nrow = 5)

# plot percent_change
densityCurveCl_percent_change <- ggplot(dfGather %>% dplyr::filter(key == "percent_change"), 
                                        aes(value, fill = tday)) +
        geom_density(alpha = 0.5) +
        # median
        geom_vline(data = aggregate(value ~ tday, 
                                    dfGather %>% dplyr::filter(key == "percent_change"), 
                                    median), 
                   aes(xintercept = value,
                       color = tday),
                   linetype = "dashed") +
        # cl_percentile_threshold
        geom_vline(data = aggregate(value ~ tday, 
                                    dfGather %>% dplyr::filter(key == "percent_change"),
                                    quantile,
                                    probs = cl_percentile_threshold), 
                   aes(xintercept = value,
                       color = tday),
                   linetype = "dotted") +
        # 1 - cl_percentile_threshold
        geom_vline(data = aggregate(value ~ tday, 
                                    dfGather %>% dplyr::filter(key == "percent_change"),
                                    quantile,
                                    probs = 1 -cl_percentile_threshold), 
                   aes(xintercept = value,
                       color = tday),
                   linetype = "dotted") +
        theme_bw() +
        scale_x_continuous(labels = scales::percent) +
        scale_y_continuous(labels = scales::percent) +
        theme(legend.position = "right") +
        labs(x = "% diff between t and t plus n day(s)") +
        ggtitle(paste0(stock, " distributions of change in percentage between today (t) and future (t plus n trading day) Close ($) for past ", xts_data_subset_partition, " trading days")) +
        facet_wrap(~tday, nrow = 5)

###################################
# evaluation chart
# data transformation for model evaluation

# spread table
modelSummarySpread <- modelSummaryDf %>% 
        dplyr::select(trend, symbol, n_period, l_period, trainMethod, term, estimate) %>%
        tidyr::spread(term, estimate) %>%
        arrange(trend, symbol, n_period, trainMethod)

# get measures
modelSummaryMeasure <- modelSummaryDf %>%
        dplyr::filter(term %in% c("recall", "precision", "f1") & trainMethod == "final - averaging") %>%
        dplyr::select(trend, symbol, n_period, l_period, measure = term, estimate) %>%
        dplyr::mutate(lday = dplyr::case_when(l_period == 1 ~ "lag 1 day",
                                              l_period == 5 ~ "lag 5 days",
                                              l_period == 10 ~ "lag 10 days",
                                              l_period == 15 ~ "lag 15 days",
                                              l_period == 20 ~ "lag 20 days") %>%
                              factor(., levels = c("lag 1 day", "lag 5 days", "lag 10 days", "lag 15 days", "lag 20 days")))

# get accuracy from eval set
accuracyDf <- evalDf %>%
        dplyr::mutate(flag = dplyr::case_when(pred_final == 0 ~ "No", TRUE ~ "Yes"),
                      accuracy = dplyr::case_when(target == flag ~ 1, TRUE ~ 0)) %>%
        dplyr::filter(!is.na(target)) %>%
        group_by(trend, symbol, n_period, l_period) %>%
        summarise(accuracy = mean(accuracy)) %>%
        dplyr::mutate(measure = "accuracy",
                      lday = dplyr::case_when(l_period == 1 ~ "lag 1 day",
                                              l_period == 5 ~ "lag 5 days",
                                              l_period == 10 ~ "lag 10 days",
                                              l_period == 15 ~ "lag 15 days",
                                              l_period == 20 ~ "lag 20 days") %>%
                              factor(., levels = c("lag 1 day", "lag 5 days", "lag 10 days", "lag 15 days", "lag 20 days"))) %>%
        dplyr::select(trend, symbol, n_period, l_period, measure, estimate = accuracy, lday) %>%
        arrange(trend, symbol, n_period, l_period)

# combine the key measures of model summary together
keyMeasures <- dplyr::bind_rows(modelSummaryMeasure, accuracyDf) %>%
        arrange(trend, symbol, n_period, l_period, measure)

# plot evaluation chart
evalChart <- keyMeasures %>%
        dplyr::filter(symbol == stock) %>%
        ggplot(aes(n_period, estimate, fill = factor(trend))) +
        geom_bar(stat = "identity", position = "dodge2") +
        geom_hline(yintercept = 0.5, linetype = "dashed", col = "black") +
        scale_y_continuous(labels = scales::percent, limits = c(0, 1)) +
        facet_grid(measure ~ lday) +
        labs(x = "Prediction for t plus n trading day(s)", y = "", fill = "trend") +
        theme_light() +
        theme(legend.position = "bottom") +
        ggtitle(paste0(stock, " Model Evaluation ", min(evalDf$date), " : ", max(evalDf$date)))

###################################
# MA charts
MA_chart <- xtsList[[stock]] %>% 
        historicalTransformation(transformOnly = TRUE) %>%
        dplyr::mutate(`5 day MA` = TTR::SMA(close, 5),
                      `20 day MA` = TTR::SMA(close, 20),
                      index = nrow(.):1) %>%
        dplyr::filter(index <= dfEval_subset_partition) %>%
        dplyr::select(date, close, `5 day MA`, `20 day MA`) %>%
        tidyr::gather(key, value, -date) %>%
        ggplot(aes(date, value)) + 
        geom_line(aes(col = key)) +
        labs(x = "", y = "") +
        scale_x_date(labels = scales::date_format("%Y-%m-%d"), date_breaks = "3 day") +
        scale_color_manual(values = c("black", "blue", "red")) +
        theme_minimal() +
        theme(legend.position = "top", 
              plot.title = element_text(hjust = 0.5),
              axis.text.x = element_text(hjust = 1, angle = 60),
              legend.title = element_blank()) +
        scale_y_continuous(labels = scales::dollar) +
        guides(col = guide_legend(reverse = TRUE)) +
        ggtitle(paste0(stock, " Close ($) Moving Average(s) for past ", dfEval_subset_partition, " trading days"))


###################################
# prediction chart

# data transformation for prediction
predDf <- evalDf %>%
        group_by(trend, symbol, n_period, date) %>%
        summarise(prediction = round(mean(pred_final_avg), 3)) %>% 
        dplyr::mutate(tday = dplyr::case_when(n_period == 1 ~ "t plus 1 day",
                                              n_period == 2 ~ "t plus 2 days",
                                              n_period == 3 ~ "t plus 3 days",
                                              n_period == 4 ~ "t plus 4 days",
                                              n_period == 5 ~ "t plus 5 days")) %>%
        ungroup %>%
        dplyr::select(-n_period)

# get signal dates
signalDate <- predDf %>%
        dplyr::select(trend, symbol, date, prediction, tday) %>%
        tidyr::spread(tday, prediction) %>%
        dplyr::mutate(`t plus 1 day` = dplyr::case_when(`t plus 1 day` > 0.5 ~ 1, TRUE ~ 0),
                      `t plus 2 days` = dplyr::case_when(`t plus 2 days` > 0.5 ~ 1, TRUE ~ 0),
                      `t plus 3 days` = dplyr::case_when(`t plus 3 days` > 0.5 ~ 1, TRUE ~ 0),
                      `t plus 4 days` = dplyr::case_when(`t plus 4 days` > 0.5 ~ 1, TRUE ~ 0),
                      `t plus 5 days` = dplyr::case_when(`t plus 5 days` > 0.5 ~ 1, TRUE ~ 0),
                      flag = `t plus 1 day` + `t plus 2 days` + `t plus 3 days` + `t plus 4 days` + `t plus 5 days`) %>%
        dplyr::select(trend, symbol, date, flag) %>%
        tidyr::spread(trend, flag) %>%
        dplyr::mutate(signal = dplyr::case_when(bearish <= 2 & bullish == 5 ~ 1,
                                                bearish == 5 & bullish <= 2 ~ 1,
                                                TRUE ~ 0)) %>%
        dplyr::filter(signal == 1) %>% 
        dplyr::select(-signal) %>%
        tidyr::gather(trend, value, -symbol, -date) %>%
        dplyr::filter(value == 5) %>%
        dplyr::select(-value)

# plot prediction chart
predChart <- predDf %>%
        dplyr::filter(symbol == stock) %>%
        ggplot(aes(x = date, y = prediction, col = trend)) +
        geom_line() +
        geom_hline(yintercept = 0.5, linetype = "dashed", col = "black") +
        geom_vline(aes(xintercept = date, col = trend), 
                   data = signalDate %>% dplyr::filter(symbol == stock),
                   linetype = "dashed") +
        scale_y_continuous(labels = scales::percent, limits = c(0, 1)) +
        scale_x_date(labels = scales::date_format("%Y-%m-%d"), 
                     date_breaks = "3 day", 
                     limits = c(min(predDf$date), max(predDf$date))) +
        facet_wrap(~ tday, nrow = 5) +
        theme_minimal() +
        theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
        theme(legend.position = "bottom") +
        labs(x = "", y = "") +
        ggtitle(paste0(stock, " Trend Prediction ", min(predDf$date), " : ", max(predDf$date)))

###################################
### PLOTLY ###

densityCurveClose %>% ggplotly()

densityCurveCl_N_diff %>% ggplotly()

densityCurveCl_percent_change %>% ggplotly()

evalChart %>% ggplotly()

MA_chart %>% ggplotly()

predChart  # vertical dashlines would disappear if we convert it into a plotly object, thus not recommend

###################################
### END ###
# stop the cluster
parallel::stopCluster(cl)