PREDICTION TECHNIQUES
This menu aims to predict the share price of a pre-loaded stock, and the usage of the following commands along with an example will be exploited below. See How to fune-tuning a NN model.
- sma
- simple moving average
- ets
- Exponential Smoothing (e.g. Holt-Winters)
- knn
- k-Nearest Neighbors
- linear
- linear regression (polynomial 1)
- quadratic
- quadratic regression (polynomial 2)
- cubic
- cubic regression (polynomial 3)
- regression
- regression (other polynomial)
- arima
- autoregressive integrated moving average
- prophet
- Facebook's prophet prediction
- mlp
- MultiLayer Perceptron
- rnn
- Recurrent Neural Network
- Contains a looping example
- lstm
- Long-Short Term Memory
- Contains a backtesting example
Note: Use this at your own discretion. All of these prediciton techniques rely solely on the closing price of the stock. This means that there are several factors that the models aren't aware of at the time of prediction, and may - drastically - move the price up or down. Examples are: news, analyst price targets, reddit post, tweets from Elon Musk, and so on.
Note 2: Enabling GPU acceleration for TensorFlow requires CUDA setup and will probably not provide any speedup unless you are building large custom models.
sma
usage: sma [-l N_LENGTH] [-d N_DAYS]
Simple Moving Average:
- -l : length of SMA window. Default 20.
- -d : prediciton days. Default 5.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
ets
usage: ets [-t TREND] [-s SEASONAL] [-p SEASONAL_PERIODS] [-d N_DAYS]
Exponential Smoothing (based on trend+seasonality, see https://otexts.com/fpp2/taxonomy.html):
- -t : trend component: N: None, A: Additive, Ad: Additive Damped. Default N.
- -s : seasonality component: N: None, A: Additive, M: Multiplicative. Default N.
- -p : seasonal periods. Default 5.
- -d : prediciton days. Default 5.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
knn
usage: knn [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS] [-n N_NEIGHBORS]
k-Nearest Neighbors:
- -i : number of days to use for prediction. Default 40.
- -d : prediciton days. Default 5.
- -j : number of jumps in training data. Default 1.
- -n : number of neighbors to use on the algorithm. Default 20.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
linear
usage: linear [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
usage: regression -p 1 [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
Linear Regression (p=1):
- -i : number of days to use for prediction. Default 40.
- -d : prediciton days. Default 5.
- -j : number of jumps in training data. Default 1.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
quadratic
usage: quadratic [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
usage: regression -p 2 [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
Quadratic Regression (p=2):
- -i : number of days to use for prediction. Default 40.
- -d : prediciton days. Default 5.
- -j : number of jumps in training data. Default 1.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
cubic
usage: cubic [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
usage: regression -p 3 [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
Cubic Regression (p=3):
- -i : number of days to use for prediction. Default 40.
- -d : prediciton days. Default 5.
- -j : number of jumps in training data. Default 1.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
regression
usage: regression -p N_POLYNOMIAL [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
Regression:
- -i : number of days to use for prediction. Default 40.
- -d : prediciton days. Default 5.
- -j : number of jumps in training data. Default 1.
- -p : polynomial associated with regression. Required.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
arima
usage: arima [-d N_DAYS] [-i {aic,aicc,bic,hqic,oob}] [-s] [-r] [-o S_ORDER]
Auto-Regressive Integrated Moving Average:
- -d : prediciton days. Default 5.
- -i : information criteria - used if auto_arima library is invoked. Default aic.
- -s : weekly seasonality flag. Default False.
- -r : results about ARIMA summary flag. Default False.
- -o : arima model order. If the model order is defined, auto_arima is not invoked, deeming information criteria useless.
Example: -o 514, where:- p = 5 : order (number of time lags) of the autoregressive model.
- d = 1 : degree of differencing (the number of times the data have had past values subtracted).
- q = 4 : order of the moving-average model.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
prophet
usage: fbprophet [-d N_DAYS]
Facebook's Prophet:
- -d : prediciton days. Default 5.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
mlp
usage: mlp [-d N_DAYS] [-i N_INPUTS] [-j N_JUMPS] [--epochs N_EPOCHS] [-p {normalization,standardization,none}]
[-o {adam,adagrad,adadelta,adamax,ftrl,nadam,optimizer,rmsprop,sgd}] [-l {mae,mape,mse,msle}] [-e S_END_DATE] [--loops N_LOOPS]
MulitLayer Perceptron:
- -d : prediciton days. Default 5.
- -i : number of days to use for prediction. Default 40.
- -j : number of jumps in training data. Default 1.
- --epochs : number of training epochs. Default 200.
- -p : pre-processing data. Default normalization.
- -o : optimization technique. Default adam.
- -l : loss function. Default mae.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
- --xla_cpu: if present, will enable XLA for CPU (overrides environment variables during run).
- --xla_gpu: if present, will enable XLA for GPU (overrides environment variables during run).
- --force_allow_gpu_growth: if true, will force TensorFlow to allow GPU memory usage to grow as needed. Otherwise will allocate 100% of available GPU memory when CUDA is set up. Default true.
- --batch_size: batch size for model training, should not be used unless advanced user. Default None.
- --loops: number of loops to iterate and train models. Default 1.
Due to the complexity of defining a model through command line, one can define it in: config_neural_network_models.txt
MultiLayer_Perceptron \
= [ {'Dense':
{'units':50, 'activation':'relu'} },
{'Dense':
{'units':100, 'activation':'relu'} },
{'Dense':
{'units':80, 'activation':'relu'} },
{'Dense':
{'units':30, 'activation':'relu'} },
{'Dense':
{'activation':'linear'} }]
rnn
usage: rnn [-d N_DAYS] [-i N_INPUTS] [-j N_JUMPS] [--epochs N_EPOCHS] [-p {normalization,standardization,none}]
[-o {adam,adagrad,adadelta,adamax,ftrl,nadam,optimizer,rmsprop,sgd}] [-l {mae,mape,mse,msle}] [-e S_END_DATE] [--loops N_LOOPS]
Recurrent Neural Network:
- -d : prediciton days. Default 5.
- -i : number of days to use for prediction. Default 40.
- -j : number of jumps in training data. Default 1.
- --epochs : number of training epochs. Default 200.
- -p : pre-processing data. Default normalization.
- -o : optimization technique. Default adam.
- -l : loss function. Default mae.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
- --xla_cpu: if present, will enable XLA for CPU (overrides environment variables during run).
- --xla_gpu: if present, will enable XLA for GPU (overrides environment variables during run).
- --force_allow_gpu_growth: if true, will force TensorFlow to allow GPU memory usage to grow as needed. Otherwise will allocate 100% of available GPU memory when CUDA is set up. Default true.
- --batch_size: batch size for model training, should not be used unless advanced user. Default None.
- --loops: number of loops to iterate and train models. Default 1.
Due to the complexity of defining a model through command line, one can define it in: config_neural_network_models.txt
Recurrent_Neural_Network \
= [ {'SimpleRNN':
{'units':100, 'activation':'linear', 'return_sequences':True} },
{'SimpleRNN':
{'units':50, 'activation':'linear', 'return_sequences':True} },
{'Dropout':
{'rate':0.2} },
{'SimpleRNN':
{'units':21, 'activation':'linear', 'return_sequences':False} },
{'Dense':
{'activation':'linear'} }]
Looping Example
lstm
usage: lstm [-d N_DAYS] [-i N_INPUTS] [-j N_JUMPS] [--epochs N_EPOCHS] [-p {normalization,standardization,none}]
[-o {adam,adagrad,adadelta,adamax,ftrl,nadam,optimizer,rmsprop,sgd}] [-l {mae,mape,mse,msle}] [-e S_END_DATE] [--loops N_LOOPS]
Long-Short Term Memory:
- -d : prediciton days. Default 5.
- -i : number of days to use for prediction. Default 40.
- -j : number of jumps in training data. Default 1.
- --epochs : number of training epochs. Default 200.
- -p : pre-processing data. Default normalization.
- -o : optimization technique. Default adam.
- -l : loss function. Default mae.
- -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.
- --xla_cpu: if present, will enable XLA for CPU (overrides environment variables during run).
- --xla_gpu: if present, will enable XLA for GPU (overrides environment variables during run).
- --force_allow_gpu_growth: if true, will force TensorFlow to allow GPU memory usage to grow as needed. Otherwise will allocate 100% of available GPU memory when CUDA is set up. Default true.
- --batch_size: batch size for model training, should not be used unless advanced user. Default None.
- --loops: number of loops to iterate and train models. Default 1.
Due to the complexity of defining a model through command line, one can define it in: config_neural_network_models.py
Long_Short_Term_Memory \
= [ {'LSTM':
{'units':25, 'activation':'tanh', 'return_sequences':True} },
{'LSTM':
{'units':15, 'activation':'tanh', 'return_sequences':False} },
{'Dense':
{'activation':'linear'} }]
Backtesting Example














